-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
73 lines (64 loc) · 1.91 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
const Discord = require('discord.js');
const Long = require('long');
const { playHonk, sendGif } = require('./goose');
const client = new Discord.Client();
const { channels, guilds } = client;
client.on('ready', () => {
let start = 10; // Minutes before another action can start
let range = 5; // Range in minutes that an action can start after start time
// Randomized Actions other period of time
setInterval(() => {
switch (Math.floor(Math.random() * 2)) {
case 0:
let found = false;
channels.tap(channel => {
if (channel.type === 'voice' && found === false) {
playHonk(channel);
found = true;
}
});
break;
case 1:
sendGif(getDefaultChannel(guilds.first()));
break;
}
}, Math.floor(Math.random() * (range * 60000) + start * 60000));
});
client.on('message', msg => {
switch (msg.content.toLowerCase()) {
case 'honk':
if (msg.member.voiceChannel) playHonk(msg.member.voiceChannel);
break;
case 'goose':
sendGif(msg.channel);
break;
}
});
client.on('guildMemberAdd', member => {
const channel = getDefaultChannel(member.guild);
channel.send(`Honk! ${member}`);
});
client.login(process.env.BOT_TOKEN);
// Source:
// https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/frequently-asked-questions.md
const getDefaultChannel = guild => {
if (guild.channels.has(guild.id)) return guild.channels.get(guild.id);
const generalChannel = guild.channels.find(
channel => channel.name === 'general'
);
if (generalChannel) return generalChannel;
return guild.channels
.filter(
c =>
c.type === 'text' &&
c.permissionsFor(guild.client.user).has('SEND_MESSAGES')
)
.sort(
(a, b) =>
a.position - b.position ||
Long.fromString(a.id)
.sub(Long.fromString(b.id))
.toNumber()
)
.first();
};