forked from pixlbreaker/ReminderBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
154 lines (125 loc) · 4.29 KB
/
index.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Constants
const Discord = require('discord.js');
const DatabaseScripts = require('./tools.js');
const config = require('./config.json')
const client = new Discord.Client();
const channel = new Discord.Channel(client);
// Replace all function
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
// Client on Message
client.on('message', msg => {
// Quits the Bot
if (msg.content === '!quitbot' && msg.author.id === '109122837524017152') {
msg.reply('Goodbye!');
client.destroy();
console.log('Disconnected...');
process.exit();
// Reminds the User
} else if (msg.content.toLowerCase().startsWith('!remindme')) {
var message = msg;
try {
// Variables
var returntime;
var timemeasure;
msg = msg.content.split(' ');
console.log('Message recieved from ' + message.author.id + ' at ' + Date.now().toString());
// Sets the return time
timemeasure = msg[1].substring((msg[1].length - 1), (msg[1].length))
returntime = msg[1].substring(0, (msg[1].length - 1))
// Based off the delimiter, sets the time
switch (timemeasure) {
case 's':
returntime = returntime * 1000;
break;
case 'm':
returntime = returntime * 1000 * 60;
break;
case 'h':
returntime = returntime * 1000 * 60 * 60;
break;
case 'd':
returntime = returntime * 1000 * 60 * 60 * 24;
break;
default:
returntime = returntime * 1000;
break;
}
// Returns the Message
client.setTimeout(function () {
// Removes the first 2 array items
msg.shift();
msg.shift();
// Creates the message
var content = msg.join();
content = content.replaceAll(',', ' ');
message.reply(content);
console.log('Message sent to ' + message.author.id + ' at ' + Date.now().toString());
}, returntime)
} catch (e) {
message.reply("An error has occured, please make sure the command has a time delimiter and message");
console.error(e.toString());
}
// List of commands
}else if (msg.content.toLowerCase() === "!reminderbot") {
msg.channel.send("Hello I am reminder bot:\n\n!reminderbot \t\tList of all Commands\n!quit \t\tTurns off the bot\n!remindme \t\t {time} {message}\n\t{time} Please have the amount of time be denoted by a time character.\n\t\tm - minutes, s - seconds, d - days.\n!remind {@User} {time} {message}\n\t{time} Please have the amount of time be denoted by a time character.\n\t\tm - minutes, s - seconds, d - days.\n\t{@User} So far you can use the user's name with the @ symbol.\n\n--- Created and Managed by pixlbreaker ---");
// Reminds a specific user
} else if (msg.content.toLowerCase().startsWith('!remind')) {
var message = msg;
try {
// Variables
var returntime;
var timemeasure;
var userid;
msg = msg.content.split(' ');
console.log('Message recieved from ' + message.author.id + ' at ' + Date.now().toString());
// Sets the userid for the recipiant
userid = client.users.get(msg[1].replace('<@!', '').slice(0, -1))
// Sets the return time
timemeasure = msg[2].substring((msg[2].length - 1), (msg[2].length))
returntime = msg[2].substring(0, (msg[2].length - 1))
// Based off the delimiter, sets the time
switch (timemeasure) {
case 's':
returntime = returntime * 1000;
break;
case 'm':
returntime = returntime * 1000 * 60;
break;
case 'h':
returntime = returntime * 1000 * 60 * 60;
break;
case 'd':
returntime = returntime * 1000 * 60 * 60 * 24;
break;
default:
returntime = returntime * 1000;
break;
}
// Returns the Message
client.setTimeout(function () {
// Removes the first 2 array items
msg.shift();
msg.shift();
msg.shift();
// Creates the message
var content = msg.join();
content = content.replaceAll(',', ' ');
message.channel.send(userid + content);
console.log('Message sent to ' + userid + ' at ' + Date.now().toString());
}, returntime)
} catch (e) {
message.reply("An error has occured, please make sure the command has a time delimiter and message");
console.error(e.toString());
}
// List of Commands
}
});
// When the thing is ready
client.on('ready', () => {
console.log('Logged in...');
});
// Login
client.login(config.token);