From fc7746eb01e29ba2a813e60838e4d48183df9beb Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Mon, 2 Jan 2023 12:09:03 +1100 Subject: [PATCH] Improve areas of the bot and update deps & faq --- package.json | 10 +++++----- src/commands/faq.ts | 2 +- src/events/guildMemberAdd.ts | 7 +++++-- src/events/guildMemberRemove.ts | 7 +++++-- src/events/interactionCreate.ts | 3 +-- src/events/messageCreate.ts | 12 +++++++----- src/events/messageDelete.ts | 17 ++++++++++++----- src/events/messageUpdate.ts | 26 ++++++++++++++++++-------- src/index.ts | 13 ++++++++++--- 9 files changed, 64 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 5a7c2fa..8d6cdf8 100644 --- a/package.json +++ b/package.json @@ -24,18 +24,18 @@ }, "dependencies": { "axios": "1.2.1", - "canvas": "2.10.2", + "canvas": "2.11.0", "discord.js": "14.7.1", "moment": "2.29.4", "ms": "2.1.3", - "sequelize": "6.26.0", - "sqlite3": "5.1.2", - "systeminformation": "5.16.4", + "sequelize": "6.28.0", + "sqlite3": "5.1.4", + "systeminformation": "5.16.9", "typescript": "4.9.4", "xml-js": "1.6.11" }, "devDependencies": { - "@types/node": "18.11.12", + "@types/node": "18.11.18", "ts-node": "10.9.1" } } diff --git a/src/commands/faq.ts b/src/commands/faq.ts index 2a3dd83..5525724 100644 --- a/src/commands/faq.ts +++ b/src/commands/faq.ts @@ -4,7 +4,7 @@ export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const options = interaction.options.getString('question') if (options == 'srp'){ - const embed = new client.embed().setColor(client.config.embedColor).setTitle('When will SRP (Survival Roleplay) return?').setImage('https://cdn.discordapp.com/attachments/898252602603610142/1013097505094893698/Screenshot_20220827-153617_YouTube.jpg'); + const embed = new client.embed().setColor(client.config.embedColor).setTitle('When will SRP (Survival Roleplay) return?').setImage('https://cdn.discordapp.com/attachments/1023338018720989305/1059259250242752562/IMG_8964.png'); interaction.reply({embeds: [embed]}) } else if (options == 'dlskin'){ const embed1 = new client.embed().setColor(client.config.embedColor).setTitle('Hex code for Daggerwin Logistics').setDescription('The main color will be Onyx (`#353839`) with red bumpers').setImage('https://cdn.discordapp.com/attachments/801965516947324969/806871878736019456/image0.png'); diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index 8af7ee4..3bba02d 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -3,8 +3,11 @@ import { TClient } from '../client'; export default { name: 'guildMemberAdd', execute: async(client:TClient, member:Discord.GuildMember)=>{ - if (member.partial) return; - if (member.guild?.id != client.config.mainServer.id) return; + //if (member.partial) return; + if ( + member.partial + || member.guild?.id != client.config.mainServer.id + ) return; const index = member.guild.memberCount; const suffix = ((index)=>{ const numbers = index.toString().split('').reverse(); // eg 1850 --> [0,5,8,1] diff --git a/src/events/guildMemberRemove.ts b/src/events/guildMemberRemove.ts index 2a48246..5fe90b9 100644 --- a/src/events/guildMemberRemove.ts +++ b/src/events/guildMemberRemove.ts @@ -4,8 +4,11 @@ export default { name: 'guildMemberRemove', execute: async(client:TClient, member:Discord.GuildMember)=>{ if (!client.config.botSwitches.logs) return; - if (!member.joinedTimestamp) return; - if (member.guild?.id != client.config.mainServer.id) return; + if ( + !member.joinedTimestamp + || member.guild?.id != client.config.mainServer.id + ) return; + // if (member.guild?.id != client.config.mainServer.id) return; const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setThumbnail(member.user.displayAvatarURL({size: 2048}) as string).setTitle(`Member Left: ${member.user.tag}`).setDescription(`<@${member.user.id}>\n\`${member.user.id}\``).addFields( {name: '🔹 Account Creation Date', value: `\n`}, {name: '🔹 Server Join Date', value: `\n`}, diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index f94a97d..24f3129 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -7,9 +7,8 @@ export default { if (interaction.isCommand()){ const commandFile = client.commands.get(interaction.commandName); console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}] ${interaction.user.tag} used /${interaction.commandName} in #${interaction.channel.name}`); - if (!client.config.botSwitches.commands && !client.config.eval.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'Commands are currently disabled.', ephemeral: true}); + if (!client.config.botSwitches.commands && !client.config.eval.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'Bot is currently being run in development mode.', ephemeral: true}); if (commandFile){ - if (commandFile.disabled) return interaction.reply({content: 'This command is currently disabled.', ephemeral: true}); try{ commandFile.default.run(client, interaction); commandFile.uses ? commandFile.uses++ : commandFile.uses = 1; diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 639bbec..776b105 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -3,8 +3,11 @@ import { TClient } from '../client'; export default { name: 'messageCreate', execute: async(client:TClient, message:Discord.Message)=>{ - if (message.author.bot) return; - if (message.channel.type === ChannelType.DM) return; + if ( + message.author.bot + || message.channel.type === ChannelType.DM + ) return; + // if (message.channel.type === ChannelType.DM) return; const msgarr = message.content.toLowerCase().split(' '); let automodded: boolean; @@ -149,10 +152,9 @@ export default { if (NightArray.some(e=>message.content.toLowerCase().startsWith(e))){ message.reply(`Night **${message.member.displayName}**`) } - + // Failsafe thingy (Toastproof maybe) if (message.content.startsWith('!!!_wepanikfrfr') && client.config.eval.whitelist.includes(message.author.id)){ - client.application.commands.set(client.registry); - message.reply({content: 'How could you manage to lose the commands??? Anyways, it\'s re-registered now.'}) + (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}\`\`\``)); } } } diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts index f1f9cfe..7e4c265 100644 --- a/src/events/messageDelete.ts +++ b/src/events/messageDelete.ts @@ -5,11 +5,18 @@ export default { execute: async(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 = ['548032776830582794', '541677709487505408'] - if (msg.guild?.id != client.config.mainServer.id) return; - if (msg.partial) return; - if (msg.author.bot) return; - if (disabledChannels.includes(msg.channelId)) return; + const disabledChannels = [ + '548032776830582794', '541677709487505408' + ] + if ( + msg.guild?.id != client.config.mainServer.id + || msg.partial + || msg.author.bot + || disabledChannels.includes(msg.channelId) + ) return; + // if (msg.partial) return; + // if (msg.author.bot) return; + // if (disabledChannels.includes(msg.channelId)) return; const embed = new client.embed().setColor(client.config.embedColorRed).setTimestamp().setAuthor({name: `Author: ${msg.author.tag} (${msg.author.id})`, iconURL: `${msg.author.displayAvatarURL()}`}).setTitle('Message deleted').setDescription(`<@${msg.author.id}>\n\`${msg.author.id}\``); if (msg.content.length != 0) embed.addFields({name: 'Content', value: `\`\`\`\n${msg.content.slice(0,1000)}\n\`\`\``}); embed.addFields( diff --git a/src/events/messageUpdate.ts b/src/events/messageUpdate.ts index 0d81e5a..96371d8 100644 --- a/src/events/messageUpdate.ts +++ b/src/events/messageUpdate.ts @@ -4,14 +4,24 @@ export default { name: 'messageUpdate', execute: async(client:TClient, oldMsg:Discord.Message, newMsg:Discord.Message)=>{ if (!client.config.botSwitches.logs) return; - const disabledChannels = ['548032776830582794', '541677709487505408'] - if (oldMsg.guild?.id != client.config.mainServer.id) return; - if (oldMsg.author == null) return; - if (oldMsg?.author.bot) return; - if (oldMsg.partial) return; - if (newMsg.partial) return; - if (!newMsg.member) return; - if (disabledChannels.includes(newMsg.channelId)) return; + const disabledChannels = [ + '548032776830582794', '541677709487505408' + ] + if ( + oldMsg.guild?.id != client.config.mainServer.id + || oldMsg.author == null + || oldMsg?.author.bot + || oldMsg.partial + || newMsg.partial + || !newMsg.member + || disabledChannels.includes(newMsg.channelId) + ) return; + // if (oldMsg.author == null) return; + // if (oldMsg?.author.bot) return; + // if (oldMsg.partial) return; + // if (newMsg.partial) return; + // if (!newMsg.member) return; + // if (disabledChannels.includes(newMsg.channelId)) return; const msgarr = newMsg.content.toLowerCase().split(' '); if (client.bannedWords._content.some((word:string)=>msgarr.includes(word)) && (!client.isStaff(newMsg.member))) newMsg.delete(); if (newMsg.content === oldMsg.content) return; diff --git a/src/index.ts b/src/index.ts index 5d5f19e..a0d0b9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,10 +9,17 @@ import {Punishment, UserLevels, FSData, FSCareerSavegame} from './typings/interf client.on('ready', async()=>{ client.guilds.cache.forEach(async(e)=>{await e.members.fetch()}); setInterval(async()=>{ - client.user.setPresence({activities: [{ name: 'Happy new year!', type: 1, url: 'https://www.youtube.com/watch?v=KY1N-ZYe8xA' }], status: 'online'}); + client.user.setPresence({activities: [{ name: '#general-chat', type: 1, url: 'https://www.youtube.com/watch?v=nhB5WoUYQbc' }], status: 'idle'}); // Playing: 0, Streaming (Requires YT/Twitch URL to work): 1, Listening to: 2, Watching: 3, Competing in: 5 }, 60000); - if (client.config.botSwitches.registerCommands) client.application.commands.set(client.registry).catch((e)=>{console.log(`Couldn't register slash commands: ${e}`)}) + // ['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)=>{ + 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}\`\`\``) + })); + }; + setInterval(()=>{ const guild = client.guilds.cache.get(client.config.mainServer.id) as Discord.Guild; guild.invites.fetch().then((invs)=>{ @@ -164,6 +171,6 @@ setInterval(async()=>{ dailyMsgs.push([formattedDate, total]); fs.writeFileSync(__dirname + '/database/dailyMsgs.json', JSON.stringify(dailyMsgs)) console.log(`[${client.moment().format('DD/MM/YY HH:mm:ss')}]`, `Pushed [${formattedDate}, ${total}] to dailyMsgs`); - client.application.commands.fetch().then((commands)=>(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send(`:pencil: Pushed \`[${formattedDate}, ${total}]\` to x.name == 'rank').id}>`)) + client.application.commands.fetch().then((commands)=>(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send(`:pencil: Pushed \`[${formattedDate}, ${total}]\` to x.name == 'rank').id}>`).catch((e)=>{(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send(`:pencil: Pushed \`[${formattedDate}, ${total}]\` to dailyMsgs`)})) } }, 5000)