mirror of
https://github.com/sern-handler/sern-community
synced 2026-06-06 01:16:57 +00:00
got rid of giveaway reroll
This commit is contained in:
@@ -194,17 +194,11 @@ export default commandModule({
|
||||
});
|
||||
|
||||
function retryRows() {
|
||||
const attemptReroll = new ButtonBuilder({
|
||||
customId: "reroll",
|
||||
label: "Attempt Reroll",
|
||||
style: ButtonStyle.Primary,
|
||||
});
|
||||
|
||||
const discardGiveaway = new ButtonBuilder({
|
||||
customId: "discard",
|
||||
label: "Discard Giveaway",
|
||||
style: ButtonStyle.Primary,
|
||||
});
|
||||
|
||||
return new ActionRowBuilder<ButtonBuilder>().addComponents(attemptReroll, discardGiveaway);
|
||||
return new ActionRowBuilder<ButtonBuilder>().addComponents(discardGiveaway);
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import { ownerIDs } from "#constants";
|
||||
import { commandModule, CommandType } from "@sern/handler";
|
||||
import { db } from "../../utils/db.js";
|
||||
|
||||
export default commandModule({
|
||||
type: CommandType.Button,
|
||||
name: "reroll",
|
||||
async execute(ctx) {
|
||||
if (!ownerIDs.includes(ctx.user.id))
|
||||
return ctx.reply({
|
||||
ephemeral: true,
|
||||
content: `You cannot reroll the giveaway because you are not one of the owners`,
|
||||
});
|
||||
|
||||
const stmt = db.prepare(`SELECT * FROM entries WHERE message_id = ?`).all(ctx.message.id);
|
||||
|
||||
const eligible = stmt.filter(
|
||||
(entry: { user_id: string }) =>
|
||||
entry.user_id !== ctx.message.author.id && entry.user_id !== ctx.user.id
|
||||
);
|
||||
|
||||
if (eligible.length === 0) {
|
||||
await ctx.reply({
|
||||
ephemeral: true,
|
||||
content: `You cannot reroll because no eligible users entered the giveaway! Please discard the giveaway and try again!`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const winnerIndex = Math.floor(Math.random() * eligible.length);
|
||||
const winner = eligible[winnerIndex].user_id;
|
||||
|
||||
await ctx.reply({
|
||||
content: `Congratulations <@${winner}> on winning the giveaway! ${stmt.length} users entered`,
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user