From 7f6fbfa93b69adad933e796f94891976ff15d799 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Tue, 2 May 2023 10:12:45 +1000 Subject: [PATCH] Improve punishment logs and other areas of the bot --- src/client.ts | 16 +++++++--------- src/commands/case.ts | 9 +++------ src/commands/unpunish.ts | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/client.ts b/src/client.ts index e7d5bb1..e286aaf 100644 --- a/src/client.ts +++ b/src/client.ts @@ -51,12 +51,11 @@ export default class TClient extends Client { super({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildMessageReactions, - GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages + GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildInvites, + GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildPresences, + GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages ], partials: [ - Partials.Channel, - Partials.Reaction, - Partials.Message + Partials.Channel, Partials.Reaction, Partials.Message ], allowedMentions: {users:[],roles:[]} }) this.invites = new Map(); @@ -92,7 +91,6 @@ export default class TClient extends Client { await mongoose.connect(this.tokens.mongodb_uri, { replicaSet: 'toastyy', autoIndex: true, - keepAlive: true, serverSelectionTimeoutMS: 15000, waitQueueTimeoutMS: 50000, socketTimeoutMS: 30000, @@ -155,13 +153,13 @@ export default class TClient extends Client { } async punish(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>, type: string){ if (!client.isStaff(interaction.member as Discord.GuildMember)) return client.youNeedRole(interaction, "dcmod"); - console.log(client.logTime(), `[PunishmentLog] ${interaction.options.getMember('member')?.user.tag ? 'No user data' : interaction.options.getUser('member')?.tag} and ${interaction.options.getString('time') ?? 'No duration set'} was used in /${interaction.commandName} for ${interaction.options.getString('reason') ?? 'Reason unspecified'}`); - + const time = interaction.options.getString('time') ?? undefined; const reason = interaction.options.getString('reason') ?? 'Reason unspecified'; const GuildMember = interaction.options.getMember('member') ?? undefined; const User = interaction.options.getUser('member', true); - + + console.log(client.logTime(), `[PunishmentLog] ${GuildMember.user.tag ?? User.tag ?? 'No user data'} and ${time ?? 'no duration set'} was used in /${interaction.commandName} for ${reason}`); if (interaction.user.id == User.id) return interaction.reply(`You cannot ${type} yourself.`); if (!GuildMember && type != 'ban') return interaction.reply(`You cannot ${type} someone who is not in the server.`); if (User.bot) return interaction.reply(`You cannot ${type} a bot!`); diff --git a/src/commands/case.ts b/src/commands/case.ts index 4c7333f..20a2432 100644 --- a/src/commands/case.ts +++ b/src/commands/case.ts @@ -27,20 +27,17 @@ export default { interaction.reply({embeds: [embed]}); }, member: async()=>{ - // if caseid is user id, show their punishment history sorted by most recent. const user = (interaction.options.getUser('user') as Discord.User); - if (user.bot) return interaction.reply(`<@${user.id}>'s punishment history cannot be viewed.`) + if (user.bot) return interaction.reply(`**${user.username}**'s punishment history cannot be viewed as they are a bot.`) const punishments = await client.punishments._content.find({}); - if (!punishments) return interaction.reply(`<@${user.id}> has a clean record.`) const userPunishmentData = await client.punishments._content.find({'member':user.id}); const userPunishment = userPunishmentData.sort((a,b)=>a.time-b.time).map((punishment)=>{ return { name: `${punishment.type[0].toUpperCase()+punishment.type.slice(1)} | Case #${punishment.id}`, - value: `Reason: \`${punishment.reason}\`\n${punishment.duration ? `Duration: ${client.formatTime(punishment.duration, 3)}\n` : ''}Moderator: <@${punishment.moderator}>${punishment.expired ? `\nOverwritten by Case #${punishments.find(x=>x.cancels===punishment._id)?._id}` : ''}${punishment.cancels ? `\nOverwrites case #${punishment.cancels}` : ''}` + value: `Reason: \`${punishment.reason}\`\n${punishment.duration ? `Duration: ${client.formatTime(punishment.duration, 3)}\n` : ''}Moderator: <@${punishment.moderator}>${punishment.expired ? `\nOverwritten by Case #${punishments.find(x=>x.cancels===punishment._id)?._id}` : ''}${punishment.cancels ? `\nOverwrites Case #${punishment.cancels}` : ''}` } }); - // if caseid is not a punishment nor a user, failed - if (!userPunishment || userPunishment.length == 0) return interaction.reply('No punishments found for that Case or User ID'); + if (!punishments || !userPunishment) return interaction.reply(`**${user.username}** has a clean record.`) const pageNum = interaction.options.getInteger('page') ?? 1; return interaction.reply({embeds: [new client.embed().setColor(client.config.embedColor).setTitle(`${user.username}'s punishment history`).setDescription(`**ID:** \`${user.id}\``).setFooter({text: `${userPunishment.length} total punishments. Viewing page ${pageNum} out of ${Math.ceil(userPunishment.length/6)}.`}).addFields(userPunishment.slice((pageNum - 1) * 6, pageNum * 6))]}); } diff --git a/src/commands/unpunish.ts b/src/commands/unpunish.ts index ba356a4..9f90366 100644 --- a/src/commands/unpunish.ts +++ b/src/commands/unpunish.ts @@ -3,12 +3,12 @@ import TClient from '../client.js'; export default { async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ if (!client.isStaff(interaction.member as Discord.GuildMember)) return client.youNeedRole(interaction, 'dcmod'); - console.log(client.logTime(), `[UnpunishmentLog] Case ${interaction.options.getInteger('case_id') ?? '--'} was used in /${interaction.commandName} for ${interaction.options.getString('reason') ?? 'Reason unspecified'}`); const punishment = (await client.punishments._content.find({})).find(x=>x._id === interaction.options.getInteger('case_id', true)); if (!punishment) return interaction.reply({content: 'Invalid Case ID', ephemeral: true}); if (punishment.expired) return interaction.reply('This case has been overwritten by another case.'); const reason = interaction.options.getString('reason') ?? 'Reason unspecified'; await client.punishments.removePunishment(punishment.id, interaction.user.id, reason, interaction); + console.log(client.logTime(), `[UnpunishmentLog] Case #${interaction.options.getInteger('case_id')} was used in /${interaction.commandName} for ${reason}`); }, data: new SlashCommandBuilder() .setName('unpunish')