-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.js
109 lines (102 loc) · 3.27 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
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
109
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
var lastMessageMap = new Map();
bot.on("any", function(event) {
/*console.log(event)*/ //Logs every event
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if(userID == bot.id){
return;
}
var timestamp = evt.d.timestamp;
if(!lastMessageMap.has(userID)){
lastMessageMap.set(userID, timestamp);
/*
bot.sendMessage({
to: channelID,
message: user + " are you fucking new here?"
});
*/
}else {
var lastTimeStamp = lastMessageMap.get(userID);
var currentDate = Date.parse(timestamp);
var lastDate = Date.parse(lastTimeStamp);
var distance = currentDate.valueOf() - lastDate.valueOf();
if(distance > 604800000){
bot.sendMessage({
to: channelID,
message: "A wild " + user + " appears. You haven't been seen in over a week."
});
}
lastMessageMap.set(userID, timestamp);
}
if (message.toLowerCase().includes("i'm going")){
bot.sendMessage({
to: channelID,
message: "He wasn't"
});
} else if (message.toLowerCase().includes("page ")){
bot.sendMessage({
to: channelID,
message: 'And lo ' + user + ' put on his rules lawyer hat'
});
} else if (message.toLowerCase().includes("rolled:") && (
message.toLowerCase().includes("d20") && message.toLowerCase().includes("(20)"))){
var trolls = ["cheating", "rewriting " + user, "sacrificing to Tzeentch"];
bot.sendMessage({
to: channelID,
message: 'Nobody suspected ' + message.substring(0,message.indexOf(','))+ ' was ' + trolls[Math.floor((Math.random() * trolls.length))] + ', but he was. He truly was.'
});
} else if (message.toLowerCase().includes("results") && (
message.toLowerCase().includes(":failure:") || message.toLowerCase().includes(":despair:"))){
bot.sendMessage({
to: channelID,
message: '"Fuck you D1-C3", he thought.'
});
} else if (message.toLowerCase().includes("results") && (
message.toLowerCase().includes(":success:") && message.toLowerCase().includes(":triumph:"))){
bot.sendMessage({
to: channelID,
message: '"Good job D1-C3!", he thought.'
});
}
if (message.substring(0, 1) == '>') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
case 'help':
bot.sendMessage({
to: channelID,
message: 'I currently have no commands and must simply contemplate the futility of my existence'
});
break;
case 'foo':
bot.sendMessage({
to: channelID,
message: 'user: ' + user + ' UserID: ' + userID
});
break;
// Just add any case commands if you want to..
}
}
});