This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
108 lines (92 loc) · 3.62 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
/*
Discord Bot for 7th Cavalry S1 Department.
Made by Vex
*/
// Libraries
const Discord = require('discord.js');
const fs = require('fs');
const moment = require('moment'); // Documentation: https://momentjs.com/
const config = require('./src/config/main.json')
const GoogleSpreadsheet = require('google-spreadsheet');
const {promisify} = require('util');
const creds = require('./client_secret.json');
async function accessSpreadsheet() {
const doc = new GoogleSpreadsheet(config.GoogleSheets.SheetID);
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
const sheet = info.worksheet[1];
console.log(`title: ${sheet.title}, Rows: ${sheet.rowCount}`);
}
//Locals
const config = require('./src/config/main.json');
const Person = require('./src/personnel.js');
// Bot initilization
const bot = new Discord.Client();
const botLogin = config.Login;
bot.on('ready', () => {
console.log('Connected as ' + bot.user.tag);
bot.user.setActivity('7cav.us/enlist', {type: 3});
})
const prefix = '!'; // Command prefix
const p = new Person(bot);
bot.on('message', msg => {
// Don't let the bot deal with its own responses
if(msg.author.bot) return;
if(msg.content.startsWith(prefix)) {
// Command Args
let messageArray = msg.content.toLowerCase().split(/\s+/g);
let command = messageArray[0]
let args = messageArray.slice(1);
// Responsive command
if(msg.content.startsWith('!online'))
{
// respond if bot is online
msg.reply('S1 bot is online!');
}
//#region S1 commands
if(msg.content.startsWith('!S1')) {
// !S1
if(args[0] == null) {
// If !Personnel is done with no 2ndary command,
// Then send them the command list.
var help = new Discord.MessageEmbed()
.setColor('#F5CC00')
.setThumbnail('https://images.7cav.us/7Cav-small.png')
.setTitle('Commands:')
.addField('!S1 time DD/MM/YYYY', 'Gets the difference in days or months between now and the specified time.')
.addField('!S1 promo', 'Gets the promotions of the week')
.setTimestamp()
msg.channel.send(help)
}
// Time command and options
if(args[0] == 'time') {
if(args[1] == null) {
msg.reply('Syntax: !Personnel time DD/MM/YYYY');
return;
} else if(args[1] == 'now') {
msg.reply(`Today is ${p.getToday()} \n ${moment().add(1, 'days').calendar()} is in 24 hours`);
return;
} else if(args[1] == 'week')
{
msg.reply(`Today is ${p.getToday()} \n ${moment().add(7, 'days').calendar()} is ${p.getDifference()}`);
} else {
msg.reply(`Today is ${p.getToday()} \n ${args[1]} is ${p.getDifference()}`);
}
}
// Promotions
// TODO: add check if author.id is in
//var roles = msg.author.roles.has(config.DiscordRoles.S1Command || config.DiscordRoles.S6);
// !S1 promo
if(args[0] == 'promo' /*&& roles*/) {
}
if(args[0] == 'add') {
//if(msg.author.roles.has(config.DiscordRoles.S1Command || config.DiscordRoles.S6)) {
var user = p.add(args[1], args[2])
msg.reply(user);
//}
}
}
//#endregion
}
})
bot.login(botLogin);