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
|
#!/usr/bin/node
/* jshint esnext:true */
"use strict";
const PREVIEW = process.env.PREVIEW != "false";
const sqlite = require("sqlite"),
path = require("path"),
winston = require("winston"),
loggly = require("winston-loggly-bulk"),
Commando = require("discord.js-commando"),
oneLine = require("common-tags").oneLine,
client = new Commando.Client({
owners: ["227440521704898561", "208974925199966208"],
// shutterfly, stormcaller
commandPrefix: (PREVIEW? "?" : "!"),
invite: "https://discord.gg/txTchJY",
unknownCommandResponse: false
}),
util = require("./util");
const DISCORD_TOKEN = process.env.DISCORD_TOKEN,
LOGGLY_TOKEN = process.env.LOGGLY_TOKEN;
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
timestamp: true,
colorize: true
})
]
});
if (LOGGLY_TOKEN)
logger.add(winston.transports.Loggly, {
inputToken: LOGGLY_TOKEN,
subdomain: "kvahuja",
tags: ["frontend", "discordbot"],
json: true
});
client
.on("error", logger.error)
.on("warn", logger.warn)
.on("debug", logger.info)
.on("ready", () => {
logger.info(`Client ready; logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`);
util.rotateGameStatus(client);
})
.on('disconnect', () => { logger.warn('Disconnected!'); })
.on('reconnecting', () => { logger.warn('Reconnecting...'); })
.on('commandError', (cmd, err) => {
if(err instanceof Commando.FriendlyError) return;
logger.error(`Error in command ${cmd.groupID}:${cmd.memberName}`, err);
})
.on('commandBlocked', (msg, reason) => {
logger.info(oneLine`
Command ${msg.command ? `${msg.command.groupID}:${msg.command.memberName}` : ''}
blocked; ${reason}
`);
})
.on('commandPrefixChange', (guild, prefix) => {
logger.info(oneLine`
Prefix ${prefix === '' ? 'removed' : `changed to ${prefix || 'the default'}`}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`);
})
.on('commandStatusChange', (guild, command, enabled) => {
logger.info(oneLine`
Command ${command.groupID}:${command.memberName}
${enabled ? 'enabled' : 'disabled'}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`);
})
.on('groupStatusChange', (guild, group, enabled) => {
logger.info(oneLine`
Group ${group.id}
${enabled ? 'enabled' : 'disabled'}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`);
})
// response reaction interface
.on("messageReactionAdd", util.onNewReaction);
client.setProvider(
sqlite.open(path.join(__dirname, "settings.sqlite3")).then(
db => new Commando.SQLiteProvider(db)));
client.registry
.registerGroup('vainsocial', 'VainSocial')
.registerGroup('vainsocial-guild', 'VainSocial Guild management')
.registerDefaultTypes()
.registerDefaultGroups()
.registerDefaultCommands({ eval_: false, commandState: false })
.registerCommandsIn(path.join(__dirname, 'commands'));
client.login(DISCORD_TOKEN);
process.on("unhandledRejection", err => {
logger.error("Uncaught Promise Error", err);
});
|