Skip to content

Commit

Permalink
Add degenerates command
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Sep 19, 2023
1 parent 30e3999 commit 6dd393b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 14 deletions.
6 changes: 5 additions & 1 deletion config.example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
"gitSecret": "github webhook secret",
"cookieSecret": "cookie secret",
"encryptionKey": "general encryption key",
"encryptionSalt": "general encryption salt"
"encryptionSalt": "general encryption salt",
"degenerateWebook": {
"id": "webhook id for degenerate notifications",
"token": "webhook token for degenerate notifications"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"fuzzy-search": "^3.2.1",
"jsonc-parser": "^3.2.0",
"morgan": "^1.10.0",
"oceanic.js": "^1.7.0",
"oceanic.js": "1.8.1-dev.08d3811",
"semver": "^7.5.1",
"typedoc": "^0.23.28"
},
Expand Down
29 changes: 17 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions src/commands/degenerates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Command from "../util/Command.js";
import { Config } from "../util/util.js";
import type { ApplicationCommandBuilder } from "@oceanicjs/builders";
import {
ApplicationCommandOptionTypes,
ApplicationCommandTypes,
MessageFlags,
type Client,
type CommandInteraction,
type Member
} from "oceanic.js";

const superRole = "1153797596482121778", role = "1011340058420318228";
export default class DegeneratesCommand extends Command {
override description = "Manage the degenerates";
override name = "degenerates";
override type = ApplicationCommandTypes.CHAT_INPUT;
override async run(this: Client, interaction: CommandInteraction) {
if (!interaction.member!.roles.includes(superRole)) {
return interaction.createMessage({ content: "You do not have permission to use this command.", flags: MessageFlags.EPHEMERAL });
}
const user = interaction.data.options.getMember("user", true);
const [action] = interaction.data.options.getSubCommand<["add" | "remove"]>(true);
switch (action) {
// eslint-disable-next-line unicorn/switch-case-braces
case "add": return DegeneratesCommand.prototype.add.call(this, interaction, user);
// eslint-disable-next-line unicorn/switch-case-braces
case "remove": return DegeneratesCommand.prototype.remove.call(this, interaction, user);
}
}

// eslint-disable-next-line @typescript-eslint/member-ordering
async add(this: Client, interaction: CommandInteraction, user: Member) {
if (user.roles.includes(role)) {
return interaction.createMessage({ content: "This user is already a degenerate.", flags: MessageFlags.EPHEMERAL });
}

await user.addRole(role, "Added by a degenerate");
await this.rest.webhooks.execute(Config.degenerateWebhook.id, Config.degenerateWebhook.token, {
username: interaction.member!.displayName,
avatarURL: interaction.member!.avatarURL(),
content: `${user.mention} has been dragged into degeneracy.`,
flags: MessageFlags.SUPPRESS_NOTIFICATIONS
});
return interaction.createMessage({ content: "Successfully added the user.", flags: MessageFlags.EPHEMERAL });
}

// eslint-disable-next-line @typescript-eslint/member-ordering
async remove(this: Client, interaction: CommandInteraction, user: Member) {
if (!user.roles.includes(role)) {
return interaction.createMessage({ content: "This user is not a degenerate.", flags: MessageFlags.EPHEMERAL });
}

if (user.roles.includes(superRole)) {
return interaction.createMessage({ content: "You cannot remove a super degenerate.", flags: MessageFlags.EPHEMERAL });
}

await user.removeRole(role, "Removed by a degenerate");
await this.rest.webhooks.execute(Config.degenerateWebhook.id, Config.degenerateWebhook.token, {
username: interaction.member!.displayName,
avatarURL: interaction.member!.avatarURL(),
content: `${user.mention} has been removed from degeneracy.`,
flags: MessageFlags.SUPPRESS_NOTIFICATIONS
});
return interaction.createMessage({ content: "Successfully removed the user.", flags: MessageFlags.EPHEMERAL });
}

override setOptions(command: ApplicationCommandBuilder) {
command
.addOption("add", ApplicationCommandOptionTypes.SUB_COMMAND, option => {
option.setDescription("Add a degenerate")
.addOption("user", ApplicationCommandOptionTypes.USER, suboption => {
suboption.setDescription("The user to add.")
.setRequired(true);
});
})
.addOption("remove", ApplicationCommandOptionTypes.SUB_COMMAND, option => {
option.setDescription("Remove a degenerate")
.addOption("user", ApplicationCommandOptionTypes.USER, suboption => {
suboption.setDescription("The user to remove.")
.setRequired(true);
});
});
}
}

0 comments on commit 6dd393b

Please sign in to comment.