-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
87 lines (79 loc) · 3.04 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
import * as Discord from 'discord.js';
import { handleBroadcastCommand } from './commands/broadcast';
import { handleElse } from './commands/else';
import { printHelp } from './commands/help';
import { handleMoveVoiceUsersCommand } from './commands/moveVoiceUsers';
import { handleNicknameChange } from './commands/nickname';
import { handleNotLinked } from './commands/notLinked';
import { handleRefreshAllUsers } from './commands/refreshAllUsers';
import { handleRefreshProfile } from './commands/refreshProfile';
import { handleRefreshUser } from './commands/refreshUser';
import { handleVerify } from './commands/verify';
import { refreshUser } from './utils/refreshUser';
const client = new Discord.Client({
intents:
Discord.GatewayIntentBits.GuildMembers |
Discord.GatewayIntentBits.GuildMessages |
Discord.GatewayIntentBits.DirectMessages |
Discord.GatewayIntentBits.Guilds,
partials: [Discord.Partials.Channel]
});
client.on('ready', () => {
console.log('Bot is running');
const guild = client.guilds.cache.get(
process.env['IVAOTHAI_GUILD'] as string
)!;
const verifiedRole = guild.roles.cache.get(
process.env['VERIFIED_ROLE'] as string
)!;
const announcementChannel = guild.channels.cache.get(
process.env['ANNOUNCEMENT_CHANNEL'] as string
)! as Discord.TextChannel;
client.on('messageCreate', (message) => {
void (async () => {
if (message.author.id !== client.user!.id) {
if (message.content === '!verify') {
await handleVerify(message);
} else if (message.content.startsWith('!broadcast')) {
await handleBroadcastCommand(message, announcementChannel);
} else if (message.content === '!help') {
await printHelp(message);
} else if (message.content.startsWith('!nickname')) {
await handleNicknameChange(message);
} else if (message.content.startsWith('!refreshUser')) {
await handleRefreshUser(message);
} else if (message.content === '!notifyNotLinked') {
await handleNotLinked(message, guild, verifiedRole);
} else if (message.content === '!refreshAllUsers') {
await handleRefreshAllUsers(message);
} else if (message.content === '!refreshProfile') {
await handleRefreshProfile(client, guild);
} else if (message.content.startsWith('!moveVoiceUsers')) {
await handleMoveVoiceUsersCommand(message, guild);
} else {
await handleElse(message);
}
}
})();
});
client.on('guildMemberUpdate', (oldMember, newMember) => {
void (async () => {
if (oldMember.nickname !== newMember.nickname) {
await refreshUser(newMember.user.id);
}
})();
});
client.on('guildMemberAdd', (newMember) => {
void (async () => {
await refreshUser(newMember.user.id);
})();
});
});
void client.login(process.env['BOT_TOKEN']);
process.on('unhandledRejection', (error) => {
console.error('Unhandled promise rejection:', error);
});
process.on('SIGINT', () => {
console.log('Terminating');
process.exit();
});