-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
319 lines (268 loc) · 10.5 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
`use strict`
//Modules
const Discord = require('discord.js');
let unirest = require('unirest');
let music = require('musicmatch')({ apikey: "" });
let fetch = require('node-fetch');
const ud = require('urban-dictionary')
let appid = "";
let apikey = "";
const color = 0xED203F;
let embed = new Discord.RichEmbed()
.setTitle('Error')
.setColor(color)
.setDescription('Invalid command! use `=>help` for a list of commands!');
let field = new Array(3);
//Constants
const bot = new Discord.Client();
const token = '';
const PREFIX = '=>';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
bot.on('ready', () => {
console.log("+bot is online+");
bot.on('message', msg => {
let args = msg.content.substring(PREFIX.length).split(" ");
if (msg.member.roles.find(r => r.name === '👑Founder👑') || msg.member.roles.find(r => r.name === 'staff')) {
switch (args[0].toLowerCase()) {
case 'clear':
clear(args, msg);
break;
case 'role':
role(args, msg);
break;
}
}
switch (args[0].toLowerCase()) {
case 'ping':
msg.reply('pong!');
break;
//gives the wheather of a location
//=>wheather [place]
case 'weather':
weather(args, msg);
break;
// definitie can urban dictionary
// =>define [term]
case 'define':
define(args, msg);
break;
// Random meme
// =>meme
case 'meme':
rndmMeme(args, msg);
break;
//Give the lyrics
//=>lyrics [song name],[artist]
case 'lyrics':
lyrics(args, msg);
break;
//gives game info
//=>game [game titel]
case 'game':
gameInfo(args, msg);
break;
//give suggestions based on a game
//=>suggest [game]
case 'suggest':
suggestGame(args, msg);
break;
case 'tictactoe':
break;
//gives all the commands of the bot
case 'help':
embed.setTitle("Commands").setColor(color).setDescription("\n -__Random meme__ =>meme\n -__define__ =>define [term]\n -__game__ =>game [game titel]\n -__suggest__ =>suggest [game]\n -__weather__ =>weather [place]");
msg.channel.send(embed);
break;
}
})
});
function gameInfo(args, msg) {
let game = args[1];
for (let i = 2; i < args.length; i++) {
game += "-" + args[i];
}
let mssg, titelGame;
fetch(`https://api.rawg.io/api/games/${game}`).then(res => {
return res.json();
}).then(res => {
if (res.detail != "Not found.") {
//msg.channel.send({ files: [res.background_image] });
titelGame = res.name;
mssg = `${res.description_raw} \n\n__Rating__ : ${res.rating}/5 \n\n__Platforms__\n`;
for (let i = 0; i < res.platforms.length - 1; i++) {
mssg += `${res.platforms[i].platform.name}, `;
}
mssg += `${res.platforms[res.platforms.length - 1].platform.name}`;
embed.setTitle(titelGame).setColor(color).setDescription(mssg).setImage(res.background_image);
} else {
titelGame = "Game not found";
mssg = ` - Check the spelling`;
embed.setTitle(titelGame).setColor(color).setDescription(mssg);
}
msg.channel.send(embed);
embed.setImage();
})
}
function suggestGame(args, msg) {
let game1 = args[1];
for (let i = 2; i < args.length; i++) {
game1 += "-" + args[i];
}
console.log(game1);
fetch(`https://api.rawg.io/api/games/${game1}`).then(res => {
return res.json();
}).then(res => {
if (res.detail != "Not found.") {
console.log("got here3 +" + res.slug + "+");
fetch(`https://api.rawg.io/api/games/${res.slug}/suggested?page_size=5`).then(res2 => {
return res2.json();
}).then(res2 => {
let mssg1 = "";
for (let i = 0; i < res2.results.length; i++) {
mssg1 += `\n -${res2.results[i].name}`;
}
embed.setTitle(`Recomended games based on ${res.name}`).setColor(color).setDescription(mssg1);
msg.channel.send(embed);
})
} else {
embed.setTitle("titelGame").setColor(color).setDescription("- Check the spelling");
msg.channel.send(embed);
}
})
}
function lyrics(args, msg) {
let title = args[1];
for (let i = 2; i < args.length; i++) {
title += " " + args[i];
}
console.log(title);
music.trackSearch({ q: title, page: 1, page_size: 1, f_has_lyrics: 1 })
.then(function (data) {
let trackID = data.message.body.track_list[0].track.track_id;
music.trackLyrics({ track_id: trackID })
.then(function (data2) {
//msg.channel.send(">>> **" + data.message.body.track_list[0].track.track_name + "** by " + data.message.body.track_list[0].track.artist_name + " \n" + data2.message.body.lyrics.lyrics_body);
embed.setTitle(`${data.message.body.track_list[0].track.track_name} by ${data.message.body.track_list[0].track.artist_name}`).setColor(color).setDescription(data2.message.body.lyrics.lyrics_body);
msg.channel.send(embed);
}).catch(function (err) {
console.log(err);
})
}).catch(function (err) {
console.log(err);
})
}
function define(args, msg) {
let definition = args[1];
for (let i = 2; i < args.length; i++) {
definition += " " + args[i];
}
ud.term(definition).then((result) => {
const entries = result.entries
embed.setTitle(`${entries[0].word}`).setColor(color).setDescription(`${entries[0].definition} \n __Example__\n${entries[0].example}`);
msg.channel.send(embed);
}).catch((error) => {
console.error(error.message)
msg.channel.send(embed);
})
}
function rndmMeme(args, msg) {
let reqMeme = unirest("GET", "https://some-random-api.ml/meme");
msg.channel.bulkDelete(1);
reqMeme.headers({
"x-rapidapi-host": "ronreiter-meme-generator.p.rapidapi.com",
"x-rapidapi-key": "9d4d6195d1mshb1dcea69f7b154ep101d69jsn250af4fe72fa"
});
reqMeme.end(function (res) {
if (res.error) throw new Error(res.error);
embed.setTitle(res.body.caption).setColor(color).setImage(res.body.image).setDescription("");
msg.channel.send(embed);
embed.setImage();
});
}
function weather(args, msg) {
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${args[1]}&APPID=${appid}`).then(res => {
return res.json();
}).then(res => {
embed.setTitle('weather').setColor(color).setDescription("in **" + args[1] + "** it is " + res.weather[0].main);
msg.channel.send(embed);
})
}
function role(args, msg) {
let rMember = msg.guild.member(msg.mentions.users.first()) || msg.guild.member.length(arg[0]);
if (!rMember) return msg.reply(args[1] + " is not a user");
let role = args[2];
for (let i = 3; i < args.length; i++) {
role += " " + args[i];
}
role = role.trim();
if (!role) return msg.reply(" No role selected");
let gRole = msg.guild.roles.find(`name`, role);
if (!gRole) return msg.reply(role + " not found");
if (rMember.roles.has(gRole.id));
rMember.addRole(gRole.id);
embed.setTitle('Role Update').setColor(color).setDescription(`Congrats to <@${rMember.id}> been given the role ${gRole.name}.`);
msg.channel.send(embed);
}
function clear(args, msg) {
if (!args[1]) return msg.reply('Missing amount')
//msg.channel.bulkDelete(parseInt(args[1]) + 1);
//console.log(msg.channel.name)
let messages1 = [];
let count = 0;
let k;
for (let a of bot.channels.array()) {
if (a.name == msg.channel.name) {
k = a
}
}
k.fetchMessages()
.then((messages) => {
messages1 = messages.array();
let minDate = new Date();
minDate.setDate(minDate.getDate() - 14);
for (let b of messages1) {
let myDate = new Date(b.createdTimestamp);
if (myDate > minDate) {
count++;
}
}
}).then(()=>{
if(count < parseInt(args[1]) + 1){
msg.channel.bulkDelete(count);
messaged(count, msg);
}else{
msg.channel.bulkDelete(parseInt(args[1]) + 1);
messaged(args[1], msg);
}
})
.catch(console.error);
}
function tictactoe(args, msg, field){
field[args[0].substring(0,1),args[0].substring(1,1)] = args[1];
let tictactoe = `
>>> \`\`\`
1 2 3
a |${field[0,0]}|${field[0,1]}|${field[0,2]}|
b |${field[1,0]}|${field[1,1]}|${field[1,2]}|
c |${field[2,0]}|${field[2,1]}|${field[2,2]}|
\`\`\`
`
embed.setdescription(tictactoe).setColor(color).setTitle("Tic Tac toe");
msg.channel.send(embed);
}
function reset(field){
for(let i = 0; i < 3; i++){
for(let j = 0; i < 3; i++){
field[i,j] = '_';
}
}
}
async function messaged(number, msg){
embed.setTitle('Clear').setColor(color).setDescription(`Cleard ${number} messages.`);
msg.channel.send(embed);
await sleep(2000);
msg.channel.bulkDelete(1);
}
bot.login(token);