2023-09-01 00:32:11 -04:00
|
|
|
interface repeatedMessages {
|
|
|
|
[key: string]: {data: Discord.Collection<number,{type:string,channel:string}>,timeout: NodeJS.Timeout}
|
|
|
|
}
|
|
|
|
type MPServerCache = Record<string,{
|
|
|
|
players: FSPlayer[],
|
|
|
|
status: 'online' | 'offline' | null,
|
|
|
|
name: string | null
|
|
|
|
}>
|
2023-10-04 21:01:36 -04:00
|
|
|
|
2023-08-30 04:34:59 -04:00
|
|
|
import Discord from 'discord.js';
|
2023-10-07 17:01:16 -04:00
|
|
|
import ConfigHelper from './helpers/ConfigHelper.js';
|
|
|
|
import {readdirSync} from 'node:fs';
|
2023-10-04 21:01:36 -04:00
|
|
|
import {Config, FSPlayer} from './typings/interfaces';
|
2023-04-14 06:47:58 -04:00
|
|
|
import bannedWords from './models/bannedWords.js';
|
|
|
|
import userLevels from './models/userLevels.js';
|
|
|
|
import suggestion from './models/suggestion.js';
|
|
|
|
import punishments from './models/punishments.js';
|
2023-08-14 10:36:29 -04:00
|
|
|
import tags from './models/tagSystem.js';
|
2023-04-14 06:47:58 -04:00
|
|
|
import bonkCount from './models/bonkCount.js';
|
|
|
|
import MPServer from './models/MPServer.js';
|
2023-08-26 11:03:14 -04:00
|
|
|
import DatabaseServer from './funcs/DatabaseServer.js';
|
2023-10-02 18:40:03 -04:00
|
|
|
import CacheServer from './funcs/CacheServer.js';
|
2023-10-07 17:01:16 -04:00
|
|
|
import fxp from 'fast-xml-parser';
|
|
|
|
import dayjs from 'dayjs';
|
2023-10-04 21:01:36 -04:00
|
|
|
import TSClient from './helpers/TSClient.js';
|
2023-10-07 17:01:16 -04:00
|
|
|
const importconfig = ConfigHelper.loadConfig(process.argv[2] ?? 'src/config.json');
|
2023-01-06 19:41:20 -05:00
|
|
|
|
2023-08-30 04:34:59 -04:00
|
|
|
export default class TClient extends Discord.Client {
|
2023-03-05 05:04:10 -05:00
|
|
|
invites: Map<any, any>;
|
|
|
|
commands: Discord.Collection<string, any>;
|
|
|
|
registry: Array<Discord.ApplicationCommandDataResolvable>;
|
|
|
|
config: Config;
|
|
|
|
embed: typeof Discord.EmbedBuilder;
|
2023-09-01 00:32:11 -04:00
|
|
|
collection: typeof Discord.Collection;
|
|
|
|
attachmentBuilder: typeof Discord.AttachmentBuilder;
|
2023-10-07 17:01:16 -04:00
|
|
|
dayjs: typeof dayjs;
|
|
|
|
fxp: typeof fxp;
|
2023-03-05 05:04:10 -05:00
|
|
|
userLevels: userLevels;
|
|
|
|
punishments: punishments;
|
|
|
|
bonkCount: bonkCount;
|
|
|
|
bannedWords: bannedWords;
|
|
|
|
MPServer: MPServer;
|
2023-08-19 08:50:05 -04:00
|
|
|
MPServerCache: MPServerCache = {};
|
2023-03-05 05:04:10 -05:00
|
|
|
suggestion: suggestion;
|
2023-08-14 10:36:29 -04:00
|
|
|
tags: tags;
|
2023-03-05 05:04:10 -05:00
|
|
|
repeatedMessages: repeatedMessages;
|
|
|
|
statsGraph: number;
|
2022-11-11 19:58:11 -05:00
|
|
|
|
2023-03-05 05:04:10 -05:00
|
|
|
constructor(){
|
|
|
|
super({
|
|
|
|
intents: [
|
2023-08-30 04:34:59 -04:00
|
|
|
Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers,
|
|
|
|
Discord.GatewayIntentBits.GuildModeration, Discord.GatewayIntentBits.GuildInvites,
|
|
|
|
Discord.GatewayIntentBits.GuildMessageReactions, Discord.GatewayIntentBits.GuildPresences,
|
|
|
|
Discord.GatewayIntentBits.MessageContent, Discord.GatewayIntentBits.GuildMessages,
|
2023-10-08 06:10:03 -04:00
|
|
|
Discord.GatewayIntentBits.DirectMessages
|
2023-04-24 07:04:32 -04:00
|
|
|
], partials: [
|
2023-08-30 04:34:59 -04:00
|
|
|
Discord.Partials.Channel, Discord.Partials.Reaction, Discord.Partials.Message
|
2023-04-24 07:04:32 -04:00
|
|
|
], allowedMentions: {users:[],roles:[]}
|
2023-03-05 05:04:10 -05:00
|
|
|
})
|
|
|
|
this.invites = new Map();
|
|
|
|
this.commands = new Discord.Collection();
|
|
|
|
this.registry = [];
|
|
|
|
this.config = importconfig as Config;
|
|
|
|
this.embed = Discord.EmbedBuilder;
|
|
|
|
this.collection = Discord.Collection;
|
|
|
|
this.attachmentBuilder = Discord.AttachmentBuilder;
|
2023-10-07 17:01:16 -04:00
|
|
|
this.dayjs = dayjs;
|
|
|
|
this.fxp = fxp;
|
2023-03-05 05:04:10 -05:00
|
|
|
this.userLevels = new userLevels(this);
|
|
|
|
this.bonkCount = new bonkCount(this);
|
|
|
|
this.punishments = new punishments(this);
|
|
|
|
this.bannedWords = new bannedWords(this);
|
|
|
|
this.MPServer = new MPServer(this);
|
2023-08-19 08:50:05 -04:00
|
|
|
this.MPServerCache = {} as MPServerCache;
|
2023-03-05 05:04:10 -05:00
|
|
|
this.suggestion = new suggestion(this);
|
2023-08-14 10:36:29 -04:00
|
|
|
this.tags = new tags(this);
|
2023-03-05 05:04:10 -05:00
|
|
|
this.repeatedMessages = {};
|
2023-09-01 00:32:11 -04:00
|
|
|
this.setMaxListeners(62);
|
2023-08-19 21:04:14 -04:00
|
|
|
this.statsGraph = -120;
|
2023-03-05 05:04:10 -05:00
|
|
|
}
|
|
|
|
async init(){
|
|
|
|
console.time('Startup');
|
2023-10-06 01:54:27 -04:00
|
|
|
await Promise.all([
|
|
|
|
CacheServer.init(),
|
|
|
|
DatabaseServer.init(),
|
|
|
|
this.login((await TSClient.Token()).main)
|
|
|
|
]);
|
|
|
|
|
|
|
|
const eventFiles = await Promise.all(
|
|
|
|
readdirSync('dist/events').map(file=>import(`./events/${file}`))
|
|
|
|
);
|
|
|
|
eventFiles.forEach((eventFile, index)=>{
|
|
|
|
const eventName = readdirSync('dist/events')[index].replace('.js', '');
|
|
|
|
this.on(eventName, async(...args)=>eventFile.default.run(this, ...args));
|
|
|
|
});
|
|
|
|
|
|
|
|
const commandFiles = await Promise.all(
|
|
|
|
readdirSync('dist/commands').map(file=>import(`./commands/${file}`))
|
|
|
|
);
|
|
|
|
commandFiles.forEach(commandFile=>{
|
|
|
|
const {default: command} = commandFile;
|
|
|
|
this.commands.set(command.data.name, {command, uses: 0});
|
|
|
|
this.registry.push(command.data.toJSON());
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(this.config.MPStatsLocation).forEach(naming=>{
|
2023-08-19 08:50:05 -04:00
|
|
|
this.MPServerCache[naming] = {
|
|
|
|
players: [],
|
|
|
|
status: null,
|
|
|
|
name: null
|
|
|
|
}
|
2023-10-06 01:54:27 -04:00
|
|
|
});
|
2023-03-05 05:04:10 -05:00
|
|
|
}
|
2022-11-14 03:45:40 -05:00
|
|
|
}
|