diff --git a/src/client.ts b/src/client.ts index 0344a5f..9665c33 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,6 @@ import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js'; import fs from 'node:fs'; import {exec} from 'node:child_process'; -import timeNames from './timeNames.js'; import mongoose from 'mongoose'; import {formatTimeOpt, Tokens, Config, repeatedMessages} from './typings/interfaces'; import bannedWords from './models/bannedWords.js'; @@ -52,15 +51,13 @@ export default class TClient extends Client { super({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites, + GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages - ], - partials: [ + ], partials: [ Partials.Channel, Partials.Reaction, Partials.Message - ], - allowedMentions: {users:[],roles:[]} + ], allowedMentions: {users:[],roles:[]} }) this.invites = new Map(); this.commands = new Discord.Collection(); @@ -101,7 +98,7 @@ export default class TClient extends Client { socketTimeoutMS: 30000, family: 4 }).then(()=>console.log(this.logTime(), 'Successfully connected to MongoDB')).catch(err=>{console.error(this.logTime(), `Failed to connect to MongoDB\n${err.reason}`); exec('pm2 stop Daggerbot')}) - await this.login(this.tokens.main); + this.login(this.tokens.main); for await (const file of fs.readdirSync('dist/events')){ const eventFile = await import(`./events/${file}`); this.on(file.replace('.js',''), async(...args)=>eventFile.default.run(this,...args)) @@ -115,10 +112,18 @@ export default class TClient extends Client { formatTime(integer: number, accuracy = 1, options?: formatTimeOpt){ let achievedAccuracy = 0; let text:any = ''; - for (const timeName of timeNames){ + for (const timeName of [ + {name: 'year', length: 31536000000}, + {name: 'month', length: 2592000000}, + {name: 'week', length: 604800000}, + {name: 'day', length: 86400000}, + {name: 'hour', length: 3600000}, + {name: 'minute', length: 60000}, + {name: 'second', length: 1000} + ]){ if (achievedAccuracy < accuracy){ const fullTimelengths = Math.floor(integer/timeName.length); - if (fullTimelengths == 0) continue; + if (fullTimelengths === 0) continue; achievedAccuracy++; text += fullTimelengths + (options?.longNames ? (' '+timeName.name+(fullTimelengths === 1 ? '' : 's')) : timeName.name.slice(0, timeName.name === 'month' ? 2 : 1)) + (options?.commas ? ', ' : ' '); integer -= fullTimelengths*timeName.length; diff --git a/src/events/messageReactionAdd.ts b/src/events/messageReactionAdd.ts new file mode 100644 index 0000000..82bd7b5 --- /dev/null +++ b/src/events/messageReactionAdd.ts @@ -0,0 +1,11 @@ +import Discord from 'discord.js'; +import TClient from '../client.js'; +export default { + run(client:TClient, reaction:Discord.MessageReaction, user:Discord.User){ + if (!client.config.botSwitches.logs) return; + if (reaction.message.guildId != client.config.mainServer.id || reaction.message.partial) return; + const ReactedFirst = reaction.users.cache.first(); + if (ReactedFirst.id != user.id) return; + if (reaction.emoji.name === '🖕') return (client.channels.cache.get(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColorYellow).setTimestamp().setAuthor({name: `Author: ${ReactedFirst.tag} (${ReactedFirst.id})`, iconURL: `${ReactedFirst.displayAvatarURL()}`}).setTitle('Message reaction').setDescription(`<@${ReactedFirst.id}>\nAdded a reaction to the message.\n**Emoji**\n${reaction.emoji.name}\n**Channel**\n<#${reaction.message.channelId}>`).setFooter({text: 'Possibly this member, bot fetches who reacted first.'})], components: [new Discord.ActionRowBuilder().addComponents(new Discord.ButtonBuilder().setStyle(5).setURL(`${reaction.message.url}`).setLabel('Jump to message'))]}); + } +} diff --git a/src/events/messageReactionRemove.ts b/src/events/messageReactionRemove.ts new file mode 100644 index 0000000..8cee6e8 --- /dev/null +++ b/src/events/messageReactionRemove.ts @@ -0,0 +1,9 @@ +import Discord from 'discord.js'; +import TClient from '../client.js'; +export default { + run(client:TClient, reaction:Discord.MessageReaction, user:Discord.User){ + if (!client.config.botSwitches.logs) return; + if (reaction.message.guildId != client.config.mainServer.id || reaction.message.partial) return; + if (reaction.emoji.name === '🖕') return (client.channels.cache.get(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColorRed).setTimestamp().setAuthor({name: `Author: ${user.tag} (${user.id})`, iconURL: `${user.displayAvatarURL()}`}).setTitle('Message reaction').setDescription(`<@${user.id}>\nRemoved a reaction from the message.\n**Emoji**\n${reaction.emoji.name}\n**Channel**\n<#${reaction.message.channelId}>`)]}) + } +} diff --git a/src/timeNames.ts b/src/timeNames.ts deleted file mode 100644 index fde511b..0000000 --- a/src/timeNames.ts +++ /dev/null @@ -1,30 +0,0 @@ -export default [ - { - name: 'year', - length: 1000 * 60 * 60 * 24 * 365 - }, - { - name: 'month', - length: 1000 * 60 * 60 * 24 * 30 - }, - { - name: 'week', - length: 1000 * 60 * 60 * 24 * 7 - }, - { - name: 'day', - length: 1000 * 60 * 60 * 24 - }, - { - name: 'hour', - length: 1000 * 60 * 60 - }, - { - name: 'minute', - length: 1000 * 60 - }, - { - name: 'second', - length: 1000 - } -]