-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
75 lines (57 loc) · 2.25 KB
/
main.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
const Discord = require('discord.js')
const client = new Discord.Client()
const bot_secret_token = process.env.BOT_TOKEN
const slack_webhook_url = process.env.SLACK_WEBHOOK
if (bot_secret_token === "") {
console.log("Warning, missing bot token")
return
}
if (slack_webhook_url === "") {
console.log("Warning, missing slack webhook")
return
}
const slackWebhook = require('@slack/webhook');
const webhook = new slackWebhook.IncomingWebhook(slack_webhook_url);
client.on('ready', () => {
console.log("Connected as " + client.user.tag)
console.log("Servers:")
client.guilds.forEach((guild) => {
console.log(" - " + guild.name)
// List all channels
guild.channels.forEach((channel) => {
console.log(` -- ${channel.name} (${channel.type}) - ${channel.id}`)
})
})
})
client.on('voiceStateUpdate', (oldMember, newMember) => {
// Here I'm storing the IDs of their voice channels, if available
let oldChannel = oldMember.voiceChannel ? oldMember.voiceChannel.id : null;
let newChannel = newMember.voiceChannel ? newMember.voiceChannel.id : null;
if (oldChannel == newChannel) return; // If there has been no change, exit
let channelID = newChannel ? newChannel : oldChannel
let didJoin = newChannel ? true: false;
let who = oldMember.voiceChannel ? oldMember : newMember;
let whoName = who.nickname || who.user.username;
let channel = client.channels.get(channelID)
const ignoredChannels = [/exec/gmi]
if (ignoredChannels.some((tester) => tester.test(channel.name))) {
console.log("bailing, private channel", channel.name)
return
}
const ignoredUsers = [/boni/gmi]
let ignoredTester = ignoredUsers.find((tester) => tester.test(whoName))
if (ignoredTester !== undefined) {
console.log(`bailing, ignoring user ${whoName} via ${ignoredTester}`)
return
}
let action = didJoin ? "joined" : "left"
console.log(`user ${who.nickname} ${action} the channel ${channel.name}: avatar: ${who.user.avatarURL}`)
let link = didJoin ? `<https://discord.gg/7qGEdSQ|Click here> to join!` : ""
webhook.send({
text: `${whoName} ${action} the channel _${channel.name}_. ${link}`,
"username": whoName,
"icon_url": who.user.avatarURL,
});
return
})
client.login(bot_secret_token)