From 5cb816854f454291a5566e608d067f3328e95486 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:45:25 +1100 Subject: [PATCH] Punishment improvements --- src/commands/case.ts | 2 +- src/commands/unpunish.ts | 5 +++-- src/components/Punish.ts | 8 +++++++- src/models/punishments.ts | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/commands/case.ts b/src/commands/case.ts index 4ec7e4c..823e6b1 100644 --- a/src/commands/case.ts +++ b/src/commands/case.ts @@ -41,7 +41,7 @@ export default class Case { {name: '\u200b', value: '\u200b', inline: true}, {name: 'Reason', value: `\`${punishment.reason || 'Reason unspecified'}\``, inline: true}) if (punishment.dataValues.duration) embed.addFields({name: 'Duration', value: `${Formatters.timeFormat(punishment.dataValues.duration, 100)}`}) - if (punishment.dataValues.expired) embed.addFields({name: 'Expired', value: `This case has been overwritten by Case #${cancelledBy.dataValues.case_id} for reason \`${cancelledBy.dataValues.reason}\``}) + if (punishment.dataValues.expired) embed.addFields({name: 'Expired', value: `This case has been overwritten by Case #${cancelledBy.dataValues.case_id} with reason \`${cancelledBy.dataValues.reason}\``}) if (punishment.dataValues.cancels) embed.addFields({name: 'Overwrites', value: `This case overwrites Case #${cancels.dataValues.case_id} with reason \`${cancels.dataValues.reason}\``}) interaction.reply({embeds: [embed]}); }, diff --git a/src/commands/unpunish.ts b/src/commands/unpunish.ts index 2b05947..693bfce 100644 --- a/src/commands/unpunish.ts +++ b/src/commands/unpunish.ts @@ -11,8 +11,9 @@ export default class Unpunish { const reason = interaction.options.getString('reason') ?? 'Reason unspecified'; await client.punishments.punishmentRemove(punishment.dataValues.case_id, interaction.user.id, reason, interaction); - Logger.console('log', 'UnpunishmentLog', `Case #${interaction.options.getInteger('case_id')} was used in /${interaction.commandName} for ${reason}`); - (client.channels.cache.get(client.config.dcServer.channels.punishment_log) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColor).setTitle('Unpunishment Log').setDescription(`Case #${interaction.options.getInteger('case_id')} was used in \`/${interaction.commandName}\` for \`${reason}\``).setTimestamp()]}); + const unpunishLog = `Case #${interaction.options.getInteger('case_id')} was used in \`/${interaction.commandName}\` for \`${reason}\``; + Logger.console('log', 'UnpunishmentLog', unpunishLog); + (client.channels.cache.get(client.config.dcServer.channels.punishment_log) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColor).setTitle('Unpunishment Log').setDescription(unpunishLog).setTimestamp()]}); } static data = new Discord.SlashCommandBuilder() .setName('unpunish') diff --git a/src/components/Punish.ts b/src/components/Punish.ts index d0ebf9e..2fffa47 100644 --- a/src/components/Punish.ts +++ b/src/components/Punish.ts @@ -1,18 +1,24 @@ import Discord from 'discord.js'; import TClient from '../client.js'; import MessageTool from '../helpers/MessageTool.js'; +import Logger from '../helpers/Logger.js'; export default async(client:TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>, type: 'ban'|'softban'|'kick'|'mute'|'warn'|'remind')=>{ if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod'); + const isInBKL = ['ban', 'kick'].includes(type) && interaction.channelId === client.config.dcServer.channels.bankick_log; 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); + const punishLog = `${GuildMember?.user?.username ?? User?.username ?? 'No user data'} ${time ? ['warn', 'kick'].includes(type) ? 'and no duration set' : `and ${time} (duration)` : ''} was used in \`/${interaction.commandName}\` for \`${reason}\``; + Logger.console('log', 'PunishmentLog', punishLog); + (client.channels.cache.get(client.config.dcServer.channels.punishment_log) as Discord.TextChannel).send({embeds:[new client.embed().setColor(client.config.embedColor).setTitle('Punishment Log').setDescription(punishLog).setTimestamp()]}); + if (interaction.user.id === User.id) return interaction.reply(`You cannot ${type} yourself.`); if (!GuildMember && !['unban', 'ban'].includes(type)) return interaction.reply(`You cannot ${type} someone who is not in the server.`); if (User.bot) return interaction.reply(`You cannot ${type} a bot!`); - await interaction.deferReply(); + await interaction.deferReply({ephemeral: isInBKL}); await client.punishments.punishmentAdd(type, {time, interaction}, interaction.user.id, reason, User, GuildMember); } diff --git a/src/models/punishments.ts b/src/models/punishments.ts index f72571b..6430460 100644 --- a/src/models/punishments.ts +++ b/src/models/punishments.ts @@ -129,7 +129,7 @@ export class PunishmentsSvc { {name: '\u200b', value: '\u200b', inline: true}, {name: '🔹 Reason', value: `\`${punishment.reason}\``, inline: true} ).setTimestamp(punishment.time); - if (punishment.duration) embed.addFields({name: '🔹 Duration', value: `${Formatters.timeFormat(punishment.duration, 4, {longNames: false, commas: true})}`, inline: true}, {name: '\u200b', value: '\u200b', inline: true}); + if (punishment.duration) embed.addFields({name: '🔹 Duration', value: `${Formatters.timeFormat(punishment.duration, 4, {longNames: true, commas: true})}`, inline: true}, {name: '\u200b', value: '\u200b', inline: true}); if (punishment.cancels) { const cancels = await this.model.findOne({where: {case_id: punishment.cancels}}) embed.addFields({name: '🔹 Overwrites', value: `This case invalidates Case #${cancels.dataValues.case_id}\n\`${cancels.dataValues.reason}\``}); @@ -252,7 +252,7 @@ export class PunishmentsSvc { .setColor(this.client.config.embedColor) .setTitle(`${removePunishmentData.type[0].toUpperCase() + removePunishmentData.type.slice(1)} | Case #${removePunishmentData.case_id}`) .setDescription(`${user.username}\n<@${user.id}>\n\`${user.id}\``) - .addFields({name: 'Reason', value: reason}, {name: 'Overwrites', value: `Case #${punishment.case_id}`}) + .addFields({name: 'Reason', value: `\`${reason}\``}, {name: 'Overwrites', value: `Case #${punishment.case_id}`}) ]}); else return `Successfully un${this.getPastTense(removePunishmentData.type.replace('un', ''))} ${user.username} (\`${user.id}\`) for ${reason}` }