mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-06-22 06:04:20 +00:00
feat: add giveaway system
Signed-off-by: Ahmad <103906421+ahmadk953@users.noreply.github.com>
This commit is contained in:
parent
e898a9238d
commit
d9d5f087e7
23 changed files with 2811 additions and 168 deletions
|
@ -1,11 +1,17 @@
|
|||
import Canvas from '@napi-rs/canvas';
|
||||
import path from 'path';
|
||||
|
||||
import { AttachmentBuilder, Client, GuildMember, Guild } from 'discord.js';
|
||||
import {
|
||||
AttachmentBuilder,
|
||||
Client,
|
||||
GuildMember,
|
||||
Guild,
|
||||
Interaction,
|
||||
} from 'discord.js';
|
||||
import { and, eq } from 'drizzle-orm';
|
||||
|
||||
import { moderationTable } from '../db/schema.js';
|
||||
import { db, handleDbError, updateMember } from '../db/db.js';
|
||||
import { moderationTable } from '@/db/schema.js';
|
||||
import { db, handleDbError, updateMember } from '@/db/db.js';
|
||||
import logAction from './logging/logAction.js';
|
||||
|
||||
const __dirname = path.resolve();
|
||||
|
@ -262,3 +268,44 @@ export function roundRect({
|
|||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an interaction is valid
|
||||
* @param interaction - The interaction to check
|
||||
* @returns - Whether the interaction is valid
|
||||
*/
|
||||
export async function validateInteraction(
|
||||
interaction: Interaction,
|
||||
): Promise<boolean> {
|
||||
if (!interaction.inGuild()) return false;
|
||||
if (!interaction.channel) return false;
|
||||
|
||||
if (interaction.isMessageComponent()) {
|
||||
try {
|
||||
await interaction.channel.messages.fetch(interaction.message.id);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely responds to an interaction
|
||||
* @param interaction - The interaction to respond to
|
||||
* @param content - The content to send
|
||||
*/
|
||||
export async function safelyRespond(interaction: Interaction, content: string) {
|
||||
try {
|
||||
if (!interaction.isRepliable()) return;
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content, flags: ['Ephemeral'] });
|
||||
} else {
|
||||
await interaction.reply({ content, flags: ['Ephemeral'] });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to respond to interaction:', error);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue