1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-27 20:35:38 -05:00

Improve punishment logs and other areas of the bot

This commit is contained in:
toast-ts 2023-05-02 10:12:45 +10:00
parent dfad604484
commit 7f6fbfa93b
3 changed files with 11 additions and 16 deletions

View File

@ -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!`);

View File

@ -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))]});
}

View File

@ -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')