diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 16:15:06 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-12-29 16:15:06 -0500 |
| commit | 08d7e6eb125c5ff6846c3a92491de79d291b8e12 (patch) | |
| tree | 4abdaeee3ad258ef8fa0d7b517ea49d262d18b0b /src | |
| parent | f9cf43fc47be2d497d92d728ea892246df96d736 (diff) | |
| download | tanzanite-08d7e6eb125c5ff6846c3a92491de79d291b8e12.tar.gz tanzanite-08d7e6eb125c5ff6846c3a92491de79d291b8e12.tar.bz2 tanzanite-08d7e6eb125c5ff6846c3a92491de79d291b8e12.zip | |
misc improvements & typings changes
Diffstat (limited to 'src')
31 files changed, 158 insertions, 533 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index 8c7c540..026f1a6 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -62,7 +62,7 @@ export default class ChannelPermissionsCommand extends BushCommand { state: 'true' | 'false' | 'neutral'; } ) { - if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); + if (!message.inGuild()) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 5ef379a..6e82011 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -37,8 +37,8 @@ export default class RoleAllCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { role: ArgType<'role'>; bots: boolean }) { - if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); + public override async exec(message: BushMessage | BushSlashMessage, args: { role: ArgType<'role'>; bots: ArgType<'boolean'> }) { + if (!message.inGuild()) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); if (!message.member!.permissions.has('ADMINISTRATOR') && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/config/customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index cf37595..cd59c9a 100644 --- a/src/commands/config/customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -12,37 +12,22 @@ // { // id: 'required_argument', // type: 'string', -// prompt: { -// start: 'What would you like to set your first argument to be?', -// retry: '{error} Pick a valid argument.', -// optional: false -// } +// description: 'This is the first argument.', +// prompt: 'What would you like to set your first argument to be?', +// retry: '{error} Pick a valid argument.', +// slashType: 'STRING' // }, // { // id: 'optional_argument', // type: 'string', -// prompt: { -// start: 'What would you like to set your second argument to be?', -// retry: '{error} Pick a valid argument.', -// optional: true -// } +// description: 'This is the second argument.', +// prompt: 'What would you like to set your second argument to be?', +// retry: '{error} Pick a valid argument.', +// optional: true, +// slashType: 'STRING' // } // ], // slash: true, -// slashOptions: [ -// { -// name: 'required_argument', -// description: 'What would you like to set your first argument to be?', -// type: 'STRING', -// required: true -// }, -// { -// name: 'optional_argument', -// description: 'What would you like to set your second argument to be?', -// type: 'STRING', -// required: false -// } -// ], // channel: 'guild', // clientPermissions: (m) => util.clientSendAndPermCheck(m), // userPermissions: ['MANAGE_GUILD'] @@ -52,8 +37,5 @@ // public override async exec( // message: BushMessage | BushSlashMessage, // args: { required_argument: string; optional_argument: string } -// ) { -// return await message.util.reply(`${util.emojis.error} Do not use the template command.`); -// args; -// } +// ) {} // } diff --git a/src/commands/config/levelRoles.ts b/src/commands/config/_levelRoles.ts index 7f99580..af7e637 100644 --- a/src/commands/config/levelRoles.ts +++ b/src/commands/config/_levelRoles.ts @@ -10,39 +10,24 @@ // examples: ['level-role 1 2'], // args: [ // { -// id: 'action', -// customType: ['add', 'remove'] -// }, -// { -// id: 'role', -// type: 'role', +// id: 'required_argument', +// type: 'string', +// description: 'This is the first argument.', // prompt: 'What would you like to set your first argument to be?', // retry: '{error} Pick a valid argument.', -// optional: false +// slashType: 'STRING' // }, // { -// id: 'level', -// type: 'integer', +// id: 'optional_argument', +// type: 'string', +// description: 'This is the second argument.', // prompt: 'What would you like to set your second argument to be?', // retry: '{error} Pick a valid argument.', -// optional: false +// optional: true, +// slashType: 'STRING' // } // ], // slash: true, -// slashOptions: [ -// { -// name: 'role', -// description: 'What would you like to set your first argument to be?', -// type: 'STRING', -// required: true -// }, -// { -// name: 'level', -// description: 'What would you like to set your second argument to be?', -// type: 'STRING', -// required: true -// } -// ], // channel: 'guild', // clientPermissions: (m) => util.clientSendAndPermCheck(m), // userPermissions: ['MANAGE_GUILD', 'MANAGE_ROLES'] @@ -52,8 +37,5 @@ // public override async exec( // message: BushMessage | BushSlashMessage, // args: { required_argument: string; optional_argument: string } -// ) { -// return await message.util.reply(`${util.emojis.error} Do not use the template command.`); -// args; -// } +// ) {} // } diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index d119774..d15b8d7 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import { User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { @@ -16,10 +16,7 @@ export default class BlacklistCommand extends BushCommand { readableType: "'blacklist'|'unblacklist'", prompt: 'Would you like to add or remove someone or something from/to the blacklist?', slashType: 'STRING', - choices: [ - { name: 'blacklist', value: 'blacklist' }, - { name: 'unblacklist', value: 'unblacklist' } - ], + choices: ['blacklist', 'unblacklist'].map((c) => ({ name: c, value: c })), only: 'slash' }, { @@ -51,7 +48,11 @@ export default class BlacklistCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { action?: 'blacklist' | 'unblacklist'; target: ArgType<'channel'> | ArgType<'user'> | string; global: boolean } + args: { + action?: 'blacklist' | 'unblacklist'; + target: ArgType<'channel'> | ArgType<'user'> | string; // there is no way to combine channel and user in slash commands without making subcommands + global: ArgType<'boolean'>; + } ) { let action: 'blacklist' | 'unblacklist' | 'toggle' = args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist' | undefined) ?? 'toggle'; diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 4341198..11d9649 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptionalArgType } from '#lib'; export default class TemplateCommand extends BushCommand { public constructor() { @@ -39,7 +39,7 @@ export default class TemplateCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { required_argument: string; optional_argument: string } + args: { required_argument: ArgType<'string'>; optional_argument: OptionalArgType<'string'> } ) { return await message.util.reply(`${util.emojis.error} Do not use the template command.`); args; diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index 4133b96..d702875 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,4 @@ -import { ArgType, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; export default class DMCommand extends BushCommand { public constructor() { @@ -21,10 +21,9 @@ export default class DMCommand extends BushCommand { id: 'content', type: 'string', match: 'rest', - description: 'This is the second argument.', - prompt: 'What would you like to set your second argument to be?', - retry: '{error} Pick a valid argument.', - optional: true, + description: 'The content to send to the user.', + prompt: 'What would you like to send to the user?', + retry: '{error} Pick something to send the user.', slashType: 'STRING' } ], @@ -35,10 +34,12 @@ export default class DMCommand extends BushCommand { userPermissions: [] }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'user'>; content: string }) { + public override async exec( + message: BushMessage | BushSlashMessage, + args: { user: ArgType<'user'>; content: ArgType<'string'> } + ) { try { - const u = await client.users.fetch(args.user.id); - await u.send(args.content); + await client.users.send(args.user.id, args.content); } catch (e) { return message.util.reply(`${util.emojis.error} There was an error sending ${util.format.input(args.user.tag)} a dm.`); } diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index 80cbbe2..2c8151f 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -26,7 +26,7 @@ export default class SayCommand extends BushCommand { }); } - public override async exec(message: BushMessage, args: { content: string }) { + public override async exec(message: BushMessage | BushSlashMessage, args: { content: string }) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index 35e98aa..3a6406d 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,4 +1,4 @@ -import { ArgType, BushCommand, Global, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, Global, type ArgType, type BushMessage } from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; export default class SuperUserCommand extends BushCommand { @@ -53,10 +53,7 @@ export default class SuperUserCommand extends BushCommand { return { action, user }; } - public override async exec( - message: BushMessage | BushSlashMessage, - { action, user }: { action: 'add' | 'remove'; user: ArgType<'user'> } - ) { + public override async exec(message: BushMessage, { action, user }: { action: 'add' | 'remove'; user: ArgType<'user'> }) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); diff --git a/src/commands/moderation/activePunishments.ts b/src/commands/moderation/_activePunishments.ts index d40f2ba..d40f2ba 100644 --- a/src/commands/moderation/activePunishments.ts +++ b/src/commands/moderation/_activePunishments.ts diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index bede2cf..919ee40 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -1,4 +1,5 @@ -import { ArgType, BushCommand, type BushMessage } from '#lib'; +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import assert from 'assert'; import { Message, type Emoji } from 'discord.js'; export default class RemoveReactionEmojiCommand extends BushCommand { @@ -37,9 +38,10 @@ export default class RemoveReactionEmojiCommand extends BushCommand { } public override async exec( - message: BushMessage, + message: BushMessage | BushSlashMessage, args: { message: ArgType<'guildMessage'> | string; emoji: ArgType<'emoji'> | ArgType<'snowflake'> } ) { + assert(message.channel); const resolvedMessage = args.message instanceof Message ? args.message : await message.channel.messages.fetch(args.message); const id = !(['string'] as const).includes(typeof args.emoji); diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index d36a5db..e7a19d6 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -1,12 +1,12 @@ import { AllowedMentions, - ArgType, BushCommand, Moderation, - OptionalArgType, + type ArgType, type BushGuildMember, type BushMessage, - type BushSlashMessage + type BushSlashMessage, + type OptionalArgType } from '#lib'; export default class UnmuteCommand extends BushCommand { @@ -56,7 +56,7 @@ export default class UnmuteCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - { user, reason, force }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force: boolean } + { user, reason, force = false }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force?: boolean } ) { const error = util.emojis.error; const member = message.guild!.members.cache.get(user.id) as BushGuildMember; diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 95e409d..5093c9b 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,12 +1,12 @@ import { AllowedMentions, - ArgType, BushCommand, Moderation, - OptionalArgType, + type ArgType, type BushGuildMember, type BushMessage, - type BushSlashMessage + type BushSlashMessage, + type OptionalArgType } from '#lib'; export default class WarnCommand extends BushCommand { @@ -55,7 +55,7 @@ export default class WarnCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - { user, reason, force }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force?: boolean } + { user, reason, force = false }: { user: ArgType<'user'>; reason: OptionalArgType<'string'>; force?: boolean } ) { const member = message.guild!.members.cache.get(user.id) as BushGuildMember; if (!member) return message.util.reply(`${util.emojis.error} I cannot warn users that are not in the server.`); diff --git a/src/commands/utilities/remind.ts b/src/commands/utilities/remind.ts index 8df24c1..6339343 100644 --- a/src/commands/utilities/remind.ts +++ b/src/commands/utilities/remind.ts @@ -1,4 +1,4 @@ -import { ArgType, BushCommand, Reminder, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, Reminder, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; export default class RemindCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/reminders.ts b/src/commands/utilities/reminders.ts index 7180aa9..34034d8 100644 --- a/src/commands/utilities/reminders.ts +++ b/src/commands/utilities/reminders.ts @@ -1,5 +1,5 @@ import { BushCommand, ButtonPaginator, Reminder, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbedOptions } from 'discord.js'; +import { type MessageEmbedOptions } from 'discord.js'; import { Op } from 'sequelize'; export default class RemindersCommand extends BushCommand { diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 480201a..67b8382 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,5 +1,5 @@ -import { ArgType, BushCommand, BushSlashMessage, type BushMessage } from '#lib'; -import { ArgumentOptions, ArgumentType, ArgumentTypeCaster, Flag } from 'discord-akairo'; +import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { type ArgumentOptions, type ArgumentType, type ArgumentTypeCaster, type Flag } from 'discord-akairo'; import _ from 'lodash'; import { URL } from 'url'; diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index 641f7ec..f0d75a2 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { Message, MessageEmbed } from 'discord.js'; +import { MessageEmbed, type Message } from 'discord.js'; export default class TemplateCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts index 6195edd..d842b58 100644 --- a/src/commands/utilities/uuid.ts +++ b/src/commands/utilities/uuid.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage } from '#lib'; +import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; export default class UuidCommand extends BushCommand { public constructor() { @@ -35,7 +35,7 @@ export default class UuidCommand extends BushCommand { } public override async exec( - message: BushMessage, + message: BushMessage | BushSlashMessage, { ign, dashed }: { ign: { match: RegExpMatchArray; matches: any[] }; dashed: boolean } ) { if (!ign) return await message.util.reply(`${util.emojis.error} Please enter a valid ign.`); diff --git a/src/lib/common/Format.ts b/src/lib/common/Format.ts deleted file mode 100644 index 6cb6edc..0000000 --- a/src/lib/common/Format.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { type CodeBlockLang } from '#lib'; -import { EscapeMarkdownOptions, Formatters, Util } from 'discord.js'; - -/** - * Formats and escapes content for formatting - */ -export class Format { - /** - * Wraps the content inside a codeblock with no language. - * @param content The content to wrap. - */ - public static codeBlock(content: string): string; - - /** - * Wraps the content inside a codeblock with the specified language. - * @param language The language for the codeblock. - * @param content The content to wrap. - */ - public static codeBlock(language: CodeBlockLang, content: string): string; - public static codeBlock(languageOrContent: string, content?: string): string { - return typeof content === 'undefined' - ? Formatters.codeBlock(Util.escapeCodeBlock(`${languageOrContent}`)) - : Formatters.codeBlock(`${languageOrContent}`, Util.escapeCodeBlock(`${content}`)); - } - - /** - * Wraps the content inside \`backticks\`, which formats it as inline code. - * @param content The content to wrap. - */ - public static inlineCode(content: string): string { - return Formatters.inlineCode(Util.escapeInlineCode(`${content}`)); - } - - /** - * Formats the content into italic text. - * @param content The content to wrap. - */ - public static italic(content: string): string { - return Formatters.italic(Util.escapeItalic(`${content}`)); - } - - /** - * Formats the content into bold text. - * @param content The content to wrap. - */ - public static bold(content: string): string { - return Formatters.bold(Util.escapeBold(`${content}`)); - } - - /** - * Formats the content into underscored text. - * @param content The content to wrap. - */ - public static underscore(content: string): string { - return Formatters.underscore(Util.escapeUnderline(`${content}`)); - } - - /** - * Formats the content into strike-through text. - * @param content The content to wrap. - */ - public static strikethrough(content: string): string { - return Formatters.strikethrough(Util.escapeStrikethrough(`${content}`)); - } - - /** - * Wraps the content inside spoiler (hidden text). - * @param content The content to wrap. - */ - public static spoiler(content: string): string { - return Formatters.spoiler(Util.escapeSpoiler(`${content}`)); - } - - /** - * Escapes any Discord-flavour markdown in a string. - * @param text Content to escape - * @param options Options for escaping the markdown - */ - public static escapeMarkdown(text: string, options?: EscapeMarkdownOptions): string { - return Util.escapeMarkdown(`${text}`, options); - } - - /** - * Formats input: makes it bold and escapes any other markdown - * @param text The input - */ - public static input(text: string): string { - return this.bold(this.escapeMarkdown(this.sanitizeWtlAndControl(`${text}`))); - } - - /** - * Formats input for logs: makes it highlighted - * @param text The input - */ - public static inputLog(text: string): string { - return `<<${this.sanitizeWtlAndControl(`${text}`)}>>`; - } - - /** - * Removes all characters in a string that are either control characters or change the direction of text etc. - * @param str The string you would like sanitized - */ - public static sanitizeWtlAndControl(str: string) { - // eslint-disable-next-line no-control-regex - return `${str}`.replace(/[\u0000-\u001F\u007F-\u009F\u200B]/g, ''); - } -} diff --git a/src/lib/common/Moderation.ts b/src/lib/common/Moderation.ts deleted file mode 100644 index ab2943b..0000000 --- a/src/lib/common/Moderation.ts +++ /dev/null @@ -1,293 +0,0 @@ -import { - ActivePunishment, - ActivePunishmentType, - Guild, - ModLog, - ModLogType, - type BushGuildMember, - type BushGuildMemberResolvable, - type BushGuildResolvable -} from '#lib'; -import { type Snowflake } from 'discord.js'; - -/** - * A utility class with moderation-related methods. - */ -export class Moderation { - /** - * Checks if a moderator can perform a moderation action on another user. - * @param moderator The person trying to perform the action. - * @param victim The person getting punished. - * @param type The type of punishment - used to format the response. - * @param checkModerator Whether or not to check if the victim is a moderator. - * @param force Override permissions checks. - * @returns `true` if the moderator can perform the action otherwise a reason why they can't. - */ - public static async permissionCheck( - moderator: BushGuildMember, - victim: BushGuildMember, - type: 'mute' | 'unmute' | 'warn' | 'kick' | 'ban' | 'unban' | 'add a punishment role to' | 'remove a punishment role from', - checkModerator = true, - force = false - ): Promise<true | string> { - if (force) return true; - - // If the victim is not in the guild anymore it will be undefined - if ((!victim || !victim.guild) && !['ban', 'unban'].includes(type)) return true; - - if (moderator.guild.id !== victim.guild.id) { - throw new Error('moderator and victim not in same guild'); - } - - const isOwner = moderator.guild.ownerId === moderator.id; - if (moderator.id === victim.id && !type.startsWith('un')) { - return `${util.emojis.error} You cannot ${type} yourself.`; - } - if ( - moderator.roles.highest.position <= victim.roles.highest.position && - !isOwner && - !(type.startsWith('un') && moderator.id === victim.id) - ) { - return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as you do.`; - } - if ( - victim.roles.highest.position >= victim.guild.me!.roles.highest.position && - !(type.startsWith('un') && moderator.id === victim.id) - ) { - return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they have higher or equal role hierarchy as I do.`; - } - if (checkModerator && victim.permissions.has('MANAGE_MESSAGES') && !(type.startsWith('un') && moderator.id === victim.id)) { - if (await moderator.guild.hasFeature('modsCanPunishMods')) { - return true; - } else { - return `${util.emojis.error} You cannot ${type} **${victim.user.tag}** because they are a moderator.`; - } - } - return true; - } - - /** - * Creates a modlog entry for a punishment. - * @param options Options for creating a modlog entry. - * @param getCaseNumber Whether or not to get the case number of the entry. - * @returns An object with the modlog and the case number. - */ - public static async createModLogEntry( - options: CreateModLogEntryOptions, - getCaseNumber = false - ): Promise<{ log: ModLog | null; caseNum: number | null }> { - const user = (await util.resolveNonCachedUser(options.user))!.id; - const moderator = (await util.resolveNonCachedUser(options.moderator))!.id; - const guild = client.guilds.resolveId(options.guild)!; - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const duration = options.duration || undefined; - - // If guild does not exist create it so the modlog can reference a guild. - await Guild.findOrCreate({ - where: { - id: guild - }, - defaults: { - id: guild - } - }); - - const modLogEntry = ModLog.build({ - type: options.type, - user, - moderator, - reason: options.reason, - duration: duration, - guild, - pseudo: options.pseudo ?? false, - evidence: options.evidence - }); - const saveResult: ModLog | null = await modLogEntry.save().catch(async (e) => { - await util.handleError('createModLogEntry', e); - return null; - }); - - if (!getCaseNumber) return { log: saveResult, caseNum: null }; - - const caseNum = (await ModLog.findAll({ where: { type: options.type, user: user, guild: guild, hidden: 'false' } }))?.length; - return { log: saveResult, caseNum }; - } - - /** - * Creates a punishment entry. - * @param options Options for creating the punishment entry. - * @returns The database entry, or null if no entry is created. - */ - public static async createPunishmentEntry(options: CreatePunishmentEntryOptions): Promise<ActivePunishment | null> { - const expires = options.duration ? new Date(+new Date() + options.duration ?? 0) : undefined; - const user = (await util.resolveNonCachedUser(options.user))!.id; - const guild = client.guilds.resolveId(options.guild)!; - const type = this.findTypeEnum(options.type)!; - - const entry = ActivePunishment.build( - options.extraInfo - ? { user, type, guild, expires, modlog: options.modlog, extraInfo: options.extraInfo } - : { user, type, guild, expires, modlog: options.modlog } - |
