153 lines
6.8 KiB
TypeScript
153 lines
6.8 KiB
TypeScript
import type { Interaction } from "discord.js";
|
|
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
|
|
import type {
|
|
SlashCommandBuilder,
|
|
SlashCommandOptionsOnlyBuilder,
|
|
} from "discord.js";
|
|
|
|
import { sql } from "./database";
|
|
|
|
const BLITZCRANK_BANNER = `
|
|
****++++++++++*+++
|
|
**+*+******+********+******+*++*
|
|
**** *+*+**+*+*+*++++++++++++++*+++++*++++***
|
|
*=....... + **+*+*+++++++++++++++++++++++++++*++++++++++**
|
|
............= +****+*+*+++++++++#%%#######%*++++++++++++++**+**+**
|
|
*.....=@@@@+......+*+++++++++++##*#*++++++++++***%*+++++****++++++*+*++
|
|
.... @@. ..@% .. ..*++++++++%***++=%=+=======+++++**@+++++++++*++++*++**+
|
|
.....=@-...:@#.....+*+++++%***++====+====--==-====++**#+++++++++**+++**+*+*
|
|
.........@@@@-....-*++++#****++==---%:::::-------===+**#++++*++++++++++++***+
|
|
+.... +@. .........+++%***+++==--::==.::::::+##*-===+**%++++++++++++++++++*+++
|
|
*.......: .......--:.=@***++++=-::::.*....:=+:...-*-==+***+++++++++**+++++****+*
|
|
*.......=%:......*+++****+%==-=*+::..--....*-.....=+==++*#++++++++++++++**++++*+**
|
|
*+ ......+++++++++#+++*-::::::*....#....*+....:+:==++**%++++++++++++++*++++++++*
|
|
*+++++*+*++++*++++#++#-:.......+...-+...:.#**#=-===+++*#+++++++*++++*++++**+++*+*
|
|
*++*+++*+*+++++++++#*=#::.......+.::.#::::-=========+++**+++++++++++++++++++*+++*++
|
|
*+**+++++++++++++++*%*+=-........+-:::-#::---========+++#@=+++++++++++++++++++++++*+*
|
|
****+++*+**+*+++++++*%**+++:....+#=-----%-----========++@+===+++++++++++++++*+*+*++***
|
|
***+++++++++++++*++++@****-+#%%*:===----=*-===========%#*@%%%%%%%%%%#*+++++++++++++++**
|
|
**+*++*++++++++++*++++%#***++++++=========%======#%*==#***%###*******#%%%%@*++++++++++*+*
|
|
**+*+++++++*+++++*++++*@*****++++++========#==#+===----=+#%#****++++*****@####++++++*+*+*
|
|
+***++++*++++++++++++++@@#****++++++=======##===---------.%#*@%*+++++++**%#+**#++++*++***
|
|
*+*+*++++++++++++++++++==%@@#%@@+++++========%##:-----::%*##=#-::#*++++++*@=++#*#+++++++*++
|
|
*+*+*++++++*++++++++++=%%%@%@#####+++=======-%####+:=**#**--::--=##++++++==++####%+++++++**
|
|
***++++++++*+++++++++%%%@###%@#*#*%++=========@*#*##%#=-::--=++%+-#=+======+####**%++++*+*+
|
|
*+*+++++++++++++++++%%%#########%@%%*++======+%@%*##+*-*===#+-=====%=@#===#######**%+++++*+
|
|
*+*++++++++++++++++%%%####**********#%%%%%%#*+++*#%*#*+#*-:=========%::-*########*#++++++*+
|
|
*+*++++*++++++++++*##%##*****************+++++++++*#*##@*-===========%*##########*#++++*+*+
|
|
***+*++*+++*++++++%###*%*****++++++++++++++***####%*#*@*##:===========%###########+++++*+*+
|
|
++***++++*++++++++%#%*****##*+++++++++++**###%%+=====:@*##%-=========+#%########*++++*+++++
|
|
*+***++*+*+*++++++%#%%%#++**+++##+++++*####@===========:@###-======%%#%%######%++++++++****
|
|
***+++*++++++++++##%%####%#*==+=++*####@==+#========----:@#%-=#%%##%*=%*#####+++++++*+*+*
|
|
+***++*++++++++++##%%%########%%%%%%%*=====-%+-====----::-#%%%##%+-*+##+*#@++++++++++**+*
|
|
*+*++++++*++++++#%%%%%#######%%@@@==========:*:---:::::#*%%%#+-#*##%%+:#++++++*++++*+*+*
|
|
*++*+++*++++++++++%%%%######%%@@%@*=======---.*+::.-+*###*+**###%%+:=#*#++++*++++++***+
|
|
+*++*+**++*++++++++%%%####%@@@@@@%%=====---::.+++**##+++=*%%%%*:-*****#%#*%#*++*++*+*
|
|
++*+++++++*++++++++++@%%%@@@@@@@@%%-==--::.:#*%##+-++###%#*::#***#**%=:-#**%++++*+++
|
|
**+++*+++++++++++++++++++%@@@@@@@@%%:-:.=**#%#%*+*###%#=::+*####*%#*=:#***#*+++**+
|
|
*++***++*+++++++++++++++++++++*#%@%@-#*#%*+*=*%%#%#+::+*#######*%#**##***%+++*+**
|
|
*++**+++*++++++++++++++++++++++%#%#%%**-+####%#=::+*####%#####*%*####**%+++++++
|
|
+*+*+*+**+++*++*+++++++++++++*%#%#%*#%*%%#=:+*#####%***##**%#*@###*%*++++**
|
|
***+*++++++*++++++++*+++++++++%#%#%%%#=-+###########*-::-+##%#%%%%+****++
|
|
*+++++++++++++++++++++++++++++%%%%++############*%*=-#*###*@#%%%+**+*+
|
|
*+++*+*+*++++++++++++++++++++#%#####%##################*%#*#%***+++
|
|
++*+*+**+*+***++++*++++***++*%###%#*%%###%*##%%#####@%%%%***+**
|
|
*+*++++*+++++++++++++++++++*%#%%+=:..:=+=%#%%%%%%%%%%*+*+*+
|
|
+*++***++++++++++++++++++++%%#*#*#######%#%%%%%%#+**+*
|
|
**+*******+++**++**++*++#%%#########%%#%%%**++*+
|
|
++**+*++++*+*+++++++++@#######%%%#*++*****
|
|
**+*+*****++********##**+*++*+**+
|
|
+******************+
|
|
|
|
"FIRED UP AND READY TO SERVE!"
|
|
`;
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.GuildMembers,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
});
|
|
|
|
import { Routes } from "discord.js";
|
|
import { guildId, appId, token, remindersChannelId } from "./config.json";
|
|
import { REST } from "discord.js";
|
|
|
|
const rest = new REST();
|
|
rest.setToken(token);
|
|
|
|
interface Command {
|
|
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder;
|
|
execute: (interaction: any) => Promise<void>;
|
|
initialize: (any) => Promise<void>;
|
|
}
|
|
|
|
import { Collection } from "discord.js";
|
|
const commands = new Collection<string, Command>();
|
|
|
|
import PingCommand from "./commands/calendar/ping";
|
|
import RemindCommand from "./commands/calendar/remind";
|
|
|
|
commands.set("ping", PingCommand({ client: client, db: sql }));
|
|
commands.set(
|
|
"remind",
|
|
RemindCommand({ client: client, db: sql, publicChannel: remindersChannelId }),
|
|
);
|
|
|
|
async function syncCommands() {
|
|
try {
|
|
console.log(`Started refreshing slash commands`);
|
|
const _data = await rest.put(
|
|
Routes.applicationGuildCommands(appId, guildId),
|
|
{
|
|
body: commands.mapValues((cmd) => cmd.data.toJSON()),
|
|
},
|
|
);
|
|
console.log(`Successfully reloaded slash commands`);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
|
if (!interaction.isChatInputCommand()) {
|
|
return;
|
|
}
|
|
try {
|
|
const command = commands.get(interaction.commandName);
|
|
if (command == null) {
|
|
await interaction.followUp(`No such command ${interaction.commandName}`);
|
|
return;
|
|
}
|
|
command.execute(interaction);
|
|
} catch (error) {
|
|
console.error(error);
|
|
if (interaction.replied || interaction.deferred) {
|
|
await interaction.followUp({
|
|
content: "There was an error while executing this command",
|
|
flags: MessageFlags.Ephemeral,
|
|
});
|
|
}
|
|
}
|
|
// TODO
|
|
});
|
|
|
|
client.once(Events.ClientReady, async (readyClient) => {
|
|
await syncCommands();
|
|
for (const [_name, cmd] of commands) {
|
|
await cmd?.initialize({
|
|
client: client,
|
|
db: sql,
|
|
});
|
|
}
|
|
// Print banner
|
|
for (const ln of BLITZCRANK_BANNER.split("\n")) {
|
|
console.log(ln);
|
|
}
|
|
console.log(`Logged in as ${readyClient.user.tag}`);
|
|
});
|
|
|
|
client.login(token);
|