mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 12:21:00 -05:00
Improve codebase in various files
This commit is contained in:
parent
81f0427756
commit
6f1f373a82
@ -6,16 +6,16 @@ export default {
|
|||||||
if (!client.config.botSwitches.logs) return;
|
if (!client.config.botSwitches.logs) return;
|
||||||
const channel = (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel);
|
const channel = (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel);
|
||||||
if (oldMember.nickname != newMember.nickname){
|
if (oldMember.nickname != newMember.nickname){
|
||||||
const embed = new client.embed().setColor(client.config.embedColor).setTimestamp().setThumbnail(newMember.user.displayAvatarURL({size: 2048})).setTitle(`Nickname updated: ${newMember.user.username}`).setDescription(`<@${newMember.user.id}>\n\`${newMember.user.id}\``)
|
const embed = new client.embed().setColor(client.config.embedColor).setTimestamp().setThumbnail(newMember.displayAvatarURL({size: 2048})).setTitle(`Nickname updated: ${newMember.user.username}`).setDescription(`<@${newMember.user.id}>\n\`${newMember.user.id}\``)
|
||||||
oldMember.nickname === null ? '' : embed.addFields({name: '🔹 Old nickname', value: `\`\`\`${oldMember.nickname}\`\`\``})
|
oldMember.nickname === null ? '' : embed.addFields({name: '🔹 Old nickname', value: `\`\`\`${oldMember.nickname}\`\`\``})
|
||||||
newMember.nickname === null ? embed.setFooter({text:'Nickname has been reset.'}) : embed.addFields({name: '🔹 New nickname', value: `\`\`\`${newMember.nickname}\`\`\``})
|
newMember.nickname === null ? embed.setFooter({text:'Nickname has been reset.'}) : embed.addFields({name: '🔹 New nickname', value: `\`\`\`${newMember.nickname}\`\`\``})
|
||||||
channel.send({embeds: [embed]})
|
channel.send({embeds: [embed]})
|
||||||
}
|
}
|
||||||
|
|
||||||
const newRoles = newMember.roles.cache.map((x,i)=>i).filter(x=>!oldMember.roles.cache.map((x,i)=>i).some(y=>y===x));
|
const newRoles = newMember.roles.cache.map((_,i)=>i).filter(x=>!oldMember.roles.cache.map((_,i)=>i).some(y=>y===x));
|
||||||
const oldRoles = oldMember.roles.cache.map((x,i)=>i).filter(x=>!newMember.roles.cache.map((x,i)=>i).some(y=>y===x));
|
const oldRoles = oldMember.roles.cache.map((_,i)=>i).filter(x=>!newMember.roles.cache.map((_,i)=>i).some(y=>y===x));
|
||||||
if (newRoles.length === 0 && oldRoles.length == 0) return;
|
if (newRoles.length === 0 && oldRoles.length == 0) return;
|
||||||
const embed = new client.embed().setColor(client.config.embedColor).setThumbnail(newMember.user.displayAvatarURL({size: 2048})).setTitle(`Role updated: ${newMember.user.username}`).setDescription(`<@${newMember.user.id}>\n\`${newMember.user.id}\``)
|
const embed = new client.embed().setColor(client.config.embedColor).setThumbnail(newMember.displayAvatarURL({size: 2048})).setTitle(`Role updated: ${newMember.user.username}`).setDescription(`<@${newMember.user.id}>\n\`${newMember.user.id}\``)
|
||||||
if (newRoles.length != 0) embed.addFields({name: newRoles.length > 1 ? '🔹 Roles added' : '🔹 Role added', value: newRoles.map(x=>`<@&${x}>`).join(' ')});
|
if (newRoles.length != 0) embed.addFields({name: newRoles.length > 1 ? '🔹 Roles added' : '🔹 Role added', value: newRoles.map(x=>`<@&${x}>`).join(' ')});
|
||||||
if (oldRoles.length != 0) embed.addFields({name: oldRoles.length > 1 ? '🔹 Roles removed' : '🔹 Role removed', value: oldRoles.map(x=>`<@&${x}>`).join(' ')});
|
if (oldRoles.length != 0) embed.addFields({name: oldRoles.length > 1 ? '🔹 Roles removed' : '🔹 Role removed', value: oldRoles.map(x=>`<@&${x}>`).join(' ')});
|
||||||
channel.send({embeds: [embed]})
|
channel.send({embeds: [embed]})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
|
import {escapeCodeBlock} from 'discord.js';
|
||||||
export default {
|
export default {
|
||||||
run(client:TClient, msg:Discord.Message){
|
run(client:TClient, msg:Discord.Message){
|
||||||
if (!client.config.botSwitches.logs) return;
|
if (!client.config.botSwitches.logs) return;
|
||||||
@ -9,7 +9,7 @@ export default {
|
|||||||
if (msg.guild?.id != client.config.mainServer.id || msg.partial || msg.author.bot || disabledChannels.includes(msg.channelId)) return;
|
if (msg.guild?.id != client.config.mainServer.id || msg.partial || msg.author.bot || disabledChannels.includes(msg.channelId)) return;
|
||||||
if (Discord.DiscordAPIError.name === '10008') return Logger.forwardToConsole('log', 'MsgDelete', 'Caught an unexpected error returned by Discord API. (Unknown Message)');
|
if (Discord.DiscordAPIError.name === '10008') return Logger.forwardToConsole('log', 'MsgDelete', 'Caught an unexpected error returned by Discord API. (Unknown Message)');
|
||||||
const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setAuthor({name: `Author: ${msg.author.username} (${msg.author.id})`, iconURL: `${msg.author.displayAvatarURL()}`}).setTitle('Message deleted').setDescription(`<@${msg.author.id}>\n\`${msg.author.id}\``);
|
const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setAuthor({name: `Author: ${msg.author.username} (${msg.author.id})`, iconURL: `${msg.author.displayAvatarURL()}`}).setTitle('Message deleted').setDescription(`<@${msg.author.id}>\n\`${msg.author.id}\``);
|
||||||
if (msg.content.length != 0) embed.addFields({name: 'Content', value: `\`\`\`\n${msg.content.slice(0,1000)}\n\`\`\``});
|
if (msg.content.length != 0) embed.addFields({name: 'Content', value: `\`\`\`\n${escapeCodeBlock(msg.content.slice(0,1000))}\n\`\`\``});
|
||||||
embed.addFields(
|
embed.addFields(
|
||||||
{ name: 'Channel', value: `<#${msg.channelId}>` },
|
{ name: 'Channel', value: `<#${msg.channelId}>` },
|
||||||
{ name: 'Sent at', value: `<t:${Math.round(msg.createdTimestamp/1000)}>\n<t:${Math.round(msg.createdTimestamp/1000)}:R>` }
|
{ name: 'Sent at', value: `<t:${Math.round(msg.createdTimestamp/1000)}>\n<t:${Math.round(msg.createdTimestamp/1000)}:R>` }
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
|
import {escapeCodeBlock} from 'discord.js';
|
||||||
export default {
|
export default {
|
||||||
async run(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message){
|
async run(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message){
|
||||||
if (!client.config.botSwitches.logs) return;
|
if (!client.config.botSwitches.logs) return;
|
||||||
if (oldMsg.guild?.id != client.config.mainServer.id || oldMsg.author === null || oldMsg?.author.bot || oldMsg.partial || newMsg.partial || !newMsg.member || ['548032776830582794', '541677709487505408', '949380187668242483'].includes(newMsg.channelId)) return;
|
if (oldMsg.guild?.id != client.config.mainServer.id || oldMsg.author === null || oldMsg?.author.bot || oldMsg.partial || newMsg.partial || !newMsg.member || ['548032776830582794', '541677709487505408', '949380187668242483'].includes(newMsg.channelId)) return;
|
||||||
if (await client.bannedWords._content.findOne({_id:newMsg.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' ')}) && (!client.isStaff(newMsg.member))) newMsg.delete();
|
if (await client.bannedWords._content.findOne({_id:newMsg.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' ')}) && (!client.isStaff(newMsg.member))) newMsg.delete();
|
||||||
if (newMsg.content === oldMsg.content) return;
|
if (newMsg.content === oldMsg.content) return;
|
||||||
(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setTimestamp().setAuthor({name: `Author: ${oldMsg.author.username} (${oldMsg.author.id})`, iconURL: `${oldMsg.author.displayAvatarURL()}`}).setTitle('Message edited').setDescription(`<@${oldMsg.author.id}>\nOld content:\n\`\`\`\n${oldMsg.content.length < 1 ? '(Attachment)' : oldMsg.content}\n\`\`\`\nNew content:\n\`\`\`\n${newMsg.content}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents(new Discord.ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]});
|
(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setTimestamp().setAuthor({name: `Author: ${oldMsg.author.username} (${oldMsg.author.id})`, iconURL: `${oldMsg.author.displayAvatarURL()}`}).setTitle('Message edited').setDescription(`<@${oldMsg.author.id}>\nOld content:\n\`\`\`\n${oldMsg.content.length < 1 ? '(Attachment)' : escapeCodeBlock(oldMsg.content.slice(0,2048))}\n\`\`\`\nNew content:\n\`\`\`\n${escapeCodeBlock(newMsg.content.slice(0,2048))}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents(new Discord.ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export default class Automoderator {
|
|||||||
client.repeatedMessages[message.author.id].timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime);
|
client.repeatedMessages[message.author.id].timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime);
|
||||||
|
|
||||||
// Message sent after (now - threshold), so purge those that were sent earlier
|
// Message sent after (now - threshold), so purge those that were sent earlier
|
||||||
client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x,i)=>i>=Date.now() - thresholdTime);
|
client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((_,i)=>i >= Date.now() - thresholdTime);
|
||||||
|
|
||||||
// A spammed message is one that has been sent within the threshold parameters
|
// A spammed message is one that has been sent within the threshold parameters
|
||||||
const spammedMessage = client.repeatedMessages[message.author.id].data.find(x=>{
|
const spammedMessage = client.repeatedMessages[message.author.id].data.find(x=>{
|
||||||
|
@ -10,14 +10,12 @@ import {writeFileSync, readFileSync} from 'node:fs';
|
|||||||
import {FSPlayer, FSData, FSCareerSavegame} from '../typings/interfaces';
|
import {FSPlayer, FSData, FSCareerSavegame} from '../typings/interfaces';
|
||||||
|
|
||||||
export default async(client:TClient, Channel:string, Message:string, Server:TServer, ServerName:string)=>{
|
export default async(client:TClient, Channel:string, Message:string, Server:TServer, ServerName:string)=>{
|
||||||
let isServerOnline = false;
|
|
||||||
let playerData:Array<string> = [];
|
let playerData:Array<string> = [];
|
||||||
const msg = await (client.channels.resolve(Channel) as Discord.TextChannel).messages.fetch(Message);
|
const msg = await (client.channels.resolve(Channel) as Discord.TextChannel).messages.fetch(Message);
|
||||||
const serverErrorEmbed = new client.embed().setColor(client.config.embedColorRed).setTitle('Host did not respond back in time');
|
const serverErrorEmbed = new client.embed().setColor(client.config.embedColorRed).setTitle('Host did not respond back in time');
|
||||||
const genericEmbed = new client.embed();
|
const genericEmbed = new client.embed();
|
||||||
|
let sessionInit = {signal: AbortSignal.timeout(8500),headers:{'User-Agent':'Daggerbot - HITALL/undici'}};
|
||||||
|
|
||||||
const HITALL = async()=>{
|
|
||||||
let sessionInit = {signal: AbortSignal.timeout(8200),headers:{'User-Agent':'Daggerbot - HITALL/undici'}};
|
|
||||||
try {
|
try {
|
||||||
const hitDSS = await fetch(Server.ip+'/feed/dedicated-server-stats.json?code='+Server.code, sessionInit).then(r=>r.json() as Promise<FSData>);
|
const hitDSS = await fetch(Server.ip+'/feed/dedicated-server-stats.json?code='+Server.code, sessionInit).then(r=>r.json() as Promise<FSData>);
|
||||||
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
const hitCSG = await fetch(Server.ip+'/feed/dedicated-server-savegame.html?code='+Server.code+'&file=careerSavegame', sessionInit).then(async r=>(client.xjs.xml2js(await r.text(), {compact: true}) as any).careerSavegame as FSCareerSavegame);
|
||||||
@ -73,7 +71,6 @@ export default async(client:TClient, Channel:string, Message:string, Server:TSer
|
|||||||
msg.edit({content: 'This embed will resume when server is back online.', embeds: [genericEmbed.setColor(client.config.embedColorRed).setTitle('The server seems to be offline.')]});
|
msg.edit({content: 'This embed will resume when server is back online.', embeds: [genericEmbed.setColor(client.config.embedColorRed).setTitle('The server seems to be offline.')]});
|
||||||
client.MPServerCache[ServerName].status = 'offline'
|
client.MPServerCache[ServerName].status = 'offline'
|
||||||
} else {
|
} else {
|
||||||
isServerOnline = true;
|
|
||||||
client.MPServerCache[ServerName].status = 'online';
|
client.MPServerCache[ServerName].status = 'online';
|
||||||
const serverDetails = new client.embed().setColor(client.config.embedColor).setTitle('Server details').setFields(
|
const serverDetails = new client.embed().setColor(client.config.embedColor).setTitle('Server details').setFields(
|
||||||
{name: 'Current map', value: hitDSS.server.mapName, inline: true},
|
{name: 'Current map', value: hitDSS.server.mapName, inline: true},
|
||||||
@ -90,6 +87,4 @@ export default async(client:TClient, Channel:string, Message:string, Server:TSer
|
|||||||
msg.edit({content: err.message, embeds: [serverErrorEmbed]});
|
msg.edit({content: err.message, embeds: [serverErrorEmbed]});
|
||||||
Logger.forwardToConsole('log', 'MPModule', `Failed to make a request for ${ServerName}: ${err.message}`);
|
Logger.forwardToConsole('log', 'MPModule', `Failed to make a request for ${ServerName}: ${err.message}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
HITALL();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user