1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 16:30:59 -04:00
Daggerbot-TS/src/commands/case.ts

77 lines
5.2 KiB
TypeScript
Raw Normal View History

import Discord,{SlashCommandBuilder} from "discord.js";
2023-04-14 06:47:58 -04:00
import TClient from '../client.js';
export default {
2023-03-05 05:04:10 -05:00
run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
2023-02-24 19:55:11 -05:00
if (!client.isStaff(interaction.member)) return client.youNeedRole(interaction, 'dcmod');
const caseId = interaction.options.getInteger('id');
({
2023-03-05 05:04:10 -05:00
update: async()=>{
const reason = interaction.options.getString('reason');
await client.punishments._content.findByIdAndUpdate(caseId, {reason});
if (await client.punishments._content.findById(caseId)) await interaction.reply({embeds: [new client.embed().setColor(client.config.embedColorGreen).setTitle('Case updated').setDescription(`Case #${caseId} has been successfully updated with new reason:\n\`${reason}\``)]});
else interaction.reply({embeds: [new client.embed().setColor(client.config.embedColorRed).setTitle('Case not updated').setDescription(`Case #${caseId} is not stored on database, not updating the reason.`)]});
2023-03-05 05:04:10 -05:00
},
view: async()=>{
const punishment = await client.punishments._content.findById(caseId);
if (!punishment) return interaction.reply('Invalid Case ID');
2023-03-05 05:04:10 -05:00
const cancelledBy = punishment.expired ? await client.punishments._content.findOne({cancels:punishment.id}) : null;
const cancels = punishment.cancels ? await client.punishments._content.findOne({_id:punishment.cancels}) : null;
const embed = new client.embed().setColor(client.config.embedColor).setTimestamp(punishment.time).setTitle(`${punishment.type[0].toUpperCase()+punishment.type.slice(1)} | Case #${punishment.id}`).addFields(
{name: '🔹 User', value: `<@${punishment.member}> \`${punishment.member}\``, inline: true},
{name: '🔹 Moderator', value: `<@${punishment.moderator}> \`${punishment.moderator}\``, inline: true},
{name: '\u200b', value: '\u200b', inline: true},
{name: '🔹 Reason', value: `\`${punishment.reason || 'Reason unspecified'}\``, inline: true})
if (punishment.duration) embed.addFields({name: '🔹 Duration', value: client.formatTime(punishment.duration, 100)})
if (punishment.expired) embed.addFields({name: '🔹 Expired', value: `This case has been overwritten by Case #${cancelledBy.id} for reason \`${cancelledBy.reason}\``})
if (punishment.cancels) embed.addFields({name: '🔹 Overwrites', value: `This case overwrites Case #${cancels.id} with reason \`${cancels.reason}\``})
2023-03-05 05:04:10 -05:00
interaction.reply({embeds: [embed]});
},
member: async()=>{
const user = (interaction.options.getUser('user') as Discord.User);
if (user.bot) return interaction.reply(`**${user.username}**'s punishment history cannot be viewed as they are a bot.`)
2023-03-05 05:04:10 -05:00
const punishments = await client.punishments._content.find({});
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}` : ''}`
2023-03-05 05:04:10 -05:00
}
});
if (!punishments || !userPunishment) return interaction.reply(`**${user.username}** has a clean record.`)
2023-03-05 05:04:10 -05:00
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))]});
}
2023-02-24 19:55:11 -05:00
} as any)[interaction.options.getSubcommand()]();
},
2023-03-05 05:04:10 -05:00
data: new SlashCommandBuilder()
.setName('case')
.setDescription('Retrieve case information or user\'s punishment history')
2023-04-24 06:10:11 -04:00
.addSubcommand(opt=>opt
2023-03-05 05:04:10 -05:00
.setName('view')
.setDescription('View a multiple or single case')
2023-03-05 05:04:10 -05:00
.addIntegerOption((optt)=>optt
.setName('id')
.setDescription('Case ID')
2023-03-05 05:04:10 -05:00
.setRequired(true)))
2023-04-24 06:10:11 -04:00
.addSubcommand(opt=>opt
2023-03-05 05:04:10 -05:00
.setName('member')
.setDescription('View member\'s punishment history')
2023-04-24 06:10:11 -04:00
.addUserOption(optt=>optt
2023-03-05 05:04:10 -05:00
.setName('user')
.setDescription('Which user do you want to view their punishment history?')
.setRequired(true))
2023-04-24 06:10:11 -04:00
.addIntegerOption(optt=>optt
2023-03-05 05:04:10 -05:00
.setName('page')
.setDescription('Select the page number')))
2023-04-24 06:10:11 -04:00
.addSubcommand(opt=>opt
2023-03-05 05:04:10 -05:00
.setName('update')
.setDescription('Update the case with new reason')
2023-04-24 06:10:11 -04:00
.addIntegerOption(optt=>optt
2023-03-05 05:04:10 -05:00
.setName('id')
.setDescription('Case ID to be updated')
2023-03-05 05:04:10 -05:00
.setRequired(true))
2023-04-24 06:10:11 -04:00
.addStringOption(optt=>optt
2023-03-05 05:04:10 -05:00
.setName('reason')
.setDescription('New reason for the case')
.setRequired(true)))
};