From ffca13d6ba81866c9763b5efa228545cd973d2d8 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Tue, 2 Jan 2024 03:41:25 +1100 Subject: [PATCH] Optimize a few things --- src/client.ts | 4 ---- src/components/Automod.ts | 3 --- src/events/messageCreate.ts | 12 ++++++------ src/modules/MPModule.ts | 3 ++- src/modules/ResponseModule.ts | 14 +++++++------- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/client.ts b/src/client.ts index a65b9a4..1cb7054 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,8 +17,6 @@ import { } from './models/IMPORTS.js'; import DatabaseServer from './components/DatabaseServer.js'; import CacheServer from './components/CacheServer.js'; -import fxp from 'fast-xml-parser'; -import dayjs from 'dayjs'; import TSClient from './helpers/TSClient.js'; export default class TClient extends Discord.Client { @@ -29,8 +27,6 @@ export default class TClient extends Discord.Client { public embed: typeof Discord.EmbedBuilder = Discord.EmbedBuilder; public collection: typeof Discord.Collection = Discord.Collection; public attachment: typeof Discord.AttachmentBuilder = Discord.AttachmentBuilder; - public dayjs: typeof dayjs = dayjs; - public fxp: typeof fxp = fxp; public dailyMsgs: DailyMsgsSvc = new DailyMsgsSvc(); public userLevels: UserLevelsSvc = new UserLevelsSvc(this); public punishments: PunishmentsSvc = new PunishmentsSvc(this); diff --git a/src/components/Automod.ts b/src/components/Automod.ts index 1358568..4a712ba 100644 --- a/src/components/Automod.ts +++ b/src/components/Automod.ts @@ -3,9 +3,6 @@ import TClient from '../client.js'; import Logger from '../helpers/Logger.js'; export default class Automoderator { private static lockQuery:Set = new Set(); - static Whitelist(message:Discord.Message, ...arr:string[]) {// Array of channel ids for automod to be disabled in (Disables prohibitedWords and advertisement, mind you.) - return arr.includes(message.channelId); - } static scanMsg(message:Discord.Message) { return message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join(''); } diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 0c6b9c4..cb878ba 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -14,7 +14,7 @@ export default class MessageCreate { if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id){ const automodFailReason = 'msg got possibly deleted by another bot.'; - if (await client.prohibitedWords.findWord(Automoderator.scanMsg(message))/* && !Whitelist.includes(message.channelId) */) { + if (await client.prohibitedWords.findWord(Automoderator.scanMsg(message))) { automodded = true; message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason)); message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000)); @@ -48,11 +48,11 @@ export default class MessageCreate { const outgoingArrays = { guildBoost: ['Thanks for boosting our server!', 'Thanks for the boost!', 'We appreciate the boost!', `Thank you for the kind boost, <@${message.author.id}>!`], } - const GeneralChatID = ConfigHelper.isDevMode() ? '1160707096493441056' : '468835415093411863'; - Response.create(client, message, GeneralChatID, 'morning'); - Response.create(client, message, GeneralChatID, 'afternoon'); - Response.create(client, message, GeneralChatID, 'evening'); - Response.create(client, message, GeneralChatID, 'night'); + const GeneralChatID = ConfigHelper.isDevMode() ? '929807948748832801' : '468835415093411863'; + Response.create(message, GeneralChatID, 'morning'); + Response.create(message, GeneralChatID, 'afternoon'); + Response.create(message, GeneralChatID, 'evening'); + Response.create(message, GeneralChatID, 'night'); CmdTrigger.registerCmds(client, message, 'register'); CmdTrigger.MFPwTrigger(message, 'farmpw'); diff --git a/src/modules/MPModule.ts b/src/modules/MPModule.ts index 5ce5f6e..7bb3123 100644 --- a/src/modules/MPModule.ts +++ b/src/modules/MPModule.ts @@ -6,6 +6,7 @@ import FormatPlayer from '../helpers/FormatPlayer.js'; import Logger from '../helpers/Logger.js'; import HookMgr from '../components/HookManager.js'; import {IServer} from '../models/MPServer.js'; +import {XMLParser} from 'fast-xml-parser'; import {FSPlayer, FSData, FSCareerSavegame} from 'src/interfaces'; let loggingPrefix:string = 'MPModule'; @@ -154,7 +155,7 @@ export async function requestServerData(client:TClient, server:IServer):Promise< try { const [DSSR, CSGR] = await Promise.allSettled([ retryReqs('http://'+server.ip+'/feed/dedicated-server-stats.json?code='+server.code, 3).then(x=>x.json() as Promise), - retryReqs('http://'+server.ip+'/feed/dedicated-server-savegame.html?code='+server.code+'&file=careerSavegame', 3).then(async x=>(new client.fxp.XMLParser({ignoreAttributes: false, attributeNamePrefix: ''}).parse(await x.text())).careerSavegame as FSCareerSavegame) + retryReqs('http://'+server.ip+'/feed/dedicated-server-savegame.html?code='+server.code+'&file=careerSavegame', 3).then(async x=>(new XMLParser({ignoreAttributes: false, attributeNamePrefix: ''}).parse(await x.text())).careerSavegame as FSCareerSavegame) ]); const dss = DSSR.status === 'fulfilled' && DSSR.value && DSSR.value.server ? DSSR.value : null; const csg = CSGR.status === 'fulfilled' && CSGR.value && CSGR.value.slotSystem ? CSGR.value : null; diff --git a/src/modules/ResponseModule.ts b/src/modules/ResponseModule.ts index 739efee..9df1e96 100644 --- a/src/modules/ResponseModule.ts +++ b/src/modules/ResponseModule.ts @@ -1,5 +1,5 @@ import Discord from 'discord.js'; -import TClient from '../client.js'; +import dayjs from 'dayjs'; import Formatters from '../helpers/Formatters.js'; export default class Response { @@ -21,15 +21,15 @@ export default class Response { suffix: ['all', 'everyone', 'guys', 'yall', 'y\'all'] } } - static create(client:TClient, message:Discord.Message, channel:Discord.Snowflake, keyword:string) { + static create(message:Discord.Message, channel:Discord.Snowflake, keyword:string) { if (message.channelId != channel || message.type != 0) return; - this.respond(client, message, keyword); + this.respond(message, keyword); } - protected static async respond(client:TClient, message:Discord.Message, responseKeyword:string) { + protected static async respond(message:Discord.Message, responseKeyword:string) { if (message.type === Discord.MessageType.Reply) return; - if (new RegExp(`^(${this.incomingArrays[responseKeyword].prefix.join('|')})?\\s?${responseKeyword} (${this.incomingArrays[responseKeyword].suffix.join('|')})\\b`, 'i').test(message.content)) return message.reply(`${this.outgoingArrays(client, message)[responseKeyword][Math.floor(Math.random()*this.outgoingArrays(client, message)[responseKeyword].length)]}`).catch(()=>null) + if (new RegExp(`^(${this.incomingArrays[responseKeyword].prefix.join('|')})?\\s?${responseKeyword} (${this.incomingArrays[responseKeyword].suffix.join('|')})\\b`, 'i').test(message.content)) return message.reply(`${this.outgoingArrays(message)[responseKeyword][Math.floor(Math.random()*this.outgoingArrays(message)[responseKeyword].length)]}`).catch(()=>null) } - protected static outgoingArrays(client:TClient, message:Discord.Message) { + protected static outgoingArrays(message:Discord.Message) { const PersonnyMcPerson = `**${message.member.displayName}**`; // const responseCreator =(id:Discord.Snowflake)=>`\n╰*Response made by <@${id}>*`; return { @@ -42,7 +42,7 @@ export default class Response { `Good grief, is it Monday already? Anyways, morning ${PersonnyMcPerson}..`, `This time I can shout! So here we go! 1..2..3\n*inhales*\nMORNING ${PersonnyMcPerson.toUpperCase()}!`, 'Gooooood morning to you!', `Good morning to you! You know what else is good? A segue to our sponsor, breakfast!\nGet started with getting out of the bed and have some breakfast!`, `## Morning ${PersonnyMcPerson}!`, '### Have a wonderful day ahead of you!', `Here, have some pancakes for breakfast, ${PersonnyMcPerson}`, 'Is it Friday yet? This week is getting boring already!', - `You have reached ${Formatters.DayOfTheYear(Math.floor(client.dayjs().diff(client.dayjs().startOf('year'), 'day', true))+1)} day of the year, also good morning to you as well!`, + `You have reached ${Formatters.DayOfTheYear(Math.floor(dayjs().diff(dayjs().startOf('year'), 'day', true))+1)} day of the year, also good morning to you as well!`, 'Good morning! Have a cookie to start your day with. :cookie:', 'https://tenor.com/view/rambo-family-rambo-rise-and-shine-wake-up-gif-22012440' ], afternoon: [