-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTohru.js
89 lines (81 loc) · 2.82 KB
/
Tohru.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
const { FriendlyError } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const path = require('path');
const winston = require('winston');
const TohruClient = require('./structures/TohruClient');
const SequelizeProvider = require('./providers/Sequelize');
const { OWNERS, COMMAND_PREFIX, TOKEN } = process.env;
const client = new TohruClient({
owner: OWNERS.split(','),
commandPrefix: COMMAND_PREFIX,
unknownCommandResponse: false,
disableEveryone: true
});
client.setProvider(new SequelizeProvider(client.database));
client.on('error', winston.error)
.on('warn', winston.warn)
.on('ready', () =>
winston.info(oneLine`
[DISCORD]: Client ready...
Logged in as ${client.user.tag}
(${client.user.id})
`)
)
.on('disconnect', () => winston.warn('[DISCORD]: Disconnected!'))
.on('reconnect', () => winston.warn('[DISCORD]: Reconnecting...'))
.on('commandRun', (cmd, promise, msg, args) =>
winston.info(oneLine`
[DISCORD]: ${msg.author.tag} (${msg.author.id})
> ${msg.guild ? `${msg.guild.name} (${msg.guild.id})` : 'DM'}
>> ${cmd.groupID}:${cmd.memberName}
${Object.values(args).length ? `>>> ${Object.values(args)}` : ''}
`)
)
.on('unknownCommand', msg => {
if (msg.channel.type === 'dm') return;
if (msg.author.bot) return;
const args = { name: msg.content.split(client.commandPrefix)[1] };
client.registry.resolveCommand('tags:tag').run(msg, args);
})
.on('commandError', (cmd, err) => {
if (err instanceof FriendlyError) return;
winston.error(`[DISCORD]: Error in command ${cmd.groupID}:${cmd.memberName}`, err);
})
.on('commandBlocked', (msg, reason) =>
winston.info(oneLine`
[DISCORD]: Command ${msg.command ? `${msg.command.groupID}:${msg.command.memberName}` : ''}
blocked; User ${msg.author.tag} (${msg.author.id}): ${reason}
`)
)
.on('commandPrefixChange', (guild, prefix) =>
winston.info(oneLine`
[DISCORD]: Prefix changed to ${prefix || 'the default'}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`)
)
.on('commandStatusChange', (guild, command, enabled) =>
winston.info(oneLine`
[DISCORD]: Command ${command.groupID}:${command.memberName}
${enabled ? 'enabled' : 'disabled'}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`)
)
.on('groupStatusChange', (guild, group, enabled) =>
winston.info(oneLine`
[DISCORD]: Group ${group.id}
${enabled ? 'enabled' : 'disabled'}
${guild ? `in guild ${guild.name} (${guild.id})` : 'globally'}.
`)
);
client.registry
.registerDefaults()
.registerGroups([
['request', 'Requests'],
['issue', 'Issues'],
['tags', 'Tags'],
['subscriptions', 'Subscriptions'],
['util', 'Utility']
])
.registerCommandsIn(path.join(__dirname, 'commands'));
client.login(TOKEN);
process.on('unhandledRejection', err => winston.error(`Uncaught Promise Error: \n${err.stack}`));