mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 08:20:58 -05:00
Optimize a few things
This commit is contained in:
parent
3208030313
commit
1e2ba296f5
@ -17,8 +17,6 @@ import {
|
|||||||
} from './models/IMPORTS.js';
|
} from './models/IMPORTS.js';
|
||||||
import DatabaseServer from './components/DatabaseServer.js';
|
import DatabaseServer from './components/DatabaseServer.js';
|
||||||
import CacheServer from './components/CacheServer.js';
|
import CacheServer from './components/CacheServer.js';
|
||||||
import fxp from 'fast-xml-parser';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
import TSClient from './helpers/TSClient.js';
|
import TSClient from './helpers/TSClient.js';
|
||||||
|
|
||||||
export default class TClient extends Discord.Client {
|
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 embed: typeof Discord.EmbedBuilder = Discord.EmbedBuilder;
|
||||||
public collection: typeof Discord.Collection = Discord.Collection;
|
public collection: typeof Discord.Collection = Discord.Collection;
|
||||||
public attachment: typeof Discord.AttachmentBuilder = Discord.AttachmentBuilder;
|
public attachment: typeof Discord.AttachmentBuilder = Discord.AttachmentBuilder;
|
||||||
public dayjs: typeof dayjs = dayjs;
|
|
||||||
public fxp: typeof fxp = fxp;
|
|
||||||
public dailyMsgs: DailyMsgsSvc = new DailyMsgsSvc();
|
public dailyMsgs: DailyMsgsSvc = new DailyMsgsSvc();
|
||||||
public userLevels: UserLevelsSvc = new UserLevelsSvc(this);
|
public userLevels: UserLevelsSvc = new UserLevelsSvc(this);
|
||||||
public punishments: PunishmentsSvc = new PunishmentsSvc(this);
|
public punishments: PunishmentsSvc = new PunishmentsSvc(this);
|
||||||
|
@ -3,9 +3,6 @@ import TClient from '../client.js';
|
|||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
export default class Automoderator {
|
export default class Automoderator {
|
||||||
private static lockQuery:Set<Discord.Snowflake> = new Set();
|
private static lockQuery:Set<Discord.Snowflake> = 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) {
|
static scanMsg(message:Discord.Message) {
|
||||||
return message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
|
return message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
|
||||||
}
|
}
|
||||||
|
@ -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){
|
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.';
|
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;
|
automodded = true;
|
||||||
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
|
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
|
||||||
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000));
|
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 = {
|
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}>!`],
|
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';
|
const GeneralChatID = ConfigHelper.isDevMode() ? '929807948748832801' : '468835415093411863';
|
||||||
Response.create(client, message, GeneralChatID, 'morning');
|
Response.create(message, GeneralChatID, 'morning');
|
||||||
Response.create(client, message, GeneralChatID, 'afternoon');
|
Response.create(message, GeneralChatID, 'afternoon');
|
||||||
Response.create(client, message, GeneralChatID, 'evening');
|
Response.create(message, GeneralChatID, 'evening');
|
||||||
Response.create(client, message, GeneralChatID, 'night');
|
Response.create(message, GeneralChatID, 'night');
|
||||||
|
|
||||||
CmdTrigger.registerCmds(client, message, 'register');
|
CmdTrigger.registerCmds(client, message, 'register');
|
||||||
CmdTrigger.MFPwTrigger(message, 'farmpw');
|
CmdTrigger.MFPwTrigger(message, 'farmpw');
|
||||||
|
@ -6,6 +6,7 @@ import FormatPlayer from '../helpers/FormatPlayer.js';
|
|||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
import HookMgr from '../components/HookManager.js';
|
import HookMgr from '../components/HookManager.js';
|
||||||
import {IServer} from '../models/MPServer.js';
|
import {IServer} from '../models/MPServer.js';
|
||||||
|
import {XMLParser} from 'fast-xml-parser';
|
||||||
import {FSPlayer, FSData, FSCareerSavegame} from 'src/interfaces';
|
import {FSPlayer, FSData, FSCareerSavegame} from 'src/interfaces';
|
||||||
|
|
||||||
let loggingPrefix:string = 'MPModule';
|
let loggingPrefix:string = 'MPModule';
|
||||||
@ -154,7 +155,7 @@ export async function requestServerData(client:TClient, server:IServer):Promise<
|
|||||||
try {
|
try {
|
||||||
const [DSSR, CSGR] = await Promise.allSettled([
|
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<FSData>),
|
retryReqs('http://'+server.ip+'/feed/dedicated-server-stats.json?code='+server.code, 3).then(x=>x.json() as Promise<FSData>),
|
||||||
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 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;
|
const csg = CSGR.status === 'fulfilled' && CSGR.value && CSGR.value.slotSystem ? CSGR.value : null;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import dayjs from 'dayjs';
|
||||||
import Formatters from '../helpers/Formatters.js';
|
import Formatters from '../helpers/Formatters.js';
|
||||||
|
|
||||||
export default class Response {
|
export default class Response {
|
||||||
@ -21,15 +21,15 @@ export default class Response {
|
|||||||
suffix: ['all', 'everyone', 'guys', 'yall', 'y\'all']
|
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;
|
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 (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 PersonnyMcPerson = `**${message.member.displayName}**`;
|
||||||
// const responseCreator =(id:Discord.Snowflake)=>`\n╰*Response made by <@${id}>*`;
|
// const responseCreator =(id:Discord.Snowflake)=>`\n╰*Response made by <@${id}>*`;
|
||||||
return {
|
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()}!`,
|
`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!`,
|
'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!',
|
`## 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'
|
'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: [
|
afternoon: [
|
||||||
|
Loading…
Reference in New Issue
Block a user