Implement /unnag
This commit is contained in:
190
index.ts
190
index.ts
@@ -1,11 +1,11 @@
|
||||
import type { Interaction } from "discord.js";
|
||||
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
|
||||
import type {Interaction} from 'discord.js';
|
||||
import {Client, Events, GatewayIntentBits, MessageFlags} from 'discord.js';
|
||||
import type {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
} from "discord.js";
|
||||
SlashCommandBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
|
||||
import { sql, GuildSetting, initDb } from "./database";
|
||||
import {sql, GuildSetting, initDb} from './database';
|
||||
|
||||
const BLITZCRANK_BANNER = `
|
||||
****++++++++++*+++
|
||||
@@ -63,105 +63,133 @@ const BLITZCRANK_BANNER = `
|
||||
`;
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.MessageContent,
|
||||
],
|
||||
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";
|
||||
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>;
|
||||
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder;
|
||||
execute: (interaction: any) => Promise<void>;
|
||||
initialize: (any) => Promise<void>;
|
||||
}
|
||||
|
||||
import { Collection } from "discord.js";
|
||||
import {Collection} from 'discord.js';
|
||||
const commands = new Collection<string, Command>();
|
||||
|
||||
import PingCommand from "./commands/calendar/ping";
|
||||
import RemindCommand from "./commands/calendar/remind";
|
||||
import QuoteCommand from "./commands/quotes/quote";
|
||||
import NagCommand from "./commands/calendar/nag/nag";
|
||||
import UnnagCommand from "./commands/calendar/nag/unnag";
|
||||
import CheckinCommand from "./commands/calendar/nag/checkin";
|
||||
import PingCommand from './commands/calendar/ping';
|
||||
import RemindCommand from './commands/calendar/remind';
|
||||
import QuoteCommand from './commands/quotes/quote';
|
||||
import NagCommand from './commands/calendar/nag/nag';
|
||||
import UnnagCommand from './commands/calendar/nag/unnag';
|
||||
import CheckinCommand from './commands/calendar/nag/checkin';
|
||||
|
||||
import {Manager} from './commands/calendar/nag/service';
|
||||
const nagManager = new Manager({
|
||||
client: client,
|
||||
db: sql,
|
||||
});
|
||||
nagManager.start();
|
||||
|
||||
console.debug(`${remindersChannelId}`);
|
||||
|
||||
commands.set("ping", PingCommand({ client: client, db: sql }));
|
||||
commands.set('ping', PingCommand({client: client, db: sql}));
|
||||
commands.set(
|
||||
"remind",
|
||||
RemindCommand({
|
||||
client: client,
|
||||
db: sql,
|
||||
publicChannel: remindersChannelId,
|
||||
responseMode: "public",
|
||||
}),
|
||||
'remind',
|
||||
RemindCommand({
|
||||
client: client,
|
||||
db: sql,
|
||||
publicChannel: remindersChannelId,
|
||||
responseMode: 'public',
|
||||
}),
|
||||
);
|
||||
commands.set('quote', QuoteCommand({}));
|
||||
commands.set(
|
||||
'nag',
|
||||
NagCommand({
|
||||
client: client,
|
||||
db: sql,
|
||||
}),
|
||||
);
|
||||
commands.set(
|
||||
'unnag',
|
||||
UnnagCommand({
|
||||
client: client,
|
||||
db: sql,
|
||||
}),
|
||||
);
|
||||
commands.set(
|
||||
'checkin',
|
||||
CheckinCommand({
|
||||
client: client,
|
||||
db: sql,
|
||||
}),
|
||||
);
|
||||
commands.set("quote", QuoteCommand({}));
|
||||
|
||||
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);
|
||||
}
|
||||
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
|
||||
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();
|
||||
initDb(); // TODO
|
||||
GuildSetting.sync(); // TODO
|
||||
client.once(Events.ClientReady, async readyClient => {
|
||||
await syncCommands();
|
||||
initDb(); // TODO
|
||||
GuildSetting.sync(); // TODO
|
||||
|
||||
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}`);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user