-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
100 lines (80 loc) · 3.38 KB
/
app.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
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
import 'dotenv/config'
import { REST, Routes, Client, Collection, GatewayIntentBits, Events } from "discord.js";
import AssignCommand from "./commands/assign.js";
import CuteifyCommand from "./commands/cuteify.js";
import UncuteifyCommand from "./commands/uncuteify.js";
import EditCommand from "./commands/edit.js";
import PingCommand from "./commands/ping.js";
import SpankCommand from "./commands/spank.js";
import WelcomeUser from "./commands/welcome.js";
import GoodbyeUser from "./commands/goodbye.js";
import monitorSecurityCattoPresence from './commands/securityCattoMonitoring.js';
import { blacklistMessageCreate, blacklistMessageUpdate } from "./commands/blacklist.js";
console.log("Starting SaphBot");
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
]});
let commands = new Collection();
for (let cmd of [AssignCommand, EditCommand, CuteifyCommand, UncuteifyCommand, PingCommand, SpankCommand]) commands.set(cmd.data.name, cmd);
client.once(Events.ClientReady, () => console.log(`Client logged in as ${client.user?.tag}`));
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
let errorBody = { content: `There was an error while executing this command!`, ephemeral: true };
if (interaction.replied || interaction.deferred) {
await interaction.followUp(errorBody);
} else {
await interaction.reply(errorBody);
}
}
});
client.on(Events.MessageCreate, async(...args) => {
await blacklistMessageCreate(client, ...args);
});
client.on(Events.MessageUpdate, async(...args) => {
await blacklistMessageUpdate(client, ...args);
});
client.on(Events.GuildMemberUpdate, async (oldMember, newMember) => {
if (oldMember.pending && !newMember.pending) {
await WelcomeUser(client, newMember);
}
});
client.on(Events.GuildMemberRemove, (member) => {
GoodbyeUser(client, member);
});
client.on(Events.PresenceUpdate, (oldPresence, newPresence) => {
monitorSecurityCattoPresence(client, newPresence);
});
const guildCommands = commands.map((cmd) => cmd.data.toJSON());
const globalCommands = [];
async function start() {
try {
//@ts-ignore
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
// @ts-ignore
const guildCommandResults = await rest.put(Routes.applicationGuildCommands(process.env.APPLICATION_ID, process.env.GUILD_ID), { body: guildCommands });
// @ts-ignore
if (guildCommandResults.length > 0) console.log(`Successfully reloaded ${guildCommandResults.length} guild application (/) commands.`);
// @ts-ignore
const globalCommandResults = await rest.put(Routes.applicationCommands(process.env.APPLICATION_ID), { body: globalCommands });
// @ts-ignore
if (globalCommandResults.length > 0) console.log(`Successfully reloaded ${globalCommandResults.length} global application (/) commands.`);
client.login(process.env.DISCORD_TOKEN);
} catch (error) {
console.error(error);
}
}
start();