Skip to content

Commit

Permalink
feat: guild banned precondition
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklvh committed Mar 24, 2024
1 parent d6042c1 commit 9cefb68
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/preconditions/global/guildBanned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApplyOptions } from "@sapphire/decorators";
import { AllFlowsPrecondition } from "@sapphire/framework";
import type {
ChatInputCommandInteraction,
ContextMenuCommandInteraction,
Message,
} from "discord.js";

@ApplyOptions<AllFlowsPrecondition.Options>({
position: 20,
})
export class GuildBannedPrecondition extends AllFlowsPrecondition {
public override chatInputRun(interaction: ChatInputCommandInteraction) {
return this.checkBanned(interaction.guildId);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.checkBanned(interaction.guildId);
}

public override messageRun(message: Message) {
return this.checkBanned(message.guildId);
}

private async checkBanned(guildId: string | null) {
if (!guildId) return this.ok();

const banned = await this.container.prisma.guild.findUnique({
where: { id: guildId, banned: true },
});

if (!banned) return this.ok();

return this.error({
identifier: "guildBanned",
message: "Your server has been banned from using Joewy.",
});
}
}

0 comments on commit 9cefb68

Please sign in to comment.