Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log message for bans in the notif channel #519

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/commandDetails/admin/ban.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { CodeyUserError } from './../../codeyUserError';
import { container } from '@sapphire/framework';
import { PermissionsBitField, User } from 'discord.js';
import { EmbedBuilder, PermissionsBitField, TextChannel, User } from 'discord.js';
import {
CodeyCommandDetails,
CodeyCommandOptionType,
SapphireMessageExecuteType,
getUserFromMessage,
} from '../../codeyCommand';
import { banUser } from '../../components/admin';
import { vars } from '../../config';
import { DEFAULT_EMBED_COLOUR } from '../../utils/embeds.js';
import { pluralize } from '../../utils/pluralize';
import { CodeyUserError } from './../../codeyUserError';

const NOTIF_CHANNEL_ID: string = vars.NOTIF_CHANNEL_ID;

// Ban a user
const banExecuteCommand: SapphireMessageExecuteType = async (client, messageFromUser, args) => {
Expand All @@ -35,6 +39,25 @@ const banExecuteCommand: SapphireMessageExecuteType = async (client, messageFrom
// get Guild object corresponding to server
const guild = await client.guilds.fetch(vars.TARGET_GUILD_ID);
if (await banUser(guild, user, reason, days)) {
const mod = getUserFromMessage(messageFromUser);
const banEmbed = new EmbedBuilder()
.setTitle('Ban')
.setColor(DEFAULT_EMBED_COLOUR)
.addFields([
{ name: 'User', value: `${user.tag} (${user.id})` },
{
name: 'Banned By',
value: `${mod.tag} (${mod.id})`,
},
{ name: 'Reason', value: reason },
{
name: 'Messages Purged',
value: !days ? 'None' : `Past ${days} ${pluralize('day', days)}`,
},
]);
(client.channels.cache.get(NOTIF_CHANNEL_ID) as TextChannel).send({
embeds: [banEmbed],
});
return `Successfully banned user ${user.tag} (id: ${user.id}) ${
days ? `and deleted their messages in the past ${days} ${pluralize('day', days)} ` : ``
}for the following reason: ${reason}`;
Expand Down
Loading