-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
113 lines (99 loc) · 2.9 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import 'dotenv/config'
import Discord from 'discord.js'
import { DiscordClient } from './src/types/DiscordClient'
import { PrivacyPolicyEmbed } from './src/constants/embeds'
import { clientOpts } from './config'
import logger from './src/utils/logger'
const bot = new Discord.Client(clientOpts) as DiscordClient
bot.logger = logger
bot.on('message', async (message) => {
if (message.author.bot) return
if (message.cleanContent.startsWith('@Lyrics Finder')) {
return void await message.channel.send(
"Mentions are not supported anymore!\nThe bot's prefix is now `~!`. Try `~!help`!"
)
}
if (!message.content.startsWith('~!')) return
if (message.content.length <= 2) return
// If message starts with a mention. Delete this after some time
const msg = message.content.substring(2).trim()
const cmd = msg.split(' ')[0].toLowerCase()
// Add commands here
switch (cmd) {
case 'about':
require('./commands/about').exec(bot, message)
break
case 'info':
case 'status':
case 'stats':
require('./commands/info').exec(bot, message)
break
case 'invite':
message.channel.send('**Invite Link**: https://lyrics-finder.angeloanan.xyz')
break
case 'ping':
message.channel.send(`Pong! *${Math.round(bot.ws.ping)}ms*`)
break
case 'help':
require('./commands/help').exec(bot, message)
break
case 's':
case 'search':
case 'lyrics':
require('./commands/search').search(bot, message)
break
case 'np':
case 'nowplaying':
require('./commands/nowplaying').nowPlaying(bot, message)
break
case 'autosearch':
case 'auto':
require('./commands/autosearch').exec(bot, message)
break
case 'support':
message.channel.send(
'**Support the bot (and the creator) here**: https://lyrics-finder.angeloanan.xyz/support'
)
break
case 'privacy':
case 'privacypolicy':
case 'policy':
message.channel.send(PrivacyPolicyEmbed())
break
case 'stopautosearch':
case 'stopauto':
require('./commands/stopautosearch').exec(bot, message)
break
}
})
/*
Events below should have a handler on ./events
*/
bot.on('guildCreate', async (guild) => {
require('./events/guildCountUpdate').handle(bot, guild)
})
bot.on('guildDelete', async (guild) => {
require('./events/guildCountUpdate').handle(bot, guild)
})
bot.on('ready', async () => {
require('./events/ready').handle(bot)
})
bot.on('presenceUpdate', (_, presence) => {
require('./events/presenceUpdate').onPresenceUpdate(bot, presence)
})
bot.on('error', (err) => {
bot.logger.fatal(err, 'DiscordJS Error')
bot.destroy()
process.exit(1)
})
process.on('SIGINT', () => {
bot.logger.warn('Process SIGINT')
bot.destroy()
process.exit(0)
})
process.on('SIGTERM', () => {
bot.logger.warn('Process SIGTERM')
bot.destroy()
process.exit(0)
})
bot.login(process.env.BOT_TOKEN)