Files
blitzcrank/index.ts
Drew Malzahn e5e38e6100 WIP: Basic event loop, database code
The monster is starting to resemble a working program
2025-06-30 00:28:47 -04:00

119 lines
5.9 KiB
TypeScript

import { token } from "./config.json";
import { Interaction } from "discord.js";
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
import type { SlashCommandBuilder } from "discord.js";
import * as _pingCommand from "./commands/calendar/ping.ts";
import RemindCommand from "./commands/calendar/remind.ts";
interface Command {
data: SlashCommandBuilder;
execute: (i: Interaction) => void;
}
const pingCommand = _pingCommand as Command;
const BLITZCRANK_BANNER = `
****++++++++++*+++
**+*+******+********+******+*++*
**** *+*+**+*+*+*++++++++++++++*+++++*++++***
*=....... + **+*+*+++++++++++++++++++++++++++*++++++++++**
............= +****+*+*+++++++++#%%#######%*++++++++++++++**+**+**
*.....=@@@@+......+*+++++++++++##*#*++++++++++***%*+++++****++++++*+*++
.... @@. ..@% .. ..*++++++++%***++=%=+=======+++++**@+++++++++*++++*++**+
.....=@-...:@#.....+*+++++%***++====+====--==-====++**#+++++++++**+++**+*+*
.........@@@@-....-*++++#****++==---%:::::-------===+**#++++*++++++++++++***+
+.... +@. .........+++%***+++==--::==.::::::+##*-===+**%++++++++++++++++++*+++
*.......: .......--:.=@***++++=-::::.*....:=+:...-*-==+***+++++++++**+++++****+*
*.......=%:......*+++****+%==-=*+::..--....*-.....=+==++*#++++++++++++++**++++*+**
*+ ......+++++++++#+++*-::::::*....#....*+....:+:==++**%++++++++++++++*++++++++*
*+++++*+*++++*++++#++#-:.......+...-+...:.#**#=-===+++*#+++++++*++++*++++**+++*+*
*++*+++*+*+++++++++#*=#::.......+.::.#::::-=========+++**+++++++++++++++++++*+++*++
*+**+++++++++++++++*%*+=-........+-:::-#::---========+++#@=+++++++++++++++++++++++*+*
****+++*+**+*+++++++*%**+++:....+#=-----%-----========++@+===+++++++++++++++*+*+*++***
***+++++++++++++*++++@****-+#%%*:===----=*-===========%#*@%%%%%%%%%%#*+++++++++++++++**
**+*++*++++++++++*++++%#***++++++=========%======#%*==#***%###*******#%%%%@*++++++++++*+*
**+*+++++++*+++++*++++*@*****++++++========#==#+===----=+#%#****++++*****@####++++++*+*+*
+***++++*++++++++++++++@@#****++++++=======##===---------.%#*@%*+++++++**%#+**#++++*++***
*+*+*++++++++++++++++++==%@@#%@@+++++========%##:-----::%*##=#-::#*++++++*@=++#*#+++++++*++
*+*+*++++++*++++++++++=%%%@%@#####+++=======-%####+:=**#**--::--=##++++++==++####%+++++++**
***++++++++*+++++++++%%%@###%@#*#*%++=========@*#*##%#=-::--=++%+-#=+======+####**%++++*+*+
*+*+++++++++++++++++%%%#########%@%%*++======+%@%*##+*-*===#+-=====%=@#===#######**%+++++*+
*+*++++++++++++++++%%%####**********#%%%%%%#*+++*#%*#*+#*-:=========%::-*########*#++++++*+
*+*++++*++++++++++*##%##*****************+++++++++*#*##@*-===========%*##########*#++++*+*+
***+*++*+++*++++++%###*%*****++++++++++++++***####%*#*@*##:===========%###########+++++*+*+
++***++++*++++++++%#%*****##*+++++++++++**###%%+=====:@*##%-=========+#%########*++++*+++++
*+***++*+*+*++++++%#%%%#++**+++##+++++*####@===========:@###-======%%#%%######%++++++++****
***+++*++++++++++##%%####%#*==+=++*####@==+#========----:@#%-=#%%##%*=%*#####+++++++*+*+*
+***++*++++++++++##%%%########%%%%%%%*=====-%+-====----::-#%%%##%+-*+##+*#@++++++++++**+*
*+*++++++*++++++#%%%%%#######%%@@@==========:*:---:::::#*%%%#+-#*##%%+:#++++++*++++*+*+*
*++*+++*++++++++++%%%%######%%@@%@*=======---.*+::.-+*###*+**###%%+:=#*#++++*++++++***+
+*++*+**++*++++++++%%%####%@@@@@@%%=====---::.+++**##+++=*%%%%*:-*****#%#*%#*++*++*+*
++*+++++++*++++++++++@%%%@@@@@@@@%%-==--::.:#*%##+-++###%#*::#***#**%=:-#**%++++*+++
**+++*+++++++++++++++++++%@@@@@@@@%%:-:.=**#%#%*+*###%#=::+*####*%#*=:#***#*+++**+
*++***++*+++++++++++++++++++++*#%@%@-#*#%*+*=*%%#%#+::+*#######*%#**##***%+++*+**
*++**+++*++++++++++++++++++++++%#%#%%**-+####%#=::+*####%#####*%*####**%+++++++
+*+*+*+**+++*++*+++++++++++++*%#%#%*#%*%%#=:+*#####%***##**%#*@###*%*++++**
***+*++++++*++++++++*+++++++++%#%#%%%#=-+###########*-::-+##%#%%%%+****++
*+++++++++++++++++++++++++++++%%%%++############*%*=-#*###*@#%%%+**+*+
*+++*+*+*++++++++++++++++++++#%#####%##################*%#*#%***+++
++*+*+**+*+***++++*++++***++*%###%#*%%###%*##%%#####@%%%%***+**
*+*++++*+++++++++++++++++++*%#%%+=:..:=+=%#%%%%%%%%%%*+*+*+
+*++***++++++++++++++++++++%%#*#*#######%#%%%%%%#+**+*
**+*******+++**++**++*++#%%#########%%#%%%**++*+
++**+*++++*+*+++++++++@#######%%%#*++*****
**+*+*****++********##**+*++*+**+
+******************+
"FIRED UP AND READY TO SERVE!"
`;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
});
const remindCommand = RemindCommand({
client: client,
});
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) {
return;
}
try {
switch (interaction.commandName) {
case "ping":
return pingCommand.execute(interaction);
case "remind":
return remindCommand.execute(interaction);
default:
return console.error(`No matching command ${interaction.commandName}`);
}
} 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 remindCommand.initialize();
// Print banner
for (const ln of BLITZCRANK_BANNER.split("\n")) {
console.log(ln);
}
console.log(`Logged in as ${readyClient.user.tag}`);
});
client.login(token);