-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
94 lines (83 loc) · 2.5 KB
/
index.ts
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
require('dotenv').config();
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix: string = "!!"
let previousMessage: string = '';
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag} `)
});
client.on('message', msg => {
console.log(msg.content);
if (!msg.content.startsWith(prefix)) {
return;
}
if (previousMessage === msg.content.toLowerCase()) {
msg.reply(`You already asked that you wanker`)
return;
}
previousMessage = msg.content.toLowerCase()
const parts = msg.content.split(' ') as string[];
if (parts.length < 1) {
return;
}
const command = parts[0].toLowerCase();
parts.splice(0, 1);
switch (command) {
case "!!help":
msg.reply(`pick your poison:
\`\`\`md
- caniuse: caniuse.com
- docs: devdocs.io
- g: lmgtfy.com
- so: stackoverflow.com
- xkcd: xkcd.com (by number)
\`\`\``)
break;
case "!!caniuse":
msg.channel.send({
content: `https://caniuse.com#search=${encodeURI(parts.join(' '))}`
})
break;
case "!!docs":
// msg.reply(`https://devdocs.io/#q=${parts.join('')}`)
msg.channel.send({
content: `https://devdocs.io/#q=${parts.join('')}`
})
break;
case "!!g":
msg.channel.send({
content: `https://lmgtfy.com/?q=${parts.join('+')}`
})
break
case "!!so":
msg.channel.send({
content: `https://stackoverflow.com/search?q=${parts.join('+')}`
})
break;
case "!!xkcd":
const comic = Number(parts[0]);
if (comic >= 0) {
msg.channel.send({
content: `https://xkcd.com/${comic}/`
})
} else {
msg.channel.send({
content: `I'm expecting a number to a comic. Try again.
https://media.giphy.com/media/d2VNGdRDbD3baHte/giphy.gif
`
})
}
break;
default:
msg.channel.send({
content: `...I have no idea what you're asking??...
https://media.giphy.com/media/aZ3LDBs1ExsE8/giphy.gif
`
})
break;
}
})
if (!process.env.DISCORD_BOT_TOKEN) {
throw new Error('DISCORD_BOT_TOKEN not found in environment variables');
}
client.login(process.env.DISCORD_BOT_TOKEN)