-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
234 lines (212 loc) · 9.5 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require("./config.json");
const ytdl = require("ytdl-core");
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
}
function mentionRandomPerson(message, onlyOnline){
let guild = message.guild;
let members = guild.members;
let gm = members.random(1)[0].user;
while (true){
if (gm.bot) {
console.log("Chose " + gm.username + ", but they're a bot.");
members.delete(gm.id);
}
else if (gm.presence.status === "offline" && onlyOnline) {
console.log("Chose " +gm.username+", but they're offline.");
members.delete(gm.id);
}
else if (gm.presence.status === "dnd" && onlyOnline) {
console.log("Chose " +gm.username+", but they're not to be disturbed.");
members.delete(gm.id);
}
else if (gm.equals(message.author)) {
console.log("Chose " +gm.username+", but they're the one who requested someone.");
members.delete(gm.id);
}
else {
console.log("Chose "+gm.username+"!");
console.log();
message.channel.send("<@" + gm.id + ">");
break;
}
if (members.size === 0){
console.log("Nobody to send the message to!");
console.log();
break;
}
gm = members.random(1)[0].user;
}
}
function queueAudio(video, message){
let vC = undefined;
let info = undefined;
try {
config.music.queue.push(ytdl(video, {filter: 'audioonly'}));
}
catch(err){
message.channel.send("That was either an invalid video or a playlist.");
}
if (config.music.queue.length > 1 || config.music.playing) {
ytdl.getBasicInfo(video).then(v => {
info = v.player_response.videoDetails.title.toString();
message.channel.send("Queued " + info + ".");
config.music.titles.push(info)
});
}
else {
ytdl.getBasicInfo(video).then( v => {
info = v.player_response.videoDetails.title.toString();
message.channel.send("Playing " + info + ".")});
}
//debugger;
//console.log(config.music.playing);
if (message.member.voiceChannel) {
message.member.voiceChannel.join();
if (!config.music.playing) {
vC = client.voiceConnections.first();
//
jukeBox(vC);
}
} else {
message.channel.send("You need to join a voice channel first!");
}
}
function endOfStream(broadcast) {
console.log("Stream ended, playing next song.");
config.music.playing = false;
jukeBox(broadcast);
}
function jukeBox(broadcast){
if (config.music.queue.length === 0) { config.music.playing = false; return;}
else if (!config.music.playing){
config.music.playing = true;
//console.log(config.music.playing);
broadcast.playStream(config.music.queue.shift()).on("end", v => { endOfStream(broadcast);});
broadcast.dispatcher.setVolume(config.music.volume/100.0);
config.music.titles.shift();
}
return;
}
client.on('message', async message => {
//debugger
if (message.author.bot) return; //no bots
if (message.content.indexOf(config.settings.prefix) === 0) {
const args = message.content.slice(config.settings.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "help"){
let outMessage = "";
outMessage += "Commands:```";
if (config.settings.useVoice) {
outMessage += (config.settings.prefix + "play: Plays a youtube link.\n");
outMessage += (config.settings.prefix + "pause: Pauses the player.\n");
outMessage += (config.settings.prefix + "resume: Resumes playback.\n");
outMessage += (config.settings.prefix + "skip: Skips the current song.\n");
outMessage += (config.settings.prefix + "leave: Leaves the voice channel.\n");
}
if(config.settings.useMemes){
outMessage += (config.settings.prefix + "meme: Sends a meme in the channel\n");
}
outMessage += (config.settings.prefix + "anyone: Mentions anyone, even if they're offline.\n");
outMessage += (config.settings.prefix + "someone: Mentions only people who are online.```");
message.channel.send(outMessage);
}
if (config.settings.useMemes && command === "meme") {
message.channel.send('Here\'s your meme:', {file: config.settings.memes + 'meme('+getRandomIntInclusive(1,config.settings.memeCount)+').jpg'});
return;
}
if (config.settings.useVoice) {
if (command === "play") {
let fileToPlay = "";
for (let ii in args){
fileToPlay += args[ii];
}
queueAudio(fileToPlay, message);
//message.channel.send("Playing "+fileToPlay+".");
if (config.settings.logging) console.log(message.member.nickname +" requested the file "+fileToPlay);
return;
}
else if (command === "pause") {
client.voiceConnections.first().dispatcher.pause();
message.channel.send("Paused. Use resume to continue playing.")
}
else if (command === "resume") client.voiceConnections.first().dispatcher.resume();
else if (command === "skip") client.voiceConnections.first().dispatcher.end();
else if (command === "leave") {
let vc = message.member.voiceChannel;
vc.leave();
return;
}
else if (command === "volume") {
let volume = args[0];
config.settings.volume = volume;
client.voiceConnections.first().dispatcher.setVolume(volume/100.0);
if (volume > 100) message.channel.send("Volume set to "+volume+". `Warning: the audio may clip at this level.`");
else message.channel.send("Volume set to "+volume+".");
if (config.settings.logging) console.log(message.member.nickname +" changed the volume to " + config.settings.volume);
return;
}
else if (command === "queue") {
let outMessage = "";
outMessage += "Queue:\n\n";
for (let ii = 0; ii < config.music.titles.length; ii++) {
outMessage += ((ii + 1).toString() + ": " + config.music.titles[ii] + "\n");
}
message.channel.send(outMessage);
}
else {}
}
if (command === "anyone"){
mentionRandomPerson(message, false);
return;
}
else if (command === "someone"){
mentionRandomPerson(message, true);
return;
}
if (command === "prefix"){
config.settings.prefix = args[0];
return;
}
}
else {
let msg = message.content.toLowerCase();
if (msg.includes("##")) return;
if (message.isMentioned(client.users.get("435060306197086219"))) message.channel.send("That's me!");
if (config.settings.useRawr) {
if (msg.includes("rawr")) message.channel.send('XD');
else if (msg.includes("owo")) message.channel.send('What\'s this?');
}
if (config.settings.useGaming) {
if (msg.includes("fortnite")) message.channel.send('Fortnite is not relevant\.');
else if (msg.includes("gmod") || msg.includes("garry\'s mod") || msg.includes("garrys mod") || msg.includes("g mod")) message.channel.send('Is it really Garry\'s Mod?');
else if (msg.includes("factorio") && msg.includes("satis")) message.channel.send('The unholy combination');
else if (msg.includes("satisfactory")) message.channel.send("Factorio 2: Electric Boogaloo");
else if (msg.includes("factorio")) message.channel.send("Good game");
else if (msg.includes("apex")) message.channel.send('Is Apex the *peak* of gaming?');
}
}
});
client.login(config.settings.token);
client.on('ready', () => {
console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} servers.`);
console.log('Using memes: '+config.settings.useMemes);
console.log('Using gaming: '+config.settings.useGaming);
console.log('Using voice: '+config.settings.useVoice);
console.log('Using rawr: '+config.settings.useRawr);
console.log('Using logging: '+ config.settings.logging);
console.log();
client.user.setActivity('God', { type: 'PLAYING' });
});
client.on("guildCreate", guild => {
// This event triggers when the bot joins a guild.
console.log(`New server joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
});
client.on("guildDelete", guild => {
// this event triggers when the bot is removed from a guild.
console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
});