-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a setting to control Melvin's laugh on a per-server basis, …
…disabled by default
- Loading branch information
1 parent
41f8141
commit 9f4cf7c
Showing
4 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240518094149_update_guild_add_laugh_flag/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "guild" ADD COLUMN "laugh" BOOLEAN NOT NULL DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { | ||
ChatInputCommand, | ||
Command, | ||
CommandOptionsRunTypeEnum, | ||
LogLevel, | ||
RegisterBehavior, | ||
} from "@sapphire/framework"; | ||
import { PermissionFlagsBits } from "discord.js"; | ||
import { writeLog } from "../../util"; | ||
|
||
export class LaughCommand extends Command { | ||
public constructor(context: Command.LoaderContext, options: Command.Options) { | ||
super(context, { | ||
...options, | ||
name: "laugh", | ||
description: "Enable or disable Melvin's evil laugh when rolling a 1", | ||
cooldownDelay: 5000, | ||
cooldownLimit: 1, | ||
requiredUserPermissions: [PermissionFlagsBits.ManageGuild], | ||
runIn: CommandOptionsRunTypeEnum.GuildText, | ||
}); | ||
} | ||
|
||
public override registerApplicationCommands( | ||
registry: ChatInputCommand.Registry | ||
) { | ||
registry.registerChatInputCommand( | ||
(builder) => | ||
builder | ||
.setName(this.name) | ||
.setDescription(this.description) | ||
.addBooleanOption((option) => | ||
option | ||
.setName("enabled") | ||
.setDescription("Enable or disable Melvin's evil laugh") | ||
.setRequired(true) | ||
), | ||
{ | ||
behaviorWhenNotIdentical: RegisterBehavior.Overwrite, | ||
} | ||
); | ||
} | ||
|
||
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) { | ||
const { guild } = interaction; | ||
if (!guild) return null; | ||
|
||
const { prisma } = this.container; | ||
|
||
const enabled = interaction.options.getBoolean("enabled", true); | ||
|
||
const savedGuild = await prisma.guild.findUnique({ | ||
where: { id: guild.id }, | ||
}); | ||
|
||
try { | ||
if (!savedGuild) { | ||
await prisma.guild.create({ | ||
data: { | ||
id: guild.id, | ||
laugh: enabled, | ||
}, | ||
}); | ||
|
||
return interaction.reply({ | ||
content: `${ | ||
enabled | ||
? "Foolish Steve! You shall regret this. Buahahahaha!" | ||
: "Foolish Steve! I knew you could not handle it. Buahahahaha!" | ||
}`, | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
await prisma.guild.update({ | ||
where: { id: guild.id }, | ||
data: { | ||
laugh: enabled, | ||
}, | ||
}); | ||
|
||
return interaction.reply({ | ||
content: `${ | ||
enabled | ||
? "Foolish Steve! You shall regret this. Buahahahaha!" | ||
: "Foolish Steve! I knew you could not handle it. Buahahahaha!" | ||
}`, | ||
ephemeral: true, | ||
}); | ||
} catch (err: any) { | ||
writeLog(LogLevel.Error, this.name, err.message); | ||
return interaction.reply({ | ||
content: `What the frig? There was an error setting the laugh option: ${err.message}`, | ||
ephemeral: true, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters