166 lines
6.9 KiB
TypeScript
166 lines
6.9 KiB
TypeScript
const BLITZCRANK_BANNER = `
|
|
****++++++++++*+++
|
|
**+*+******+********+******+*++*
|
|
**** *+*+**+*+*+*++++++++++++++*+++++*++++***
|
|
*=....... + **+*+*+++++++++++++++++++++++++++*++++++++++**
|
|
............= +****+*+*+++++++++#%%#######%*++++++++++++++**+**+**
|
|
*.....=@@@@+......+*+++++++++++##*#*++++++++++***%*+++++****++++++*+*++
|
|
.... @@. ..@% .. ..*++++++++%***++=%=+=======+++++**@+++++++++*++++*++**+
|
|
.....=@-...:@#.....+*+++++%***++====+====--==-====++**#+++++++++**+++**+*+*
|
|
.........@@@@-....-*++++#****++==---%:::::-------===+**#++++*++++++++++++***+
|
|
+.... +@. .........+++%***+++==--::==.::::::+##*-===+**%++++++++++++++++++*+++
|
|
*.......: .......--:.=@***++++=-::::.*....:=+:...-*-==+***+++++++++**+++++****+*
|
|
*.......=%:......*+++****+%==-=*+::..--....*-.....=+==++*#++++++++++++++**++++*+**
|
|
*+ ......+++++++++#+++*-::::::*....#....*+....:+:==++**%++++++++++++++*++++++++*
|
|
*+++++*+*++++*++++#++#-:.......+...-+...:.#**#=-===+++*#+++++++*++++*++++**+++*+*
|
|
*++*+++*+*+++++++++#*=#::.......+.::.#::::-=========+++**+++++++++++++++++++*+++*++
|
|
*+**+++++++++++++++*%*+=-........+-:::-#::---========+++#@=+++++++++++++++++++++++*+*
|
|
****+++*+**+*+++++++*%**+++:....+#=-----%-----========++@+===+++++++++++++++*+*+*++***
|
|
***+++++++++++++*++++@****-+#%%*:===----=*-===========%#*@%%%%%%%%%%#*+++++++++++++++**
|
|
**+*++*++++++++++*++++%#***++++++=========%======#%*==#***%###*******#%%%%@*++++++++++*+*
|
|
**+*+++++++*+++++*++++*@*****++++++========#==#+===----=+#%#****++++*****@####++++++*+*+*
|
|
+***++++*++++++++++++++@@#****++++++=======##===---------.%#*@%*+++++++**%#+**#++++*++***
|
|
*+*+*++++++++++++++++++==%@@#%@@+++++========%##:-----::%*##=#-::#*++++++*@=++#*#+++++++*++
|
|
*+*+*++++++*++++++++++=%%%@%@#####+++=======-%####+:=**#**--::--=##++++++==++####%+++++++**
|
|
***++++++++*+++++++++%%%@###%@#*#*%++=========@*#*##%#=-::--=++%+-#=+======+####**%++++*+*+
|
|
*+*+++++++++++++++++%%%#########%@%%*++======+%@%*##+*-*===#+-=====%=@#===#######**%+++++*+
|
|
*+*++++++++++++++++%%%####**********#%%%%%%#*+++*#%*#*+#*-:=========%::-*########*#++++++*+
|
|
*+*++++*++++++++++*##%##*****************+++++++++*#*##@*-===========%*##########*#++++*+*+
|
|
***+*++*+++*++++++%###*%*****++++++++++++++***####%*#*@*##:===========%###########+++++*+*+
|
|
++***++++*++++++++%#%*****##*+++++++++++**###%%+=====:@*##%-=========+#%########*++++*+++++
|
|
*+***++*+*+*++++++%#%%%#++**+++##+++++*####@===========:@###-======%%#%%######%++++++++****
|
|
***+++*++++++++++##%%####%#*==+=++*####@==+#========----:@#%-=#%%##%*=%*#####+++++++*+*+*
|
|
+***++*++++++++++##%%%########%%%%%%%*=====-%+-====----::-#%%%##%+-*+##+*#@++++++++++**+*
|
|
*+*++++++*++++++#%%%%%#######%%@@@==========:*:---:::::#*%%%#+-#*##%%+:#++++++*++++*+*+*
|
|
*++*+++*++++++++++%%%%######%%@@%@*=======---.*+::.-+*###*+**###%%+:=#*#++++*++++++***+
|
|
+*++*+**++*++++++++%%%####%@@@@@@%%=====---::.+++**##+++=*%%%%*:-*****#%#*%#*++*++*+*
|
|
++*+++++++*++++++++++@%%%@@@@@@@@%%-==--::.:#*%##+-++###%#*::#***#**%=:-#**%++++*+++
|
|
**+++*+++++++++++++++++++%@@@@@@@@%%:-:.=**#%#%*+*###%#=::+*####*%#*=:#***#*+++**+
|
|
*++***++*+++++++++++++++++++++*#%@%@-#*#%*+*=*%%#%#+::+*#######*%#**##***%+++*+**
|
|
*++**+++*++++++++++++++++++++++%#%#%%**-+####%#=::+*####%#####*%*####**%+++++++
|
|
+*+*+*+**+++*++*+++++++++++++*%#%#%*#%*%%#=:+*#####%***##**%#*@###*%*++++**
|
|
***+*++++++*++++++++*+++++++++%#%#%%%#=-+###########*-::-+##%#%%%%+****++
|
|
*+++++++++++++++++++++++++++++%%%%++############*%*=-#*###*@#%%%+**+*+
|
|
*+++*+*+*++++++++++++++++++++#%#####%##################*%#*#%***+++
|
|
++*+*+**+*+***++++*++++***++*%###%#*%%###%*##%%#####@%%%%***+**
|
|
*+*++++*+++++++++++++++++++*%#%%+=:..:=+=%#%%%%%%%%%%*+*+*+
|
|
+*++***++++++++++++++++++++%%#*#*#######%#%%%%%%#+**+*
|
|
**+*******+++**++**++*++#%%#########%%#%%%**++*+
|
|
++**+*++++*+*+++++++++@#######%%%#*++*****
|
|
**+*+*****++********##**+*++*+**+
|
|
+******************+
|
|
|
|
"FIRED UP AND READY TO SERVE!"
|
|
`;
|
|
|
|
import type {Interaction} from 'discord.js';
|
|
import {
|
|
Client,
|
|
Collection,
|
|
Events,
|
|
GatewayIntentBits,
|
|
MessageFlags,
|
|
REST,
|
|
Routes,
|
|
} from 'discord.js';
|
|
import {GuildSetting, initializeDatabase, initializeModels, sequelize, syncModels} from './database';
|
|
import {readEnvSettings} from './environ';
|
|
|
|
import {Command} from './plugin';
|
|
import { NagPlugin } from './plugins/nag'
|
|
import { PingPlugin } from './plugins/ping'
|
|
import { QuotePlugin } from './plugins/quote'
|
|
import { RemindPlugin } from './plugins/remind'
|
|
|
|
|
|
|
|
const envSettings = readEnvSettings();
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.GuildMembers,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
});
|
|
const rest = new REST();
|
|
rest.setToken(envSettings.BLITZCRANK_API_TOKEN);
|
|
|
|
const commands = new Collection<string, Command>();
|
|
|
|
const settings = {
|
|
client: client,
|
|
database: sequelize,
|
|
}
|
|
|
|
const plugins = [
|
|
new NagPlugin(settings),
|
|
new QuotePlugin(settings),
|
|
new RemindPlugin(settings),
|
|
new PingPlugin(settings),
|
|
]
|
|
|
|
async function addApplicationGuildCommands() {
|
|
for (const plugin of plugins) {
|
|
for (const command of plugin.commands) {
|
|
commands.set(command.data.name, command);
|
|
}
|
|
}
|
|
for (const [_guildId, guild] of client.guilds.cache) {
|
|
try {
|
|
console.log(`Started refreshing slash commands`);
|
|
const _data = await rest.put(
|
|
Routes.applicationGuildCommands(
|
|
envSettings.BLITZCRANK_APP_ID,
|
|
guild.id,
|
|
),
|
|
{
|
|
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 initializeDatabase();
|
|
await initializeModels();
|
|
await syncModels();
|
|
await addApplicationGuildCommands();
|
|
|
|
for (const ln of BLITZCRANK_BANNER.split('\n')) {
|
|
console.log(ln);
|
|
}
|
|
|
|
console.log(`Logged in as ${readyClient.user.tag}`);
|
|
});
|
|
|
|
client.login(envSettings.BLITZCRANK_API_TOKEN);
|