1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 04:10:59 -05:00
Daggerbot-TS/src/client.ts

78 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-12-24 10:21:40 -05:00
interface IRepeatedMessages {
[key:string]: {
type:string;
count:number;
firstTime:number;
timeout:NodeJS.Timeout;
}
2023-09-01 00:32:11 -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';
import {Config} from 'src/interfaces';
2023-12-24 10:21:40 -05:00
import {
DailyMsgsSvc, UserLevelsSvc, BonkCountSvc,
MPServerSvc, PunishmentsSvc, ProhibitedWordsSvc,
SuggestionsSvc, TagSystemSvc, YouTubeChannelsSvc
} from './models/IMPORTS.js';
import DatabaseServer from './components/DatabaseServer.js';
import CacheServer from './components/CacheServer.js';
import TSClient from './helpers/TSClient.js';
2023-01-06 19:41:20 -05:00
2023-08-30 04:34:59 -04:00
export default class TClient extends Discord.Client {
2023-12-24 10:21:40 -05:00
public invites: Map<any, any> = new Map();
public commands: Discord.Collection<string, any> = new Discord.Collection();
public registry: Discord.ApplicationCommandDataResolvable[] = [];
2023-12-24 10:21:40 -05:00
public config: Config;
public embed: typeof Discord.EmbedBuilder = Discord.EmbedBuilder;
public collection: typeof Discord.Collection = Discord.Collection;
public attachment: typeof Discord.AttachmentBuilder = Discord.AttachmentBuilder;
public dailyMsgs: DailyMsgsSvc = new DailyMsgsSvc();
public userLevels: UserLevelsSvc = new UserLevelsSvc(this);
public punishments: PunishmentsSvc = new PunishmentsSvc(this);
public bonkCount: BonkCountSvc = new BonkCountSvc();
public prohibitedWords: ProhibitedWordsSvc = new ProhibitedWordsSvc();
public MPServer: MPServerSvc = new MPServerSvc();
public suggestions: SuggestionsSvc = new SuggestionsSvc();
public tags: TagSystemSvc = new TagSystemSvc();
public ytChannels: YouTubeChannelsSvc = new YouTubeChannelsSvc();
public repeatedMessages: IRepeatedMessages = {};
2022-11-11 19:58:11 -05:00
2023-12-24 10:21:40 -05:00
constructor() {
2023-03-05 05:04:10 -05:00
super({
intents: [
2023-08-30 04:34:59 -04:00
Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildModeration, Discord.GatewayIntentBits.GuildInvites,
2023-12-26 17:49:07 -05:00
Discord.GatewayIntentBits.GuildPresences, Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.DirectMessages
], partials: [
2023-12-26 17:49:07 -05:00
Discord.Partials.Channel, Discord.Partials.Message
2023-12-24 10:21:40 -05:00
], allowedMentions: {users:[], roles:[]}
2023-03-05 05:04:10 -05:00
})
2023-12-24 10:21:40 -05:00
this.config = ConfigHelper.loadConfig() as Config;
this.setMaxListeners(50);
2023-03-05 05:04:10 -05:00
}
2023-12-24 10:21:40 -05:00
async init() {
2023-03-05 05:04:10 -05:00
console.time('Startup');
2023-10-06 01:54:27 -04:00
2023-12-24 10:21:40 -05:00
const eventFiles = await Promise.all(readdirSync('dist/events').map(file=>import(`./events/${file}`)));
2023-10-06 01:54:27 -04:00
eventFiles.forEach((eventFile, index)=>{
const eventName = readdirSync('dist/events')[index].replace('.js', '');
this.on(eventName, async(...args)=>eventFile.default.run(this, ...args));
});
2023-12-24 10:21:40 -05:00
const commandFiles = await Promise.all(readdirSync('dist/commands').map(file=>import(`./commands/${file}`)));
2023-10-06 01:54:27 -04:00
commandFiles.forEach(commandFile=>{
const {default: command} = commandFile;
this.commands.set(command.data.name, {command, uses: 0});
this.registry.push(command.data.toJSON());
});
2023-12-24 10:21:40 -05:00
await Promise.all([
CacheServer.init(),
DatabaseServer.init(),
this.login((await TSClient()).main)
]);
2023-03-05 05:04:10 -05:00
}
}