mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-11 19:23:06 +00:00
Added Basic Fact of the Day Feature
This commit is contained in:
parent
2139f2efa0
commit
40942e2539
9 changed files with 544 additions and 27 deletions
|
@ -2,39 +2,79 @@ import { Events, Interaction } from 'discord.js';
|
|||
|
||||
import { ExtendedClient } from '../structures/ExtendedClient.js';
|
||||
import { Event } from '../types/EventTypes.js';
|
||||
import { approveFact, deleteFact } from '../db/db.js';
|
||||
|
||||
export default {
|
||||
name: Events.InteractionCreate,
|
||||
execute: async (interaction: Interaction) => {
|
||||
if (!interaction.isCommand()) return;
|
||||
if (interaction.isCommand()) {
|
||||
const client = interaction.client as ExtendedClient;
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
const client = interaction.client as ExtendedClient;
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
console.error(
|
||||
`No command matching ${interaction.commandName} was found.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!command) {
|
||||
console.error(
|
||||
`No command matching ${interaction.commandName} was found.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(`Error executing ${interaction.commandName}`);
|
||||
console.error(error);
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(`Error executing ${interaction.commandName}`);
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
} else {
|
||||
await interaction.reply({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (interaction.isButton()) {
|
||||
const { customId } = interaction;
|
||||
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
if (customId.startsWith('approve_fact_')) {
|
||||
if (!interaction.memberPermissions?.has('ModerateMembers')) {
|
||||
await interaction.reply({
|
||||
content: 'You do not have permission to approve facts.',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const factId = parseInt(customId.replace('approve_fact_', ''), 10);
|
||||
await approveFact(factId);
|
||||
|
||||
await interaction.update({
|
||||
content: `✅ Fact #${factId} has been approved by <@${interaction.user.id}>`,
|
||||
components: [],
|
||||
});
|
||||
} else {
|
||||
await interaction.reply({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
} else if (customId.startsWith('reject_fact_')) {
|
||||
if (!interaction.memberPermissions?.has('ModerateMembers')) {
|
||||
await interaction.reply({
|
||||
content: 'You do not have permission to reject facts.',
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const factId = parseInt(customId.replace('reject_fact_', ''), 10);
|
||||
await deleteFact(factId);
|
||||
|
||||
await interaction.update({
|
||||
content: `❌ Fact #${factId} has been rejected by <@${interaction.user.id}>`,
|
||||
components: [],
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('Unhandled interaction type:', interaction);
|
||||
return;
|
||||
}
|
||||
},
|
||||
} as Event<typeof Events.InteractionCreate>;
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Client, Events } from 'discord.js';
|
|||
import { setMembers } from '../db/db.js';
|
||||
import { loadConfig } from '../util/configLoader.js';
|
||||
import { Event } from '../types/EventTypes.js';
|
||||
import { scheduleFactOfTheDay } from '../util/factManager.js';
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
|
@ -21,6 +22,8 @@ export default {
|
|||
const members = await guild.members.fetch();
|
||||
const nonBotMembers = members.filter((m) => !m.user.bot);
|
||||
await setMembers(nonBotMembers);
|
||||
|
||||
await scheduleFactOfTheDay(client);
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize members in database:', error);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue