Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/commands/toggle_giveaway_monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ApplyOptions } from "@sapphire/decorators";
import { isTextChannel } from "@sapphire/discord.js-utilities";
import { Command } from "@sapphire/framework";
import consola from "consola";
import {
ApplicationCommandOptionType,
EmbedBuilder,
MessageFlags,
} from "discord.js";
import { Polyfrost } from "../const.ts";
import { isModTeam } from "../lib/permissions.ts";
import { GiveawayMonitorDB } from "../lib/db.ts";

@ApplyOptions<Command.Options>({
description: "Set the state of the giveaway monitor",
})
export class UserCommand extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand({
name: this.name,
description: this.description,
options: [
{
type: ApplicationCommandOptionType.Boolean,
name: "state",
description: "The state to set",
},
],
});
}

public override async chatInputRun(
interaction: Command.ChatInputCommandInteraction,
) {
if (interaction.guildId != Polyfrost.id) return;
if (!isModTeam(interaction.member)) {
return interaction.reply({
flags: MessageFlags.Ephemeral,
content: "❔",
});
}

const db = GiveawayMonitorDB.data;
const newState = interaction.options.getBoolean("state") ?? !db.enabled;
await GiveawayMonitorDB.update((data) => (data.enabled = newState));

const embed = new EmbedBuilder()
.setColor(newState ? "Green" : "Red")
.setTitle("Giveaway Monitor State update")
.setDescription(
`Giveaway monitor has been **${newState ? "Enabled" : "Disabled"}**`,
)
.setAuthor({
name: `${interaction.user.displayName} (${interaction.user.id})`,
iconURL: interaction.user.displayAvatarURL(),
});

const botLogsChannel = Polyfrost.channels.BotLogs;
const botLogs = interaction.client.channels.cache.get(botLogsChannel);
if (!isTextChannel(botLogs)) {
consola.error("Bot logs channel not found", botLogsChannel);
return;
}

const logEmbed = new EmbedBuilder(embed.data).addFields(
{
name: "New State",
value: newState ? "Enabled" : "Disabled",
inline: true,
},
{
name: "Old State",
value: db.enabled ? "Enabled" : "Disabled",
inline: true,
},
);

await botLogs.send({ embeds: [logEmbed], allowedMentions: { parse: [] } });
return;
}
}
6 changes: 6 additions & 0 deletions src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export const BoostersDB = await JSONFilePreset<BoostersDB>(
join(baseDir, "boosters.json"),
{},
);

type GiveawayMonitorDB = { enabled: boolean };
export const GiveawayMonitorDB = await JSONFilePreset<GiveawayMonitorDB>(
join(baseDir, "giveaway_monitor.json"),
{ enabled: true },
);
4 changes: 4 additions & 0 deletions src/listeners/presence/giveawayMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "discord.js";
import { Polyfrost } from "../../const.ts";
import { isTicket } from "../../lib/ticket.ts";
import { GiveawayMonitorDB } from "../../lib/db.ts";

const streaks: Record<string, string[]> = {};
const ignoredChannels = [
Expand All @@ -34,6 +35,9 @@ export class MessageListener extends Listener<typeof Events.MessageCreate> {
const member = guild.members.cache.get(author.id);
if (!member) return;

const db = GiveawayMonitorDB.data;
if (!db.enabled) return;

if (guild.id != Polyfrost.id) return;
if (!isGuildBasedChannel(channel)) return;
if (isTicket(channel)) return;
Expand Down