Skip to content

Commit

Permalink
fix: cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklvh committed Nov 25, 2023
1 parent 5c0a92f commit f64ee94
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 339 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@prisma/client": "^5.6.0",
"@sapphire/decorators": "^6.0.2",
"@sapphire/discord.js-utilities": "^7.1.2",
"@sapphire/fetch": "^2.4.1",
"@sapphire/framework": "^4.8.2",
"@sapphire/plugin-logger": "^3.0.7",
Expand All @@ -39,12 +40,12 @@
"devDependencies": {
"@sapphire/eslint-config": "^5.0.2",
"@sapphire/ts-config": "^5.0.0",
"@swc/core": "^1.3.96",
"@swc/core": "^1.3.99",
"@types/module-alias": "^2.0.4",
"@types/node": "^20.9.2",
"@types/node": "^20.10.0",
"prisma": "^5.6.0",
"tsup": "^8.0.0",
"typescript": "^5.2.2"
"tsup": "^8.0.1",
"typescript": "^5.3.2"
},
"packageManager": "[email protected]",
"_moduleAliases": {
Expand Down
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ model Member {
}

model Modlog {
id Int @id @default(autoincrement())
caseId Int @id @default(autoincrement())
memberId String
moderatorId String
reason String
type ModerationType
createdAt DateTime @default(now())
createdAt DateTime @default(now()) @unique
Guild Guild @relation(fields: [guildId], references: [id])
guildId String
Member Member @relation(fields: [memberId], references: [id])
Expand Down
2 changes: 2 additions & 0 deletions src/core/commands/moderation/BanCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export class BanCommand extends Command {
});
}
} catch (e) {
this.container.logger.error(e);

return interaction.editReply({
embeds: [
errorEmbed.setDescription(
Expand Down
74 changes: 72 additions & 2 deletions src/core/commands/moderation/InfractionsCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Command } from '@sapphire/framework';
import { PermissionFlagsBits } from 'discord.js';
import { ApplyOptions } from '@sapphire/decorators';
import { PaginatedMessage } from '@sapphire/discord.js-utilities';
import { capitaliseFirstLetter } from '@lib/utils';

@ApplyOptions<Command.Options>({
name: 'infractions',
description: 'show all of a members infractions: warns/bans/mutes/kicks...',
description: 'show all of a members infractions, warns/bans/mutes/kicks...',
requiredUserPermissions: [PermissionFlagsBits.ManageMessages],
runIn: 'GUILD_ANY',
})
Expand Down Expand Up @@ -32,6 +34,74 @@ export class InfractionsCommand extends Command {
) {
const user = interaction.options.getUser('user', false) ?? interaction.user;

await interaction.reply(user.toString());
const message = new PaginatedMessage().setActions(
PaginatedMessage.defaultActions.filter(
(action) =>
'customId' in action &&
[
'@sapphire/paginated-messages.previousPage',
'@sapphire/paginated-messages.stop',
'@sapphire/paginated-messages.nextPage',
].includes(action.customId),
),
);

let guildInDB = await this.container.prisma.guild.findUnique({
where: {
id: interaction.guildId!,
},
});

if (!guildInDB) {
guildInDB = await this.container.prisma.guild.create({
data: {
id: interaction.guildId!,
},
});
}

const infractions = await this.container.prisma.modlog.findMany({
where: {
memberId: user.id,
Guild: guildInDB,
guildId: interaction.guildId!,
},
});

if (!infractions || !infractions.length) {
return interaction.reply({
content: 'This user has no infractions',
ephemeral: true,
});
}

for (const infraction of infractions) {
message.addPageEmbed((embed) => {
return embed.setTitle(`Infraction #${infraction.caseId}`).addFields([
{
name: 'Moderator',
value: `<@${infraction.moderatorId}>`,
inline: true,
},
{
name: 'Reason',
value: infraction.reason,
inline: true,
},
{
name: 'Type',
value: capitaliseFirstLetter(infraction.type),
inline: false,
},
{
name: 'Date',
value: `<t:${infraction.createdAt.getMilliseconds()}:f>`,
inline: true,
},
]);
});
}

return message.run(interaction);
}
}
2 changes: 2 additions & 0 deletions src/core/commands/moderation/KickCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export class KickCommand extends Command {
});
}
} catch (e) {
this.container.logger.error(e);

await interaction.editReply({
embeds: [
errorEmbed.setDescription(
Expand Down
Loading

0 comments on commit f64ee94

Please sign in to comment.