1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-18 00:31:00 -05:00
Daggerbot-TS/src/client.ts

114 lines
4.4 KiB
TypeScript
Raw Normal View History

2023-08-30 04:34:59 -04:00
import Discord from 'discord.js';
2023-08-14 10:36:29 -04:00
import {readFileSync, readdirSync} from 'node:fs';
2023-08-30 04:34:59 -04:00
import {Tokens, Config, repeatedMessages, type MPServerCache} 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';
import DatabaseServer from './funcs/DatabaseServer.js';
2023-04-14 06:47:58 -04:00
import xjs from 'xml-js';
2022-12-18 23:22:28 -05:00
import moment from 'moment';
2023-08-24 12:06:39 -04:00
const tokens = JSON.parse(readFileSync('src/tokens.json', 'utf8'));
2023-07-20 08:13:09 -04:00
// Import assertion warning workaround yes
2023-01-06 19:41:20 -05:00
let importconfig:Config
try{
2023-08-24 12:06:39 -04:00
importconfig = JSON.parse(readFileSync('src/DB-Beta.config.json', 'utf8'));
2023-03-05 05:04:10 -05:00
console.log('Using development config :: Daggerbot Beta')
2023-01-06 19:41:20 -05:00
} catch(e){
2023-08-24 12:06:39 -04:00
importconfig = JSON.parse(readFileSync('src/config.json', 'utf8'))
2023-03-05 05:04:10 -05:00
console.log('Using production config')
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;
tokens: Tokens;
YTCache: any;
embed: typeof Discord.EmbedBuilder;
collection: any;
messageCollector: any;
attachmentBuilder: any;
moment: typeof moment;
2023-04-14 06:47:58 -04:00
xjs: typeof xjs;
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,
Discord.GatewayIntentBits.GuildVoiceStates, Discord.GatewayIntentBits.DirectMessages
], partials: [
2023-08-30 04:34:59 -04:00
Discord.Partials.Channel, Discord.Partials.Reaction, Discord.Partials.Message
], 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.tokens = tokens as Tokens;
this.YTCache = {
'UCQ8k8yTDLITldfWYKDs3xFg': undefined, // Daggerwin
'UCguI73--UraJpso4NizXNzA': undefined // Machinery Restorer
2022-11-11 19:58:11 -05:00
}
2023-03-05 05:04:10 -05:00
this.embed = Discord.EmbedBuilder;
this.collection = Discord.Collection;
this.messageCollector = Discord.MessageCollector;
this.attachmentBuilder = Discord.AttachmentBuilder;
this.moment = moment;
2023-04-14 06:47:58 -04:00
this.xjs = xjs;
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 = {};
this.setMaxListeners(45);
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-08-24 12:06:39 -04:00
await DatabaseServer(this);
2023-08-19 20:17:22 -04:00
this.login(this.tokens.main);
2023-08-26 10:47:06 -04:00
for (const file of readdirSync('dist/events')){
2023-04-14 06:47:58 -04:00
const eventFile = await import(`./events/${file}`);
2023-04-21 02:20:01 -04:00
this.on(file.replace('.js',''), async(...args)=>eventFile.default.run(this,...args))
}
2023-08-26 10:47:06 -04:00
for (const file of readdirSync('dist/commands')){
2023-04-14 06:47:58 -04:00
const command = await import(`./commands/${file}`);
2023-04-21 02:20:01 -04:00
this.commands.set(command.default.data.name,{command, uses: 0});
2023-03-05 05:04:10 -05:00
this.registry.push(command.default.data.toJSON())
}
2023-08-19 08:50:05 -04:00
for (const naming of Object.keys(this.config.MPStatsLocation)){
this.MPServerCache[naming] = {
players: [],
status: null,
name: null
}
}
2023-03-05 05:04:10 -05:00
}
isStaff = (guildMember:Discord.GuildMember)=>this.config.mainServer.staffRoles.map((x: string)=>this.config.mainServer.roles[x]).some((x: string)=>guildMember.roles.cache.has(x));
youNeedRole = (interaction:Discord.CommandInteraction, role:string)=>interaction.reply(`This command is restricted to <@&${this.config.mainServer.roles[role]}>`);
logTime = ()=>`[${this.moment().format('DD/MM/YY HH:mm:ss')}]`;
}