diff --git a/config.example.jsonc b/config.example.jsonc index 2f0e478..5f815e7 100644 --- a/config.example.jsonc +++ b/config.example.jsonc @@ -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" + } } diff --git a/package.json b/package.json index 56ac174..20eaa5a 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a91c0d..ebe1993 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,7 +7,7 @@ settings: dependencies: '@oceanicjs/builders': specifier: ^1.1.7 - version: 1.1.7(oceanic.js@1.7.0) + version: 1.1.7(oceanic.js@1.8.1-dev.08d3811) '@octokit/rest': specifier: ^19.0.11 version: 19.0.11 @@ -36,8 +36,8 @@ dependencies: specifier: ^1.10.0 version: 1.10.0 oceanic.js: - specifier: ^1.7.0 - version: 1.7.0 + specifier: 1.8.1-dev.08d3811 + version: 1.8.1-dev.08d3811 semver: specifier: ^7.5.1 version: 7.5.1 @@ -134,7 +134,7 @@ packages: '@types/ws': 8.5.4 discord-api-types: 0.37.39 prism-media: 1.3.5 - tslib: 2.5.2 + tslib: 2.6.2 ws: 8.13.0 transitivePeerDependencies: - '@discordjs/opus' @@ -249,12 +249,12 @@ packages: fastq: 1.13.0 dev: true - /@oceanicjs/builders@1.1.7(oceanic.js@1.7.0): + /@oceanicjs/builders@1.1.7(oceanic.js@1.8.1-dev.08d3811): resolution: {integrity: sha512-pF7tL9vzkHfLWO7IBKHm4uHl2M28VkWXhiV5Ap8t4DMpM3ZrxkQnFjJ60w3SFikpxQ9jDc5x5eVvbDwUWq7yqA==} peerDependencies: oceanic.js: '*' dependencies: - oceanic.js: 1.7.0 + oceanic.js: 1.8.1-dev.08d3811 dev: false /@octokit/auth-token@3.0.1: @@ -2408,12 +2408,12 @@ packages: es-abstract: 1.21.2 dev: true - /oceanic.js@1.7.0: - resolution: {integrity: sha512-gjmfcofqQ0wgr0WM9VsYnkMBmu5jvMTfVl79tVq+9sJFakfwMGO66pkaUNFULPQOUahUI1giUAe/nZTA784/4A==} + /oceanic.js@1.8.1-dev.08d3811: + resolution: {integrity: sha512-2iNt3c1tk2xYBc73Uh7iUF7EvjTAGM070MEcXC/ZNhGCpDVwwdMDu4yroUwlVJz3DT63c8Mnq+c6j60m/INWpA==} engines: {node: '>=16.16.0'} dependencies: - tslib: 2.5.2 - undici: 5.22.1 + tslib: 2.6.2 + undici: 5.24.0 ws: 8.13.0 optionalDependencies: '@discordjs/voice': 0.16.0 @@ -3004,6 +3004,11 @@ packages: /tslib@2.5.2: resolution: {integrity: sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==} + dev: true + + /tslib@2.6.2: + resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: false /tsutils@3.21.0(typescript@5.0.4): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} @@ -3081,8 +3086,8 @@ packages: which-boxed-primitive: 1.0.2 dev: true - /undici@5.22.1: - resolution: {integrity: sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==} + /undici@5.24.0: + resolution: {integrity: sha512-OKlckxBjFl0oXxcj9FU6oB8fDAaiRUq+D8jrFWGmOfI/gIyjk/IeS75LMzgYKUaeHzLUcYvf9bbJGSrUwTfwwQ==} engines: {node: '>=14.0'} dependencies: busboy: 1.6.0 diff --git a/src/commands/degenerates.ts b/src/commands/degenerates.ts new file mode 100644 index 0000000..dd986d6 --- /dev/null +++ b/src/commands/degenerates.ts @@ -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); + }); + }); + } +}