-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (53 loc) · 1.98 KB
/
index.js
File metadata and controls
61 lines (53 loc) · 1.98 KB
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
const dayjs = require('dayjs')
const Discord = require('discord.js')
const { IncomingWebhook } = require('@slack/webhook')
const client = new Discord.Client()
const discordBotToken = process.env.DISCORD_BOT_TOKEN
const slackWebhookURL = process.env.SLACK_WEBHOOK_URL
if (discordBotToken == undefined || slackWebhookURL == undefined) {
console.error('Environment variables are not defined...')
process.exit(1)
}
const webhook = new IncomingWebhook(slackWebhookURL)
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on('message', (message) => {
if (
message.mentions.has(client.user.id) &&
message.content.includes('ping')
) {
message.reply('うつになった...')
}
})
client.on('voiceStateUpdate', (oldMember, newMember) => {
if (oldMember.channelID == undefined && newMember.channelID !== undefined) {
webhook.send({
attachments: [
{
fallback: `${newMember.member.user.username} が :loud_sound: ${newMember.channel.name} に参加しました`,
color: 'good',
author_icon: newMember.member.user.avatarURL().replace('webp', 'png'),
author_name: `${newMember.member.user.username}#${newMember.member.user.discriminator}`,
title: `:loud_sound: ${newMember.channel.name} に参加しました`,
ts: dayjs().unix(),
},
],
})
}
if (oldMember.channelID !== undefined && newMember.channelID == undefined) {
webhook.send({
attachments: [
{
fallback: `${oldMember.member.user.username} が :loud_sound: ${oldMember.channel.name} から離脱しました`,
color: 'danger',
author_icon: oldMember.member.user.avatarURL().replace('webp', 'png'),
author_name: `${oldMember.member.user.username}#${oldMember.member.user.discriminator}`,
title: `:loud_sound: ${oldMember.channel.name} から離脱しました`,
ts: dayjs().unix(),
},
],
})
}
})
client.login(discordBotToken)