From 137a0ae7b84f64471b6ac9ad2f343a35b9593dab Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Tue, 16 Jan 2024 22:41:30 +1100 Subject: [PATCH] Missed a few bits here and there --- src/commands/case.ts | 4 ++-- src/commands/prohibitedWords.ts | 2 +- src/commands/purge.ts | 2 +- src/commands/unpunish.ts | 2 +- src/components/Automod.ts | 4 +--- src/components/CacheServer.ts | 8 ++------ src/components/HookManager.ts | 4 +--- src/models/prohibitedWords.ts | 4 +--- 8 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/commands/case.ts b/src/commands/case.ts index 6cd8aa8..4ec7e4c 100644 --- a/src/commands/case.ts +++ b/src/commands/case.ts @@ -19,7 +19,7 @@ export default class Case { } } static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ - if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod'); + if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod'); const caseId = interaction.options.getInteger('id'); ({ update: async()=>{ @@ -56,7 +56,7 @@ export default class Case { value: `Reason: \`${punishment.dataValues.reason}\`\n${punishment.dataValues.duration ? `Duration: ${Formatters.timeFormat(punishment.dataValues.duration, 3)}\n` : ''}Moderator: ${MessageTool.formatMention(punishment.dataValues.moderator, 'user')}${punishment.dataValues.expired ? `\nOverwritten by Case #${punishments.find(x=>x.dataValues.cancels===punishment.dataValues.case_id)?.case_id}` : ''}${punishment.dataValues.cancels ? `\nOverwrites Case #${punishment.dataValues.cancels}` : ''}` } }); - if (!punishments || !userPunishment) return interaction.reply(`**${user.username}** has a clean record.`) + if (!userPunishment.length) return interaction.reply(`**${user.username}** has a clean record.`) const pageNum = interaction.options.getInteger('page') ?? 1; return interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle(`${user.username}'s punishment history`).setDescription(`**ID:** \`${user.id}\``).setFooter({text: `${userPunishment.length} total punishments. Viewing page ${pageNum} out of ${Math.ceil(userPunishment.length/6)}.`}).addFields(userPunishment.slice((pageNum - 1) * 6, pageNum * 6))]}); } diff --git a/src/commands/prohibitedWords.ts b/src/commands/prohibitedWords.ts index ce7f8bb..f8b647e 100644 --- a/src/commands/prohibitedWords.ts +++ b/src/commands/prohibitedWords.ts @@ -4,7 +4,7 @@ import HookMgr from '../components/HookManager.js'; import MessageTool from '../helpers/MessageTool.js'; export default class ProhibitedWords { static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ - if (!MessageTool.isStaff(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return MessageTool.youNeedRole(interaction, 'admin'); + if (!MessageTool.isModerator(interaction.member) && !client.config.whitelist.includes(interaction.member.id)) return MessageTool.youNeedRole(interaction, 'admin'); const word = interaction.options.getString('word'); const wordExists = await client.prohibitedWords.findWord(word); ({ diff --git a/src/commands/purge.ts b/src/commands/purge.ts index 6b0a5b5..0d77fca 100644 --- a/src/commands/purge.ts +++ b/src/commands/purge.ts @@ -3,7 +3,7 @@ import TClient from '../client.js'; import MessageTool from '../helpers/MessageTool.js'; export default class Purge { static async run(_client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ - if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod'); + if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod'); const amount = interaction.options.getInteger('amount') as number; if (amount > 100) return interaction.reply({content: 'Discord API limits purging up to 100 messages.', ephemeral: true}) const user = interaction.options.getUser('user'); diff --git a/src/commands/unpunish.ts b/src/commands/unpunish.ts index 84b740e..2b05947 100644 --- a/src/commands/unpunish.ts +++ b/src/commands/unpunish.ts @@ -4,7 +4,7 @@ import Logger from '../helpers/Logger.js'; import MessageTool from '../helpers/MessageTool.js'; export default class Unpunish { static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ - if (!MessageTool.isStaff(interaction.member as Discord.GuildMember)) return MessageTool.youNeedRole(interaction, 'dcmod'); + if (!MessageTool.isModerator(interaction.member as Discord.GuildMember)) return MessageTool.youNeedRole(interaction, 'dcmod'); const punishment = await client.punishments.findCase(interaction.options.getInteger('case_id', true)); if (!punishment) return interaction.reply({content: 'Case ID is not found in database.', ephemeral: true}); if (['unban', 'unmute', 'punishmentOverride'].includes(punishment.dataValues.type)) return interaction.reply({content: 'This case ID is immutable. (Informative case)', ephemeral: true}); diff --git a/src/components/Automod.ts b/src/components/Automod.ts index f169d9a..b5162c8 100644 --- a/src/components/Automod.ts +++ b/src/components/Automod.ts @@ -3,9 +3,7 @@ import TClient from '../client.js'; import Logger from '../helpers/Logger.js'; export default class Automoderator { private static lockQuery:Set = new Set(); - static scanMsg(message:Discord.Message) { - return message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join(''); - } + static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join(''); static async repeatedMessages(client:TClient, message:Discord.Message, thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) { const now = Date.now(); diff --git a/src/components/CacheServer.ts b/src/components/CacheServer.ts index 44cfe94..c755a45 100644 --- a/src/components/CacheServer.ts +++ b/src/components/CacheServer.ts @@ -29,12 +29,8 @@ export default class CacheServer { if (jsonMode) return await RedisClient.json.set(key, '.', value); else return await RedisClient.set(key, JSON.stringify(value)); } - public static async expiry(key:any, time:number) { - return await RedisClient.expire(key, time); // NOTE: time is in seconds, not milliseconds -- you know what you did wrong - } - public static async delete(key:any) { - return await RedisClient.del(key); - } + public static expiry = async(key:any, time:number)=>await RedisClient.expire(key, time); // NOTE: time is in seconds, not milliseconds -- you know what you did wrong + public static delete = async(key:any)=>await RedisClient.del(key); public static init() { try { RedisClient.connect(); diff --git a/src/components/HookManager.ts b/src/components/HookManager.ts index e62a603..b64f27c 100644 --- a/src/components/HookManager.ts +++ b/src/components/HookManager.ts @@ -14,9 +14,7 @@ export default class HookMgr { this.webhookId = webhookId; } - protected async channelFetch(client:TClient, channel:ChannelList) { - return await client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel; - } + protected channelFetch = async(client:TClient, channel:ChannelList)=>await client.channels.fetch(config.dcServer.channels[channel]) as Discord.TextChannel; protected async fetch(client:TClient, channel:ChannelList, webhookId:Discord.Snowflake) { const hookInstance = await (await this.channelFetch(client, channel)).fetchWebhooks().then(x=>x.find(y=>y.id===webhookId)); if (!hookInstance) throw new Error('[HookManager] Webhook not found.'); diff --git a/src/models/prohibitedWords.ts b/src/models/prohibitedWords.ts index 67d23e3..c984d20 100644 --- a/src/models/prohibitedWords.ts +++ b/src/models/prohibitedWords.ts @@ -26,9 +26,7 @@ export class ProhibitedWordsSvc { }) this.model.sync(); } - async findWord(word:string) { - return await this.model.findByPk(word); - } + findWord = async(word:string)=>await this.model.findByPk(word); async importWords(file:string) { const jsonData = await new Promise((resolve, reject)=>{ get(file, res=>{