1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 08:20:58 -05:00
Daggerbot-TS/src/events/ready.ts

33 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-08-26 10:47:06 -04:00
import Discord from 'discord.js';
import TClient from '../client.js';
2023-10-06 02:11:23 -04:00
import ansi from 'ansi-colors';
2023-12-24 10:21:40 -05:00
export default class Ready {
static async run(client:TClient){
2023-10-06 02:11:23 -04:00
const botSwitches = Object.entries(client.config.botSwitches).map(([k, v])=>`${ansi.yellow(k)}${ansi.black(':')} ${v}`).join('\n').replace(/true/g, ansi.green('true')).replace(/false/g, ansi.red('false'));
2023-10-06 01:54:27 -04:00
2023-12-24 10:21:40 -05:00
await client.guilds.fetch(client.config.dcServer.id).then(async guild=>{
2024-03-04 19:03:04 -05:00
const logsArray = [client.config.dcServer.channels.bot_log, client.config.dcServer.channels.bankick_log];
2023-12-24 10:21:40 -05:00
for (const channelID of logsArray) {
const channel = await client.channels.fetch(channelID) as Discord.TextChannel;
if (channel && channel.type === Discord.ChannelType.GuildText) await channel.messages.fetch({limit: 15});
}
2023-08-26 10:47:06 -04:00
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})))
2024-01-31 15:54:38 -05:00
}, 300000)
2023-08-26 10:47:06 -04:00
})
2024-01-31 15:54:38 -05:00
if (client.config.botSwitches.registerCommands) {
2023-08-26 10:47:06 -04:00
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);
2023-12-24 10:21:40 -05:00
(client.channels.resolve(client.config.dcServer.channels.errors) as Discord.TextChannel).send(`Cannot register slash commands for **${client.guilds.cache.get(guildId).name}** (\`${guildId}\`):\n\`\`\`${e.message}\`\`\``)
2023-08-26 10:47:06 -04:00
}))
}
2024-01-31 15:54:38 -05:00
console.log(`Ready as ${client.user.tag}`);
2023-08-26 10:47:06 -04:00
console.log(client.config.botSwitches, client.config.whitelistedServers);
2024-01-31 15:54:38 -05:00
(client.channels.resolve(client.config.dcServer.channels.bot_status) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColor).setDescription(`**\`\`\`ansi\n${botSwitches}\n\`\`\`**`)]});
2023-08-26 10:47:06 -04:00
console.timeEnd('Startup')
}
}