mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 16:30:58 -05:00
Added message reaction logs and improvements
This commit is contained in:
parent
f5bd1c2dcb
commit
034828d099
@ -1,7 +1,6 @@
|
|||||||
import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js';
|
import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import {exec} from 'node:child_process';
|
import {exec} from 'node:child_process';
|
||||||
import timeNames from './timeNames.js';
|
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import {formatTimeOpt, Tokens, Config, repeatedMessages} from './typings/interfaces';
|
import {formatTimeOpt, Tokens, Config, repeatedMessages} from './typings/interfaces';
|
||||||
import bannedWords from './models/bannedWords.js';
|
import bannedWords from './models/bannedWords.js';
|
||||||
@ -52,15 +51,13 @@ export default class TClient extends Client {
|
|||||||
super({
|
super({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers,
|
GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers,
|
||||||
GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites,
|
GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildMessageReactions,
|
||||||
GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages
|
GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages
|
||||||
],
|
], partials: [
|
||||||
partials: [
|
|
||||||
Partials.Channel,
|
Partials.Channel,
|
||||||
Partials.Reaction,
|
Partials.Reaction,
|
||||||
Partials.Message
|
Partials.Message
|
||||||
],
|
], allowedMentions: {users:[],roles:[]}
|
||||||
allowedMentions: {users:[],roles:[]}
|
|
||||||
})
|
})
|
||||||
this.invites = new Map();
|
this.invites = new Map();
|
||||||
this.commands = new Discord.Collection();
|
this.commands = new Discord.Collection();
|
||||||
@ -101,7 +98,7 @@ export default class TClient extends Client {
|
|||||||
socketTimeoutMS: 30000,
|
socketTimeoutMS: 30000,
|
||||||
family: 4
|
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')})
|
}).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')){
|
for await (const file of fs.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))
|
||||||
@ -115,10 +112,18 @@ export default class TClient extends Client {
|
|||||||
formatTime(integer: number, accuracy = 1, options?: formatTimeOpt){
|
formatTime(integer: number, accuracy = 1, options?: formatTimeOpt){
|
||||||
let achievedAccuracy = 0;
|
let achievedAccuracy = 0;
|
||||||
let text:any = '';
|
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){
|
if (achievedAccuracy < accuracy){
|
||||||
const fullTimelengths = Math.floor(integer/timeName.length);
|
const fullTimelengths = Math.floor(integer/timeName.length);
|
||||||
if (fullTimelengths == 0) continue;
|
if (fullTimelengths === 0) continue;
|
||||||
achievedAccuracy++;
|
achievedAccuracy++;
|
||||||
text += fullTimelengths + (options?.longNames ? (' '+timeName.name+(fullTimelengths === 1 ? '' : 's')) : timeName.name.slice(0, timeName.name === 'month' ? 2 : 1)) + (options?.commas ? ', ' : ' ');
|
text += fullTimelengths + (options?.longNames ? (' '+timeName.name+(fullTimelengths === 1 ? '' : 's')) : timeName.name.slice(0, timeName.name === 'month' ? 2 : 1)) + (options?.commas ? ', ' : ' ');
|
||||||
integer -= fullTimelengths*timeName.length;
|
integer -= fullTimelengths*timeName.length;
|
||||||
|
11
src/events/messageReactionAdd.ts
Normal file
11
src/events/messageReactionAdd.ts
Normal file
@ -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<Discord.ButtonBuilder>().addComponents(new Discord.ButtonBuilder().setStyle(5).setURL(`${reaction.message.url}`).setLabel('Jump to message'))]});
|
||||||
|
}
|
||||||
|
}
|
9
src/events/messageReactionRemove.ts
Normal file
9
src/events/messageReactionRemove.ts
Normal file
@ -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}>`)]})
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
||||||
]
|
|
Loading…
Reference in New Issue
Block a user