-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
141 lines (110 loc) · 4.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const Discord = require('discord.js');
const bot = new Discord.Client();
const GoogleSpreadsheet = require('google-spreadsheet');
const { promisify } = require('util');
//---------------------------------------------------------------------------------------------------------------------------------
const creds = require('./client_secret.json')
async function accessDocSpreadsheet(user){
const doc = new GoogleSpreadsheet('1PEOVTKqOyI3ezu3RPZnxAyFeJjSp9lgcEEZDCCjL2BU');
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
const sheet = info.worksheets[0];
const row = {
num: `${date.getMonth()+1}/${date.getDate()}`,
name: nameMap.get(user),
action: actionMap.get(user),
goal: goalMap.get(user)
}
await promisify(sheet.addRow)(row);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------
const token = 'NjYzMjE3MzQxMjU2OTU3OTcy.XhFT5g.D-zLURx2qX9cYMvTJn7XCwbLbxw';
const PREFIX = '!';//we might change this later because I want to make !d
const documentation = {
NOT: 'not',
NAME: 'name',
ACTION: 'action',
ACHIEVEMENT: 'achievement'
}
var nameMap = new Map()
var actionMap = new Map()
var goalMap = new Map()
var date;
var docMap = new Map()
// OTHER ENUMS WILL GO HERE LATER NERDS
bot.on('ready', () => {
console.log('this bot is online');
bot.user.setActivity(' !help');
})
bot.login(token);
bot.on('message', message=>{
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0])
{
case 'help':
const embed = new Discord.RichEmbed()
.setTitle('Commands:')
.addField('!doc', 'document what you did today',false)
.addBlankField()
.addField('!scout prematch','answer questions about a team to scout them',false)
.addBlankField()
.addField('!scout match', 'score a team and answer questions to scout them',false)
.addBlankField()
.addField('!link','gives the link to Doccys spreadsheet', false)
.setColor(0xF1C40F)
message.channel.sendEmbed(embed);
break;
case 'doc':
date = new Date();
docMap.set(message.author.username,documentation.NAME)
message.channel.sendMessage('('+message.author.username+') What is your name?')
break;
case 'scout':
if(args[1] === 'prematch')
{
message.channel.sendMessage('you have chosen prematch scouting')
}else if(args[1] === 'match')
{
message.channel.sendMessage("you are doing in game scouting")
}
break;
case 'link':
message.channel.sendMessage("https://docs.google.com/spreadsheets/d/1PEOVTKqOyI3ezu3RPZnxAyFeJjSp9lgcEEZDCCjL2BU/edit?usp=sharing")
break;
default:
if(!(message.author.username === 'DoccyBot'))
{
switch(docMap.get(message.author.username))
{
case documentation.ACHIEVEMENT:
docMap.set(message.author.username,documentation.NOT)
goalMap.set(message.author.username,message)
accessDocSpreadsheet(message.author.username);
break;
case documentation.ACTION:
docMap.set(message.author.username,documentation.ACHIEVEMENT)
actionMap.set(message.author.username,message)
message.channel.sendMessage('('+message.author.username+') What did you finish/accomplish?')
break;
case documentation.NAME:
docMap.set(message.author.username,documentation.ACTION)
nameMap.set(message.author.username,message)
message.channel.sendMessage('('+message.author.username+') What did you do today?')
break;
}
}
}
})
//TODO:
// make the bot interact with a spreadsheet
// make the bot be able to score matches live
//enum system + conversation
//helpful stuff:
//message.reply - pings person
//channel.sendMessage - sends message into a channel
// case 'clear':
// if(!args[1]) return message.reply('add a second argument') - deletes messages
// message.channel.bulkDelete(args[1]);
// break;
//message.author.username - fetches user's name
//message.author.avatarURL - image of url