-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
74 lines (59 loc) · 2.13 KB
/
bot.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
const config = require("./config.json");
const Discord = require("discord.js");
const client = new Discord.Client();
const Utils = require("./utils.js");
const utils = new Utils(this, client);
let halanRegexp = /^ial(:?an)?\b/i; //Hal or Halan
let admin = null;
var mysql = require('mysql');
const connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'password',
database : 'ialan',
});
connection.connect(function(err) {
// connected! (unless `err` is set)
console.log(err);
});
let defaultResponder = require("./onMessageListeners/confused.js");
let onMesageListeners = [
require("./onMessageListeners/say.js"),
require("./onMessageListeners/help.js"),
require("./onMessageListeners/games.js"),
require("./onMessageListeners/gifme.js"),
require("./onMessageListeners/insults.js"),
require("./onMessageListeners/compliments.js"),
];
let onPresenceUpdateListeners = [
require("./presenceUpdate/partyBroadcaster.js"),
];
let onReady = function () {
console.log("Halan Online!");
admin = client.users.get("115308057994592259"); //Ursoc's Id
}
let notifyOnMessageListeners = function(message) {
if (!message.content.match(halanRegexp) || message.author.bot) return;
utils.removeBotName(message.content);
utils.resolveToMentions(message);
let responded = false;
onMesageListeners.forEach(listener => {
if (listener.sendMessage(message)) {
responded = true;
}
});
if (!responded){
defaultResponder.sendMessage(message);
}
}
let notifyOnPressenceUpdateLisenters = function(oldGuildMember, newGuildMember) {
onPresenceUpdateListeners.forEach(listener => { listener.sendMessage(oldGuildMember, newGuildMember); });
}
client.on("ready", () => { onReady(); });
client.on("message", (message) => { notifyOnMessageListeners(message); });
client.on("presenceUpdate", (oldGuildMember, newGuildMember) => { notifyOnPressenceUpdateLisenters });
client.login(config.token);
module.exports.halanRegexp = halanRegexp;
module.exports.client = client;
module.exports.utils = utils;
module.exports.connection = connection;