mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 00:10:58 -05:00
Sync event handler from TAEMBO/IRTGaming-bot
This commit is contained in:
parent
81991ab75e
commit
2fb0da786d
@ -10,7 +10,7 @@ export default {
|
||||
let messagesArray: Array<string> = [];
|
||||
|
||||
if (user){
|
||||
(interaction.channel as Discord.TextChannel).messages.fetch({limit: 100}).then((msgs)=>{
|
||||
(interaction.channel as Discord.TextChannel).messages.fetch({limit: amount}).then((msgs)=>{
|
||||
const msgList = msgs.filter(x=>x.author.id == user.id);
|
||||
(interaction.channel as Discord.TextChannel).bulkDelete(msgList);
|
||||
})
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord, { AuditLogEvent } from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'guildBanAdd',
|
||||
execute: async(client:TClient, member:Discord.GuildMember)=>{
|
||||
async run(client:TClient, member:Discord.GuildMember){
|
||||
if (member.guild?.id != client.config.mainServer.id) return;
|
||||
const fetchBanlog = await member.guild.fetchAuditLogs({
|
||||
limit: 1,
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord, { AuditLogEvent } from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'guildBanRemove',
|
||||
execute: async(client:TClient, member:Discord.GuildMember)=>{
|
||||
async run(client:TClient, member:Discord.GuildMember){
|
||||
if (member.guild?.id != client.config.mainServer.id) return;
|
||||
const fetchUnbanlog = await member.guild.fetchAuditLogs({
|
||||
limit: 1,
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'guildMemberAdd',
|
||||
execute: async(client:TClient, member:Discord.GuildMember)=>{
|
||||
async run(client:TClient, member:Discord.GuildMember){
|
||||
//if (member.partial) return;
|
||||
if (
|
||||
member.partial
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'guildMemberRemove',
|
||||
execute: async(client:TClient, member:Discord.GuildMember)=>{
|
||||
async run(client:TClient, member:Discord.GuildMember){
|
||||
if (!client.config.botSwitches.logs) return;
|
||||
if (
|
||||
!member.joinedTimestamp
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'guildMemberUpdate',
|
||||
execute: async(client:TClient, oldMember:Discord.GuildMember, newMember:Discord.GuildMember)=>{
|
||||
async run(client:TClient, oldMember:Discord.GuildMember, newMember:Discord.GuildMember){
|
||||
if (oldMember.guild.id != client.config.mainServer.id) return;
|
||||
if (!client.config.botSwitches.logs) return;
|
||||
const channel = (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel)
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'interactionCreate',
|
||||
execute: async(client:TClient, interaction:Discord.ChatInputCommandInteraction)=>{
|
||||
async run(client:TClient, interaction:Discord.ChatInputCommandInteraction){
|
||||
if (!interaction.inGuild() || !interaction.inCachedGuild() || !interaction.command) return;
|
||||
if (interaction.isCommand()){
|
||||
const commandFile = client.commands.get(interaction.commandName);
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'inviteCreate',
|
||||
execute: async(client:TClient, invite: Discord.Invite)=>{
|
||||
async run(client:TClient, invite: Discord.Invite){
|
||||
if (!invite.guild) return;
|
||||
const newInvites = await (invite.guild as Discord.Guild).invites.fetch();
|
||||
newInvites.forEach(inv=>client.invites.set(inv.code,{uses: inv.code, creator: inv.inviterId}))
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'inviteDelete',
|
||||
execute: async(client:TClient, invite: Discord.Invite)=>{
|
||||
async run(client:TClient, invite: Discord.Invite){
|
||||
client.invites.delete(invite.code)
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
import Discord, { ChannelType } from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'messageCreate',
|
||||
execute: async(client:TClient, message:Discord.Message)=>{
|
||||
async run(client:TClient, message:Discord.Message){
|
||||
if (
|
||||
message.author.bot
|
||||
|| message.channel.type === ChannelType.DM
|
||||
@ -153,7 +152,7 @@ export default {
|
||||
message.reply(`Night **${message.member.displayName}**`)
|
||||
}
|
||||
// Failsafe thingy (Toastproof maybe)
|
||||
if (message.content.startsWith('!!!_wepanikfrfr') && client.config.eval.whitelist.includes(message.author.id)){
|
||||
if (message.content.startsWith('!!_wepanikfrfr') && client.config.eval.whitelist.includes(message.author.id)){
|
||||
(client.guilds.cache.get(message.guildId) as Discord.Guild).commands.set(client.registry).then(()=>message.reply('How did you manage to lose the commands??? Anyways, it\'s re-registered now.')).catch((e:Error)=>message.reply(`Failed to deploy slash commands:\n\`\`\`${e.message}\`\`\``));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'messageDelete',
|
||||
execute: async(client:TClient, msg:Discord.Message)=>{
|
||||
async run(client:TClient, msg:Discord.Message){
|
||||
if (!client.config.botSwitches.logs) return;
|
||||
const channel = client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel;
|
||||
const disabledChannels = [
|
||||
|
@ -1,15 +1,11 @@
|
||||
import Discord, { Message, Snowflake } from 'discord.js';
|
||||
import Discord from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'messageDeleteBulk',
|
||||
execute: async(client:TClient, messages:Discord.Collection<Snowflake, Message>)=>{
|
||||
async run(client:TClient, messages:Discord.Collection<string, Discord.Message<boolean>>){
|
||||
const channel = client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel;
|
||||
if (!client.config.botSwitches.logs) return;
|
||||
let msgArray: Array<string> = [];
|
||||
messages.forEach((m)=>{
|
||||
msgArray.push(`${m.author.username}: ${m.content}`);
|
||||
});
|
||||
const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setTitle(`${messages.size} messages were purged`).setDescription(`\`\`\`${msgArray.reverse().join('\n')}\`\`\``.slice(0,3900)).addFields({name: 'Channel', value: `<#${(messages.first() as Discord.Message).channel.id}>`});
|
||||
if ((client.guilds.cache.get('929807948748832798') as Discord.Guild)?.id != client.config.mainServer.id) return;
|
||||
const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setTitle(`${messages.size} messages were purged`).setDescription(`\`\`\`${messages.map((msgs)=>`${msgs.member.displayName}: ${msgs.content}`).reverse().join('\n').slice(0,3900)}\`\`\``).addFields({name: 'Channel', value: `<#${(messages.first() as Discord.Message).channel.id}>`});
|
||||
channel.send({embeds: [embed]})
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
import Discord, { ActionRowBuilder, ButtonBuilder } from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'messageUpdate',
|
||||
execute: async(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message)=>{
|
||||
async run(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message){
|
||||
if (!client.config.botSwitches.logs) return;
|
||||
const disabledChannels = [
|
||||
'548032776830582794', '541677709487505408'
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Discord, { AuditLogEvent } from 'discord.js';
|
||||
import { TClient } from '../client';
|
||||
export default {
|
||||
name: 'roleUpdate',
|
||||
execute: async(client:TClient, oldRole:Discord.Role, newRole:Discord.Role)=>{
|
||||
async run(client:TClient, oldRole:Discord.Role, newRole:Discord.Role){
|
||||
const fetchRoleUpdoot = await client.guilds.cache.get(oldRole.guild.id).fetchAuditLogs({
|
||||
limit: 1,
|
||||
type: AuditLogEvent.RoleUpdate
|
||||
|
11
src/index.ts
11
src/index.ts
@ -14,7 +14,7 @@ client.on('ready', async()=>{
|
||||
}, 60000);
|
||||
// ['929807948748832798', '468835415093411861', '1058183358267543552', '549114074273677314'] - 0=Dev Server, 1=Main Server, 2=Throne, 3=Toast's test server
|
||||
if (client.config.botSwitches.registerCommands){
|
||||
['929807948748832798', '468835415093411861', '1058183358267543552'].forEach((guildId)=>(client.guilds.cache.get(guildId) as Discord.Guild).commands.set(client.registry).catch((e:Error)=>{
|
||||
['929807948748832798'].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}\`\`\``)
|
||||
}));
|
||||
@ -33,11 +33,16 @@ client.on('ready', async()=>{
|
||||
(client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send(`${client.user.username} is active\n\`\`\`json\n${Object.entries(client.config.botSwitches).map((hi)=>`${hi[0]}: ${hi[1]}`).join('\n')}\`\`\``);
|
||||
|
||||
// Event handler
|
||||
const eventFiles = fs.readdirSync('src/events').filter(file=>file.endsWith('.ts'));
|
||||
fs.readdirSync('src/events').forEach((file)=>{
|
||||
const eventFile = require(`./events/${file}`);
|
||||
client.on(file.replace('.ts', ''), async(...args)=>eventFile.default.run(client,...args));
|
||||
});
|
||||
|
||||
/*const eventFiles = fs.readdirSync('src/events').filter(file=>file.endsWith('.ts'));
|
||||
eventFiles.forEach((file)=>{
|
||||
const event = require(`./events/${file}`);
|
||||
client.on(event.default.name, async(...args)=>event.default.execute(client, ...args));
|
||||
});
|
||||
});*/
|
||||
})
|
||||
|
||||
// Handle errors
|
||||
|
Loading…
Reference in New Issue
Block a user