Files
blitzcrank/index.ts
2025-07-01 09:55:23 -04:00

151 lines
6.8 KiB
TypeScript

import { 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,
],
});
const pingCommand = PingCommand({
client: client,
db: sql,
});
const remindCommand = RemindCommand({
client: client,
db: sql,
});
import { Routes } from "discord.js";
import { guildId, appId, token } 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>
};
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 }));
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();
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);