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

Compare commits

..

2 Commits

Author SHA1 Message Date
AnxietyisReal
4067eac730 Move dedicated files to functions folder 2023-08-27 01:03:14 +10:00
AnxietyisReal
8cf15cc231 Rehome the ready event 2023-08-27 00:47:06 +10:00
6 changed files with 35 additions and 35 deletions

View File

@ -8,7 +8,7 @@ import punishments from './models/punishments.js';
import tags from './models/tagSystem.js'; import tags from './models/tagSystem.js';
import bonkCount from './models/bonkCount.js'; import bonkCount from './models/bonkCount.js';
import MPServer from './models/MPServer.js'; import MPServer from './models/MPServer.js';
import DatabaseServer from './DatabaseServer.js'; import DatabaseServer from './funcs/DatabaseServer.js';
import xjs from 'xml-js'; import xjs from 'xml-js';
import moment from 'moment'; import moment from 'moment';
const tokens = JSON.parse(readFileSync('src/tokens.json', 'utf8')); const tokens = JSON.parse(readFileSync('src/tokens.json', 'utf8'));
@ -92,11 +92,11 @@ export default class TClient extends Client {
console.time('Startup'); console.time('Startup');
await DatabaseServer(this); await DatabaseServer(this);
this.login(this.tokens.main); this.login(this.tokens.main);
for await (const file of readdirSync('dist/events')){ for (const file of readdirSync('dist/events')){
const eventFile = await import(`./events/${file}`); const eventFile = await import(`./events/${file}`);
this.on(file.replace('.js',''), async(...args)=>eventFile.default.run(this,...args)) this.on(file.replace('.js',''), async(...args)=>eventFile.default.run(this,...args))
} }
for await (const file of readdirSync('dist/commands')){ for (const file of readdirSync('dist/commands')){
const command = await import(`./commands/${file}`); const command = await import(`./commands/${file}`);
this.commands.set(command.default.data.name,{command, uses: 0}); this.commands.set(command.default.data.name,{command, uses: 0});
this.registry.push(command.default.data.toJSON()) this.registry.push(command.default.data.toJSON())

25
src/events/ready.ts Normal file
View File

@ -0,0 +1,25 @@
import Discord from 'discord.js';
import TClient from '../client.js';
export default {
async run(client:TClient){
await client.guilds.fetch(client.config.mainServer.id).then(async guild=>{
await guild.members.fetch();
setInterval(()=>{
client.user.setPresence(client.config.botPresence);
guild.invites.fetch().then(invites=>invites.forEach(inv=>client.invites.set(inv.code, {uses: inv.uses, creator: inv.inviterId, channel: inv.channel.name})))
},300000)
})
if (client.config.botSwitches.registerCommands){
console.log('Total commands: '+client.registry.length) //Debugging reasons.
client.config.whitelistedServers.forEach(guildId=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{
console.log(`Couldn't register slash commands for ${guildId} because`, e.stack);
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``)
}))
}
console.log(`${client.user.username} has logged into Discord API`);
console.log(client.config.botSwitches, client.config.whitelistedServers);
(client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send({content: `${client.user.username} is active`, embeds:[new client.embed().setColor(client.config.embedColor).setDescription(`\`\`\`json\n${Object.entries(client.config.botSwitches).map(x=>`${x[0]}: ${x[1]}`).join('\n')}\`\`\``)]});
console.timeEnd('Startup')
}
}

View File

@ -1,4 +1,4 @@
import TClient from './client'; import TClient from '../client';
import mongoose from 'mongoose'; import mongoose from 'mongoose';
export default async(client:TClient)=>{ export default async(client:TClient)=>{
@ -24,7 +24,7 @@ export default async(client:TClient)=>{
.on('disconnecting', ()=>console.log(client.logTime(), `${LogPrefix} Disconnecting from MongoDB`)) .on('disconnecting', ()=>console.log(client.logTime(), `${LogPrefix} Disconnecting from MongoDB`))
.on('disconnected', ()=>console.log(client.logTime(), `${LogPrefix} Disconnected from MongoDB`)) .on('disconnected', ()=>console.log(client.logTime(), `${LogPrefix} Disconnected from MongoDB`))
.on('close', ()=>console.log(client.logTime(), `${LogPrefix} MongoDB has closed the connection`)) .on('close', ()=>console.log(client.logTime(), `${LogPrefix} MongoDB has closed the connection`))
.on('reconnected', ()=>console.log(client.logTime(), `${LogPrefix} Re-establishing a connection to MongoDB`)) .on('reconnected', ()=>console.log(client.logTime(), `${LogPrefix} Connection to MongoDB has been re-established`))
.on('all', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to all members`)) .on('all', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to all members`))
.on('fullsetup', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to Primary server & atleast one member`)) .on('fullsetup', ()=>console.log(client.logTime(), `${LogPrefix} Successfully established a connection to Primary server & atleast one member`))
.on('error', ((err:mongoose.Error)=>console.error(client.logTime(), `${LogPrefix} Encountered an error in MongoDB: ${err.message}`))); .on('error', ((err:mongoose.Error)=>console.error(client.logTime(), `${LogPrefix} Encountered an error in MongoDB: ${err.message}`)));

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js'; import Discord from 'discord.js';
import TClient from './client'; import TClient from '../client';
import {writeFileSync, readFileSync} from 'node:fs'; import {writeFileSync, readFileSync} from 'node:fs';
import {FSPlayer, FSData, FSCareerSavegame, TServer} from './typings/interfaces'; import {FSPlayer, FSData, FSCareerSavegame, TServer} 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 MPLoopPrefix = '[MPLoop] '; let MPLoopPrefix = '[MPLoop] ';

View File

@ -2,32 +2,11 @@ import Discord from 'discord.js';
import TClient from './client.js'; import TClient from './client.js';
const client = new TClient; const client = new TClient;
client.init(); client.init();
import MPLoop from './MPLoop.js'; import MPLoop from './funcs/MPLoop.js';
import {Player} from 'discord-player'; import {Player} from 'discord-player';
const player = Player.singleton(client); const player = Player.singleton(client);
import {writeFileSync, readFileSync} from 'node:fs'; import {writeFileSync, readFileSync} from 'node:fs';
client.on('ready', async()=>{
await client.guilds.fetch(client.config.mainServer.id).then(async guild=>{
await guild.members.fetch();
setInterval(()=>{
client.user.setPresence(client.config.botPresence);
guild.invites.fetch().then(invites=>invites.forEach(inv=>client.invites.set(inv.code, {uses: inv.uses, creator: inv.inviterId, channel: inv.channel.name})))
},300000)
});
if (client.config.botSwitches.registerCommands){
console.log('Total commands: '+client.registry.length) //Debugging reasons.
client.config.whitelistedServers.forEach(guildId=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{
console.log(`Couldn't register slash commands for ${guildId} because`, e.stack);
(client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``)
}))
};
console.log(`${client.user.username} has logged into Discord API`);
console.log(client.config.botSwitches, client.config.whitelistedServers);
(client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send({content: `${client.user.username} is active`, embeds:[new client.embed().setColor(client.config.embedColor).setDescription(`\`\`\`json\n${Object.entries(client.config.botSwitches).map(x=>`${x[0]}: ${x[1]}`).join('\n')}\`\`\``)]});
console.timeEnd('Startup')
})
// 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 ([ if ([
@ -42,7 +21,6 @@ process.on('unhandledRejection', (error: Error)=>DZ(error, 'unhandledRejection')
process.on('uncaughtException', (error: Error)=>DZ(error, 'uncaughtException')); process.on('uncaughtException', (error: Error)=>DZ(error, 'uncaughtException'));
process.on('error', (error: Error)=>DZ(error, 'nodeError')); process.on('error', (error: Error)=>DZ(error, 'nodeError'));
client.on('error', (error: Error)=>DZ(error, 'clientError')); client.on('error', (error: Error)=>DZ(error, 'clientError'));
//client.on('debug', console.log).on('warn', console.log);
// Audio Player event handling // Audio Player event handling
if (client.config.botSwitches.music){ if (client.config.botSwitches.music){
@ -59,14 +37,11 @@ if (client.config.botSwitches.music){
if (queue.tracks.size < 1) return queue.channel.send('There\'s no songs left in the queue, leaving voice channel in 15 seconds.').then(()=>setTimeout(()=>queue.connection.disconnect(), 15000)) if (queue.tracks.size < 1) return queue.channel.send('There\'s no songs left in the queue, leaving voice channel in 15 seconds.').then(()=>setTimeout(()=>queue.connection.disconnect(), 15000))
}); });
player.events.on('playerPause', queue=>queue.channel.send({embeds:[playerEmbed(client.config.embedColor, 'Player has been paused.\nRun the command to unpause it')]})); player.events.on('playerPause', queue=>queue.channel.send({embeds:[playerEmbed(client.config.embedColor, 'Player has been paused.\nRun the command to unpause it')]}));
/* player.events.on('debug', (queue,message)=>{
console.log(client.logTime(), message)
}) */
player.events.on('playerError', (queue, error)=>DZ(error, 'playerError')); // I don't know if both of these actually works, because most player.events.on('playerError', (queue, error)=>DZ(error, 'playerError')); // I don't know if both of these actually works, because most
player.events.on('error', (queue, error)=>DZ(error, 'playerInternalError')); // errors from the player is coming from unhandledRejection player.events.on('error', (queue, error)=>DZ(error, 'playerInternalError')); // errors from the player is coming from unhandledRejection
} }
// YouTube Upload notification and Daggerwin MP loop // YouTube Upload notification and MP loop
if (client.config.botSwitches.mpstats) setInterval(async()=>{ if (client.config.botSwitches.mpstats) setInterval(async()=>{
const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id)); const serverlake = (await client.MPServer._content.findById(client.config.mainServer.id));
for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPLoop(client, locArea.channel, locArea.message, serverlake[locName], locName) for await (const [locName, locArea] of Object.entries(client.config.MPStatsLocation)) await MPLoop(client, locArea.channel, locArea.message, serverlake[locName], locName)

View File

@ -15,5 +15,5 @@
"typeRoots": [ "./src/typings" ], "typeRoots": [ "./src/typings" ],
}, },
"include": [ "src/" ], "include": [ "src/" ],
"exclude": [ ".yarn/cache", ".yarn/unplugged",".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json", "src/disabled" ] "exclude": [ ".yarn/cache", ".yarn/unplugged",".git", "src/config.json", "src/DB-Beta.config.json", "src/Toast-Testbot.config.json" ]
} }