-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
110 lines (68 loc) · 2.64 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
const Discord = require('discord.js')
const bot = new Discord.Client();
const token = "Njk5NDA2NzEyNzMzNDMzOTg2.XpVLFw.Lb_lSR_ppJ9vThPcJlP8D-M-UwU";
const prefix = ".";
const emojiCharacters = require('./emojis');
const cheerio = require('cheerio');
const request = require('request');
var isReady = true;
const fs = require('fs');
const ytdl = require('ytdl-core');
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
bot.on('ready', () => {
console.log(`Ahoy! ${emojiCharacters['?']}`);
});
bot.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case "help":
bot.commands.get('Cmds').execute(message, args);
break;
case "clear":
bot.commands.get('Clear').execute(message, args);
message.channel.send(`You cleared ${args[1]} messages.`);
break;
case "Sad":
bot.commands.get('SadBoi').execute(message, args);
break;
}
});
bot.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case 'image':
image(message);
break;
}
});
function image(message){
var options = {
url: "https://www.google.com/search?q=cats&tbm=" + "cat",
method: "GET",
headers: {
"Accept": "text/html",
"User-Agent": "Chrome"
}
};
request(options, function(error, response, responseBody) {
if (error) {
return;
}
$ = cheerio.load(responseBody);
var links = $('img.rg_i a.link');
var urls = new Array(links.length).fill(0).map((v, i) => links.eq(i).attr("href"));
console.log(urls);
if (!urls.length) {
return;
}
// Send result
message.channel.send( urls[Math.floor(Math.random() * urls.length)]);
});
}
//---------------------------------------------------- Music Bot
bot.login(token);