mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-12-28 08:55:38 -05:00
Bot improvements
This commit is contained in:
parent
c37bffe8a9
commit
e3c025ad12
@ -23,7 +23,7 @@ import CacheServer from './funcs/CacheServer.js';
|
|||||||
import fxp from 'fast-xml-parser';
|
import fxp from 'fast-xml-parser';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import TSClient from './helpers/TSClient.js';
|
import TSClient from './helpers/TSClient.js';
|
||||||
const importconfig = ConfigHelper.loadConfig(process.argv[2] ?? 'src/config.json');
|
const importconfig = ConfigHelper.loadConfig();
|
||||||
|
|
||||||
export default class TClient extends Discord.Client {
|
export default class TClient extends Discord.Client {
|
||||||
invites: Map<any, any>;
|
invites: Map<any, any>;
|
||||||
|
@ -11,21 +11,20 @@ export default {
|
|||||||
if (!message.inGuild()) return (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({content: `<:fish_unamused:1083675172407623711> ${MessageTool.formatMention(client.config.whitelist[0], 'user')}\n**${message.author.username}** tried to send me a DM, their message is:\`\`\`${message.content}\`\`\``, allowedMentions: {parse: ['users']}});
|
if (!message.inGuild()) return (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({content: `<:fish_unamused:1083675172407623711> ${MessageTool.formatMention(client.config.whitelist[0], 'user')}\n**${message.author.username}** tried to send me a DM, their message is:\`\`\`${message.content}\`\`\``, allowedMentions: {parse: ['users']}});
|
||||||
let automodded: boolean;
|
let automodded: boolean;
|
||||||
|
|
||||||
if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.mainServer.roles.admin) && message.guildId == client.config.mainServer.id){
|
if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.mainServer.roles.admin) && message.guildId === client.config.mainServer.id){
|
||||||
const automodFailReason = 'msg got possibly deleted by another bot.';
|
const automodFailReason = 'msg got possibly deleted by another bot.';
|
||||||
if (await client.bannedWords._content.findById(Automoderator.scanMsg(message))/* && !Whitelist.includes(message.channelId) */){
|
if (await client.bannedWords._content.findById(Automoderator.scanMsg(message))/* && !Whitelist.includes(message.channelId) */){
|
||||||
automodded = true;
|
automodded = true;
|
||||||
message.delete().catch(()=>Logger.forwardToConsole('log', 'AUTOMOD-BANNEDWORDS', automodFailReason));
|
message.delete().catch(()=>Logger.forwardToConsole('log', 'AUTOMOD-BANNEDWORDS', 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));
|
||||||
await Automoderator.repeatedMessages(client, message, 30000, 3, 'bw', '30m', 'Constant swearing');
|
await Automoderator.repeatedMessages(client, message, 30000, 3, 'bw', '30m', 'Constant swears');
|
||||||
} else if (message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember)){
|
} else if (message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember)){
|
||||||
const url = message.content.split(' ').find(x=>x.includes('discord.gg/'));
|
const validInvite = await client.fetchInvite(message.content.split(' ').find(x=>x.includes('discord.gg/'))).catch(()=>null);
|
||||||
const validInvite = await client.fetchInvite(url).catch(()=>undefined);
|
|
||||||
if (validInvite && validInvite.guild?.id !== client.config.mainServer.id){
|
if (validInvite && validInvite.guild?.id !== client.config.mainServer.id){
|
||||||
automodded = true;
|
automodded = true;
|
||||||
message.delete().catch(()=>Logger.forwardToConsole('log', 'AUTOMOD-ADVERT', automodFailReason));
|
message.delete().catch(()=>Logger.forwardToConsole('log', 'AUTOMOD-ADVERT', automodFailReason));
|
||||||
message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000));
|
message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000));
|
||||||
await Automoderator.repeatedMessages(client, message, 60000, 2, 'adv', '1h', 'Discord advertisement');
|
await Automoderator.repeatedMessages(client, message, 60000, 2, 'adv', '1h', 'Discord Advertisement');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,9 +54,8 @@ export default {
|
|||||||
Response.create(client, message, GeneralChatID, 'evening');
|
Response.create(client, message, GeneralChatID, 'evening');
|
||||||
Response.create(client, message, GeneralChatID, 'night');
|
Response.create(client, message, GeneralChatID, 'night');
|
||||||
|
|
||||||
CmdTrigger.registerCmds(client, message, '!!_wepanikfrfr');
|
CmdTrigger.registerCmds(client, message, 'wepanikfrfr');
|
||||||
CmdTrigger.MFPwTrigger(message, '!!_farmpw');
|
CmdTrigger.MFPwTrigger(message, 'farmpw');
|
||||||
CmdTrigger.TriggerTest(message, '!!_test-trigger');
|
|
||||||
|
|
||||||
if (message.type === 8 && message.channelId === GeneralChatID) message.channel.send({content: outgoingArrays.guildBoost[Math.floor(Math.random() * outgoingArrays.guildBoost.length)], allowedMentions: {parse: ['users']}})
|
if (message.type === 8 && message.channelId === GeneralChatID) message.channel.send({content: outgoingArrays.guildBoost[Math.floor(Math.random() * outgoingArrays.guildBoost.length)], allowedMentions: {parse: ['users']}})
|
||||||
if (message.mentions.members.has('309373272594579456') && !MessageTool.isStaff(message.member)) message.reply('Please don\'t tag Daggerwin, read rule 14 in <#468846117405196289>');
|
if (message.mentions.members.has('309373272594579456') && !MessageTool.isStaff(message.member)) message.reply('Please don\'t tag Daggerwin, read rule 14 in <#468846117405196289>');
|
||||||
|
@ -2,8 +2,9 @@ import Discord from 'discord.js';
|
|||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
|
|
||||||
export default class CmdTrigger {
|
export default class CmdTrigger {
|
||||||
protected static SenseTrigger(message:Discord.Message, trigger:string) {
|
private static readonly prefix = '!!_';
|
||||||
return message.content.toLowerCase().startsWith(trigger)
|
private static SenseTrigger(message:Discord.Message, trigger:string): boolean {
|
||||||
|
return message.content.toLowerCase().startsWith(this.prefix+trigger)
|
||||||
}
|
}
|
||||||
static registerCmds(client:TClient, message:Discord.Message, trigger:string) {
|
static registerCmds(client:TClient, message:Discord.Message, trigger:string) {
|
||||||
if (this.SenseTrigger(message, trigger) && client.config.whitelist.includes(message.author.id)) {
|
if (this.SenseTrigger(message, trigger) && client.config.whitelist.includes(message.author.id)) {
|
||||||
@ -19,7 +20,4 @@ export default class CmdTrigger {
|
|||||||
else if (message.channelId === '1149138202662293555') return message.reply(farmPwText += '`eastfarm`')
|
else if (message.channelId === '1149138202662293555') return message.reply(farmPwText += '`eastfarm`')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static TriggerTest(message:Discord.Message, trigger:string) {
|
|
||||||
if (this.SenseTrigger(message, trigger)) return message.reply('Triggered!')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import {Config} from '../typings/interfaces';
|
import ConfigHelper from '../helpers/ConfigHelper.js';
|
||||||
import {readFileSync} from 'node:fs';
|
const config = ConfigHelper.readConfig();
|
||||||
const config:Config = JSON.parse(readFileSync('src/config.json', 'utf-8'));
|
|
||||||
type ChannelList = keyof typeof config.mainServer.channels;
|
type ChannelList = keyof typeof config.mainServer.channels;
|
||||||
export default class HookMgr {
|
export default class HookMgr {
|
||||||
protected static async channelFetch(client:TClient, channel:ChannelList) {
|
protected static async channelFetch(client:TClient, channel:ChannelList) {
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
import {readFileSync} from 'node:fs';
|
import {readFileSync} from 'node:fs';
|
||||||
import {Config} from '../typings/interfaces';
|
import {Config} from '../typings/interfaces';
|
||||||
export default class ConfigHelper {
|
export default class ConfigHelper {
|
||||||
static loadConfig(configFile:string) {
|
static loadConfig() {
|
||||||
let importconfig:Config;
|
let importconfig:Config;
|
||||||
try {
|
try {
|
||||||
importconfig = JSON.parse(readFileSync(configFile, 'utf8'));
|
importconfig = JSON.parse(readFileSync(process.argv[2] ?? 'src/config.json', 'utf8'));
|
||||||
console.log(`Loaded the config :: ${importconfig.configName}`);
|
console.log(`Loaded the config :: ${importconfig.configName}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Error loading config file "${configFile}": ${e}`);
|
console.error(`Error loading config file "${process.argv[2] ?? 'src/config.json'}": ${e}`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
return importconfig;
|
return importconfig;
|
||||||
}
|
}
|
||||||
|
static readConfig() {
|
||||||
|
return JSON.parse(readFileSync(process.argv[2] ?? 'src/config.json', 'utf8')) as Config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import MessageTool from './MessageTool.js';
|
import MessageTool from './MessageTool.js';
|
||||||
import {Config} from 'src/typings/interfaces';
|
import ConfigHelper from './ConfigHelper.js';
|
||||||
import {readFileSync} from 'node:fs';
|
const config = ConfigHelper.readConfig();
|
||||||
const config:Config = JSON.parse(readFileSync('src/config.json', 'utf8'));
|
|
||||||
export default class FAQStore {
|
export default class FAQStore {
|
||||||
protected static readonly errorMsg:string = 'Failed to send the message, please report to **Toast** if it continues.';
|
protected static readonly errorMsg:string = 'Failed to send the message, please report to **Toast** if it continues.';
|
||||||
static async reply(interaction:Discord.ChatInputCommandInteraction, title:string|null, message:string, image:string|null, useEmbed:boolean=false) {
|
static async reply(interaction:Discord.ChatInputCommandInteraction, title:string|null, message:string, image:string|null, useEmbed:boolean=false) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import {readFileSync} from 'node:fs';
|
import ConfigHelper from './ConfigHelper.js';
|
||||||
import {Config} from 'src/typings/interfaces';
|
const config = ConfigHelper.readConfig();
|
||||||
const config:Config = JSON.parse(readFileSync('src/config.json', 'utf8'));
|
|
||||||
type RoleKeys = keyof typeof config.mainServer.roles;
|
type RoleKeys = keyof typeof config.mainServer.roles;
|
||||||
|
|
||||||
export default class MessageTool {
|
export default class MessageTool {
|
||||||
|
@ -1,18 +1,6 @@
|
|||||||
export default class UsernameHelper {
|
export default class UsernameHelper {
|
||||||
static stripName(text: string){
|
static stripName(text: string){
|
||||||
let matchesLeft = true;
|
|
||||||
const dirSlash = process.platform === 'linux' ? '\/' : '\\';
|
const dirSlash = process.platform === 'linux' ? '\/' : '\\';
|
||||||
const array = text.split(dirSlash);
|
return text.replace(/(?<=\/Users\/|\/media\/)[^/]+/g, match=>'・'.repeat(match.length)).split(dirSlash).join(dirSlash);
|
||||||
while (matchesLeft) {
|
|
||||||
let usersIndex = array.indexOf(process.platform === 'linux' ? 'media' : 'Users');
|
|
||||||
if (usersIndex < 1) matchesLeft = false;
|
|
||||||
else {
|
|
||||||
let usernameIndex = usersIndex + 1;
|
|
||||||
if (array[usernameIndex].length === 0) usernameIndex += 1;
|
|
||||||
array[usernameIndex] = '・'.repeat(array[usernameIndex].length);
|
|
||||||
array[usersIndex] = process.platform === 'linux' ? 'med\u200bia' : 'Us\u200bers';
|
|
||||||
}
|
|
||||||
return array.join(dirSlash);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,15 @@ client.init();
|
|||||||
import Logger from './helpers/Logger.js';
|
import Logger from './helpers/Logger.js';
|
||||||
import YTModule from './funcs/YTModule.js';
|
import YTModule from './funcs/YTModule.js';
|
||||||
import MPModule from './funcs/MPModule.js';
|
import MPModule from './funcs/MPModule.js';
|
||||||
|
import UsernameHelper from './helpers/UsernameHelper.js';
|
||||||
import {Punishment} from './typings/interfaces';
|
import {Punishment} from './typings/interfaces';
|
||||||
import {writeFileSync, readFileSync} from 'node:fs';
|
import {writeFileSync, readFileSync} from 'node:fs';
|
||||||
|
|
||||||
// Error handler
|
// Error handler
|
||||||
function DZ(error:Error, type:string){// Yes, I may have shiternet but I don't need to wake up to like a hundred messages or so.
|
function DZ(error:Error, type:string){// Yes, I may have shiternet but I don't need to wake up to like a hundred messages or so.
|
||||||
if (JSON.parse(readFileSync('src/errorBlocklist.json', 'utf8')).includes(error.message)) return;// I wonder if my idea works, if not then please run me over with a bulldozer.
|
if (JSON.parse(readFileSync('src/errorBlocklist.json', 'utf8')).includes(error.message)) return;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel | null)?.send({embeds: [new client.embed().setColor('#560000').setTitle('Error caught!').setFooter({text: 'Error type: ' + type}).setDescription(`**Error:**\n\`\`\`${error.message}\`\`\`**Stack:**\n\`\`\`${`${error.stack}`.slice(0, 2500)}\`\`\``)]})
|
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel | null)?.send({embeds: [new client.embed().setColor('#560000').setTitle('Error caught!').setFooter({text: 'Error type: ' + type}).setDescription(`**Error:**\n\`\`\`${error.message}\`\`\`**Stack:**\n\`\`\`${`${UsernameHelper.stripName(error.stack)}`.slice(0, 2500)}\`\`\``)]})
|
||||||
}
|
}
|
||||||
process.on('unhandledRejection', (error: Error)=>DZ(error, 'unhandledRejection'));
|
process.on('unhandledRejection', (error: Error)=>DZ(error, 'unhandledRejection'));
|
||||||
process.on('uncaughtException', (error: Error)=>DZ(error, 'uncaughtException'));
|
process.on('uncaughtException', (error: Error)=>DZ(error, 'uncaughtException'));
|
||||||
|
@ -18,5 +18,5 @@
|
|||||||
"typeRoots": [ "./src/typings" ]
|
"typeRoots": [ "./src/typings" ]
|
||||||
},
|
},
|
||||||
"include": [ "src/" ],
|
"include": [ "src/" ],
|
||||||
"exclude": [ ".yarn/cache", ".yarn/unplugged", ".git", "src/errorBlocklist.json", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ]
|
"exclude": [ ".yarn/cache", ".yarn/unplugged", ".git", "src/errorBlocklist.json", "src/config.json", "src/DB-Beta.config.json" ]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user