-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
97 lines (80 loc) · 2.83 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
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === '!ping') {
msg.reply('pong');
}
});
client.on('message', msg => {
if (/^!spongecase/i.test(msg.content)) {
let tokens = msg.content.split(' ')
tokens.shift();
let str = tokens.join(' ');
// here's the dang algorithm
let counter = 0;
let spongeArray = [];
str.split('').forEach((chr) => {
if (/[A-Za-z]/.test(chr)) {
if (counter % 2 == 0) {
spongeArray.push(chr.toUpperCase());
} else {
spongeArray.push(chr.toLowerCase());
}
counter = counter + 1;
} else {
spongeArray.push(chr);
}
});
spongeString = spongeArray.join('');
msg.channel.send(spongeString);
}
});
client.on('message', async (msg) => {
if (/^!compliment/i.test(msg.content)) {
const fetch = require('node-fetch');
let response = await fetch('https://complimentr.com/api');
let data = await response.json();
await msg.channel.send(data.compliment);
}
});
client.on('message', async (msg) => {
if (/^!summon/i.test(msg.content)) {
// removes command
let tokens = msg.content.split(' ')
tokens.shift();
let str = tokens.join(' ');
const useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36"
const fetch = require('node-fetch');
const jsdom = require('jsdom')
const { JSDOM } = jsdom;
let response = await fetch (`https://www.google.com/search?q=${encodeURI(str)}&tbm=isch`, { headers: {"User-Agent": useragent }})
let html = await response.text()
let dom = new JSDOM(html)
let imageurl = JSON.parse(dom.window.document.getElementsByClassName('rg_meta').item(0).innerHTML).ou;
await msg.channel.send(`**SUMMONED ${str.toUpperCase()}!**\n${imageurl}`);
}
});
client.on('message', async (msg) => {
if (/^!(fullwidth|fw)/i.test(msg.content)) {
// removes command
let tokens = msg.content.split(' ')
tokens.shift();
let str = tokens.join(' ');
let output = ""
for (let i = 0; i < str.length; i++) {
let character = str.charCodeAt(i);
if (character == 32) {
output = output + String.fromCharCode(0x3000);
} else if (character > 0x20 && character < 0x7F) {
output = output + String.fromCharCode(0xFF00 - 0x20 + character);
} else {
output = output + String.fromCharCode(character);
}
}
await msg.channel.send(output);
}
});
client.login(process.env.BOT_TOKEN);