Skip to content

Commit 3ca260b

Browse files
committed
Merge branch 'main' of github.com:uwcsc/codeybot into Issue495
2 parents 6533b4d + 8bedc02 commit 3ca260b

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

src/commandDetails/admin/ban.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { CodeyUserError } from './../../codeyUserError';
21
import { container } from '@sapphire/framework';
3-
import { PermissionsBitField, User } from 'discord.js';
2+
import { EmbedBuilder, PermissionsBitField, TextChannel, User } from 'discord.js';
43
import {
54
CodeyCommandDetails,
65
CodeyCommandOptionType,
76
SapphireMessageExecuteType,
7+
getUserFromMessage,
88
} from '../../codeyCommand';
99
import { banUser } from '../../components/admin';
1010
import { vars } from '../../config';
11+
import { DEFAULT_EMBED_COLOUR } from '../../utils/embeds.js';
1112
import { pluralize } from '../../utils/pluralize';
13+
import { CodeyUserError } from './../../codeyUserError';
14+
15+
const NOTIF_CHANNEL_ID: string = vars.NOTIF_CHANNEL_ID;
1216

1317
// Ban a user
1418
const banExecuteCommand: SapphireMessageExecuteType = async (client, messageFromUser, args) => {
@@ -35,6 +39,25 @@ const banExecuteCommand: SapphireMessageExecuteType = async (client, messageFrom
3539
// get Guild object corresponding to server
3640
const guild = await client.guilds.fetch(vars.TARGET_GUILD_ID);
3741
if (await banUser(guild, user, reason, days)) {
42+
const mod = getUserFromMessage(messageFromUser);
43+
const banEmbed = new EmbedBuilder()
44+
.setTitle('Ban')
45+
.setColor(DEFAULT_EMBED_COLOUR)
46+
.addFields([
47+
{ name: 'User', value: `${user.tag} (${user.id})` },
48+
{
49+
name: 'Banned By',
50+
value: `${mod.tag} (${mod.id})`,
51+
},
52+
{ name: 'Reason', value: reason },
53+
{
54+
name: 'Messages Purged',
55+
value: !days ? 'None' : `Past ${days} ${pluralize('day', days)}`,
56+
},
57+
]);
58+
(client.channels.cache.get(NOTIF_CHANNEL_ID) as TextChannel).send({
59+
embeds: [banEmbed],
60+
});
3861
return `Successfully banned user ${user.tag} (id: ${user.id}) ${
3962
days ? `and deleted their messages in the past ${days} ${pluralize('day', days)} ` : ``
4063
}for the following reason: ${reason}`;

src/commandDetails/coin/leaderboard.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { container, SapphireClient } from '@sapphire/framework';
2-
import { EmbedBuilder, User } from 'discord.js';
2+
import { EmbedBuilder } from 'discord.js';
33
import {
44
CodeyCommandDetails,
55
getUserFromMessage,
@@ -36,17 +36,12 @@ const getCoinLeaderboardEmbed = async (
3636
leaderboard = await getCoinLeaderboard(LEADERBOARD_LIMIT_FETCH, offset);
3737
i = 0;
3838
}
39-
if (leaderboard.length === 0) {
39+
if (i >= leaderboard.length) {
4040
break;
4141
}
4242
const userCoinEntry = leaderboard[i++];
43-
let user: User;
44-
try {
45-
user = await client.users.fetch(userCoinEntry.user_id);
46-
} catch (e) {
47-
continue;
48-
}
49-
if (user.bot) continue;
43+
const user = await client.users.fetch(userCoinEntry.user_id).catch(() => null);
44+
if (user?.bot) continue;
5045
if (previousBalance === userCoinEntry.balance) {
5146
previousBalance = userCoinEntry.balance;
5247
// rank does not change
@@ -60,18 +55,7 @@ const getCoinLeaderboardEmbed = async (
6055
position = rank;
6156
}
6257
if (leaderboardArray.length < LEADERBOARD_LIMIT_DISPLAY) {
63-
const userTag = user?.tag ?? '<unknown>';
64-
const cleanUserTag = userTag
65-
.split('~')
66-
.join('\\~')
67-
.split('*')
68-
.join('\\*')
69-
.split('_')
70-
.join('\\_')
71-
.split('`')
72-
.join('\\`');
73-
// added a "\\" below in ${rank}\\. ${cleanUserTag} so that Markdown does not automatically increment by 1 each time
74-
const userCoinEntryText = `${rank}\\. ${cleanUserTag} - ${
58+
const userCoinEntryText = `${rank}\\. <@${userCoinEntry.user_id}> - ${
7559
userCoinEntry.balance
7660
} ${getCoinEmoji()}`;
7761
leaderboardArray.push(userCoinEntryText);

0 commit comments

Comments
 (0)