-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.js
More file actions
107 lines (97 loc) · 4.16 KB
/
Copy pathbot.js
File metadata and controls
107 lines (97 loc) · 4.16 KB
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
#!/usr/bin/env node
const discordMessage = require('./Libraries/DatabaseLibrary/DiscordMessage.js');
const fs = require('fs');
const Discord = require('discord.js');
const auth = require('./auth/auth.json');
const snowflakes = require('./auth/snowflakes.json');
const sqlAuth = require('./auth/azureauth.json');
const BotCommon = require('./Libraries/BotLibrary/botcommon.js');
const common = require('./Libraries/CommonLibrary/common.js');
const reactions = require('./Libraries/BotLibrary/reactions.js');
const moment = require('moment');
const momentz = require('moment-timezone');
const bot = new BotCommon();
const sqlConfig = sqlAuth;
const botClient = new Discord.Client();
bot.botClient = botClient;
// Automation
//const automation = require('./Libraries/BotLibrary/automation.js');
//const automate = new automation(snowflakes.automatesheetid);
// Command and Event handlers.
botClient.commands = new Discord.Collection(); // Collection for all commands
botClient.aliases = new Discord.Collection(); // Collection for all aliases of every command
const modules = ['admin', 'automation', 'stats', 'misc']; // This will be the list of the names of all modules (folder) your bot has
modules.forEach(c => {
fs.readdir(`./commands/${c}/`, (err, files) => {
if (err) console.log(err);
const jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0) {
return console.log("[LOGS] Couldn't Find Commands!");
}
console.log(`[Commandlogs] Loaded ${files.length} commands of module ${c}`); // When commands of a module are successfully loaded, you can see it in the console
files.forEach(f => { // Now we go through all files of a folder (module)
const props = require(`./commands/${c}/${f}`); // Location of the current command file
botClient.commands.set(props.properties.command, props); // Now we add the commmand in the client.commands Collection which we defined in previous code
props.properties.aliases.forEach(alias => { // It could be that the command has aliases, so we go through them too
botClient.aliases.set(alias, props.properties.command); // If we find one, we add it to the client.aliases Collection
});
});
});
});
botClient.on('ready', () => {
if (auth.dev === 0) {
botClient.user.setActivity('Komennot: !help');
} else {
botClient.user.setActivity('Its Time For Kablew!');
}
});
botClient.on('error', () => bot.log('discord errored'));
botClient.login(auth.token);
botClient.on('raw', packet => {
if (auth.dev === 0) {
if (['MESSAGE_REACTION_ADD'].includes(packet.t)) {
reactions.handleReactions(packet);
}
if (['GUILD_MEMBER_ADD'].includes(packet.t)) {
bot.logEvent('```diff\n+Uusi käyttäjä (' + packet.d.user.id + ') ' + packet.d.user.username + ' liittyi serverille.```');
}
if (['GUILD_MEMBER_REMOVE'].includes(packet.t)) {
bot.logEvent('```diff\n-Käyttäjä (' + packet.d.user.id + ') ' + packet.d.user.username + ' poistui serveriltä.```');
}
} else {
if (['MESSAGE_REACTION_ADD'].includes(packet.t)) {
if (packet.d.emoji.name === 'idea') {
//reactions.handleReactions(packet);
}
}
}
});
botClient.on('message', msg => {
const prefix = auth.prefix;
const messageArray = msg.content.split(" ");
const command = messageArray[0];
const properties = command.properties;
const args = messageArray.slice(1);
const commandfile = botClient.commands.get(command.slice(prefix.length)) || botClient.commands.get(botClient.aliases.get(command.slice(prefix.length)));
if(commandfile) commandfile.run(msg, args);
// Reaaliaikainen syncronointi
if (!(msg.channel instanceof Discord.DMChannel) && auth.dev === 0) {
if (msg.channel.id !== '532946068967784508' && msg.channel.id !== '524337438462836779' && msg.channel.id !== '502911862606659586') {
discordMessage.save(msg);
bot.messagesSynced++;
}
}
});
/**
* Globaali virheenkäsittelijä
*/
process.on('uncaughtException', (e) => {
console.info('uncaughtException even-listener has invoked');
console.error(e);
});
exports.discord = Discord;
exports.client = botClient;
exports.bot = bot;
exports.snowflakes = snowflakes;
exports.common = common;
exports.sqlConfig = sqlConfig;