|
| 1 | +import { container } from '@sapphire/framework'; |
| 2 | +import { Permissions, User } from 'discord.js'; |
| 3 | +import { |
| 4 | + CodeyCommandDetails, |
| 5 | + CodeyCommandOptionType, |
| 6 | + CodeyCommandResponseType, |
| 7 | + SapphireMessageExecuteType |
| 8 | +} from '../../codeyCommand'; |
| 9 | +import { getUserPrivacy, changeUserPrivacy } from '../../components/coin'; |
| 10 | + |
| 11 | +// Update coin leaderboard privacy of a user |
| 12 | +const coinUpdateExecuteCommand: SapphireMessageExecuteType = async (client, messageFromUser, args) => { |
| 13 | + if (!(<Readonly<Permissions>>messageFromUser.member?.permissions).has('ADMINISTRATOR')) { |
| 14 | + return `You do not have permission to use this command.`; |
| 15 | + } |
| 16 | + |
| 17 | + // First mandatory argument is user |
| 18 | + const user = <User>args['user']; |
| 19 | + if (!user) { |
| 20 | + throw new Error('please enter a valid user mention or ID for balance adjustment.'); |
| 21 | + } |
| 22 | + |
| 23 | + // Second mandatory argument is privacy |
| 24 | + const privacy = args['privacy']; |
| 25 | + if (typeof privacy !== 'number' || (privacy !== 0 && privacy !== 1)) { |
| 26 | + throw new Error('please enter 0/1 for public/private.'); |
| 27 | + } |
| 28 | + |
| 29 | + // Adjust privacy |
| 30 | + await changeUserPrivacy(user.id, <number>privacy); |
| 31 | + |
| 32 | + // Get new privacy |
| 33 | + const newPrivacy = await getUserPrivacy(user.id); |
| 34 | + return `${user.username} is now ${newPrivacy ? 'private' : 'not private'}.`; |
| 35 | +}; |
| 36 | + |
| 37 | +export const coinPrivacyCommandDetails: CodeyCommandDetails = { |
| 38 | + name: 'privacy', |
| 39 | + aliases: ['p'], |
| 40 | + description: 'Update the leaderboard privacy of a user.', |
| 41 | + detailedDescription: `**Examples:** |
| 42 | + \`${container.botPrefix}coin privacy @Codey 1\``, |
| 43 | + |
| 44 | + isCommandResponseEphemeral: false, |
| 45 | + messageWhenExecutingCommand: 'Updating leaderboard privacy...', |
| 46 | + executeCommand: coinUpdateExecuteCommand, |
| 47 | + codeyCommandResponseType: CodeyCommandResponseType.STRING, |
| 48 | + |
| 49 | + options: [ |
| 50 | + { |
| 51 | + name: 'user', |
| 52 | + description: 'The user to adjust the privacy of,', |
| 53 | + type: CodeyCommandOptionType.USER, |
| 54 | + required: true |
| 55 | + }, |
| 56 | + { |
| 57 | + name: 'privacy', |
| 58 | + description: 'The privacy to set the specified user to,', |
| 59 | + type: CodeyCommandOptionType.NUMBER, |
| 60 | + required: true |
| 61 | + } |
| 62 | + ], |
| 63 | + subcommandDetails: {} |
| 64 | +}; |
0 commit comments