|
| 1 | +import { ApplicationCommandMessage } from "@fire/lib/extensions/appcommandmessage"; |
| 2 | +import { FireMember } from "@fire/lib/extensions/guildmember"; |
| 3 | +import { Command } from "@fire/lib/util/command"; |
| 4 | +import { Language } from "@fire/lib/util/language"; |
| 5 | +import { PermissionFlagsBits } from "discord-api-types/v9"; |
| 6 | + |
| 7 | +export default class TempMediaPerms extends Command { |
| 8 | + constructor() { |
| 9 | + super("temp-media-perms", { |
| 10 | + description: (language: Language) => |
| 11 | + language.get("TEMP_MEDIA_PERMS_COMMAND_DESCRIPTION"), |
| 12 | + args: [ |
| 13 | + { |
| 14 | + id: "user", |
| 15 | + type: "member", |
| 16 | + description: (language: Language) => |
| 17 | + language.get("TEMP_MEDIA_PERMS_ARGUMENT_USER_DESCRIPTION"), |
| 18 | + default: undefined, |
| 19 | + required: true, |
| 20 | + }, |
| 21 | + ], |
| 22 | + guilds: ["864592657572560958"], |
| 23 | + enableSlashCommand: true, |
| 24 | + restrictTo: "guild", |
| 25 | + moderatorOnly: true, |
| 26 | + slashOnly: true, |
| 27 | + ephemeral: true, |
| 28 | + }); |
| 29 | + } |
| 30 | + |
| 31 | + async run(command: ApplicationCommandMessage, args: { user: FireMember }) { |
| 32 | + if (!args.user) return await command.error("TEMP_MEDIA_PERMS_MISSING_USER"); |
| 33 | + if ( |
| 34 | + args.user.permissions.has( |
| 35 | + PermissionFlagsBits.AttachFiles | PermissionFlagsBits.EmbedLinks |
| 36 | + ) |
| 37 | + ) |
| 38 | + return await command.error("TEMP_MEDIA_PERMS_ALREADY_HAS"); |
| 39 | + |
| 40 | + const role = command.guild.roles.cache.find( |
| 41 | + (role) => role.name == "TEMP MEDIA PERMISSIONS" |
| 42 | + ); |
| 43 | + const added = await args.user.roles |
| 44 | + .add( |
| 45 | + role, |
| 46 | + command.language.get("TEMP_MEDIA_PERMS_REASON", { |
| 47 | + author: `${command.author} (${command.author.id})`, |
| 48 | + }) |
| 49 | + ) |
| 50 | + .catch(() => {}); |
| 51 | + if (!added) return await command.error("COMMAND_ERROR_500"); |
| 52 | + else |
| 53 | + setTimeout(() => { |
| 54 | + args.user.roles.remove( |
| 55 | + role, |
| 56 | + command.language.get("TEMP_MEDIA_PERMS_REASON", { |
| 57 | + author: `${command.author} (${command.author.id})`, |
| 58 | + }) |
| 59 | + ); |
| 60 | + }, 120_000); |
| 61 | + } |
| 62 | +} |
0 commit comments