Skip to content

Commit a76b727

Browse files
authored
Use discord.js@dev (#268)
Use `discord.js@dev` remove bloat related to discordjs/discord.js#9568 rearrange /u-i log display name changes support display names
1 parent c226c18 commit a76b727

File tree

26 files changed

+129
-130
lines changed

26 files changed

+129
-130
lines changed

modules/automod/nicknames.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default async function changeNickname(member: GuildMember) {
2323
);
2424

2525
if (members.size > 1) {
26-
const [safe, unsafe] = members.partition((found) => found.user.username === newNick);
26+
const [safe, unsafe] = members.partition((found) => found.user.displayName === newNick);
2727

2828
if (safe.size > 0) {
2929
for (const [id, found] of unsafe) {
30-
const censored = censor(found.user.username);
31-
const nick = censored ? censored.censored : found.user.username;
30+
const censored = censor(found.user.displayName);
31+
const nick = censored ? censored.censored : found.user.displayName;
3232

3333
if (nick === found.displayName) continue;
3434

@@ -38,8 +38,8 @@ export default async function changeNickname(member: GuildMember) {
3838
}
3939
const unchanged = safe.concat(unsafe);
4040
if (unchanged.size > 1 && unchanged.has(member.id)) {
41-
const censored = censor(member.user.username);
42-
const nick = censored ? censored.censored : member.user.username;
41+
const censored = censor(member.user.displayName);
42+
const nick = censored ? censored.censored : member.user.displayName;
4343

4444
if (nick !== member.displayName) {
4545
setNickname(member, nick, "Conflicts");
@@ -60,7 +60,10 @@ export default async function changeNickname(member: GuildMember) {
6060

6161
async function setNickname(member: GuildMember, newNickname: string, reason: string) {
6262
if (member.moderatable)
63-
await member.setNickname(member.user.username === newNickname ? null : newNickname, reason);
63+
await member.setNickname(
64+
member.user.displayName === newNickname ? null : newNickname,
65+
reason,
66+
);
6467
else
6568
await log(
6669
`${LoggingErrorEmoji} Missing permissions to change ${member.toString()}’s nickname to \`${newNickname}\` (${reason})`,

modules/board/misc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function generateBoardMessage(
110110
const description = await messageToText(message);
111111

112112
const censored = censor(description);
113-
const censoredName = censor(message.author.username);
113+
const censoredName = censor(message.author.displayName);
114114

115115
while (embeds.length > 9) embeds.pop(); // 9 and not 10 because we still need to add ours
116116

@@ -160,7 +160,7 @@ export async function generateBoardMessage(
160160
: (message.member?.displayName ??
161161
(censoredName
162162
? censoredName.censored
163-
: message.author.username)) +
163+
: message.author.displayName)) +
164164
(message.author.bot ? " 🤖" : ""),
165165
},
166166

modules/bot/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineCommand(
2525
description: `(${
2626
process.env.NODE_ENV === "production"
2727
? owner instanceof User
28-
? owner.username
28+
? owner.displayName
2929
: owner?.name + " team"
3030
: "Scradd dev"
3131
} only) Run code on Scradd`,

modules/bot/info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ async function getRole(roleId: Snowflake, useMentions = false): Promise<string>
4343
members.push({ user: await client.users.fetch(constants.users.retron) });
4444

4545
return joinWithAnd(
46-
members.sort((one, two) => one.user.username.localeCompare(two.user.username)),
47-
(member) => (useMentions ? userMention(member.user.id) : member.user.username),
46+
members.sort((one, two) => one.user.displayName.localeCompare(two.user.displayName)),
47+
(member) => (useMentions ? userMention(member.user.id) : member.user.displayName),
4848
);
4949
}
5050

modules/bot/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function getCode(interaction: ChatInputCommandInteraction<"
2020
content: `${constants.emojis.statuses.no} This command is reserved for ${
2121
process.env.NODE_ENV === "production"
2222
? owner instanceof User
23-
? owner.username
23+
? owner.displayName
2424
: "the " + owner?.name + " team"
2525
: "Scradd developers"
2626
} only!`,

modules/bot/say.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function sayAutocomplete(interaction: AutocompleteInteraction<"cach
4343
interaction: message.interaction && "/" + message.interaction.commandName,
4444
attachments: message.attachments.map((attachment) => attachment.name),
4545
stickers: message.stickers.map((sticker) => sticker.name),
46-
author: message.author.username,
46+
author: message.author.displayName,
4747
components: message.components,
4848
createdTimestamp: message.createdTimestamp,
4949
content: stripMarkdown(

modules/games/guessAddon.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export default async function guessAddon(
161161
: interaction.user
162162
).displayAvatarURL(),
163163

164-
name:
165-
interaction.member instanceof GuildMember
166-
? interaction.member.displayName
167-
: interaction.user.username,
164+
name: (interaction.member instanceof GuildMember
165+
? interaction.member
166+
: interaction.user
167+
).displayName,
168168
},
169169

170170
title: "🤔 Think of an addon…",
@@ -431,10 +431,10 @@ export default async function guessAddon(
431431
: interaction.user
432432
).displayAvatarURL(),
433433

434-
name:
435-
interaction.member instanceof GuildMember
436-
? interaction.member.displayName
437-
: interaction.user.username,
434+
name: (interaction.member instanceof GuildMember
435+
? interaction.member
436+
: interaction.user
437+
).displayName,
438438
},
439439

440440
color: constants.themeColor,

modules/logging/member.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ export async function userUpdate(oldUser: User | PartialUser, newUser: User) {
181181
);
182182
}
183183

184+
if (oldUser.displayName !== newUser.displayName) {
185+
await log(
186+
`${LoggingEmojis.UserUpdate} ${newUser.toString()} changed their display name from ${
187+
oldUser.displayName
188+
} to ${newUser.displayName}`,
189+
"members",
190+
);
191+
}
192+
184193
const quarantined = !!newUser.flags?.has("Quarantined");
185194
if (!!oldUser.flags?.has("Quarantined") !== quarantined) {
186195
await log(

modules/logging/misc.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ export async function getLoggingThread(group?: LogGroup | typeof DATABASE_THREAD
111111
const threads = await config.channels.modlogs.threads.fetchActive();
112112

113113
return (
114-
threads.threads.find(
115-
(thread) => thread.parent?.id === config.channels.modlogs?.id && thread.name === group,
116-
) ||
114+
threads.threads.find((thread) => thread.name === group) ||
117115
(await config.channels.modlogs.threads.create({
118116
name: group,
119117
reason: "New logging thread",

modules/modInterestForm.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import giveXp from "./xp/giveXp.js";
1010
if (!config.channels.admin) throw new ReferenceError("Could not find admin channel");
1111
const threads = await config.channels.admin.threads.fetchActive();
1212
const thread =
13-
threads.threads.find(
14-
(thread) =>
15-
thread.parent?.id === config.channels.admin?.id &&
16-
thread.name === "Moderator Interest Forms",
17-
) ||
13+
threads.threads.find((thread) => thread.name === "Moderator Interest Forms") ||
1814
(await config.channels.admin.threads.create({
1915
name: "Moderator Interest Forms",
2016
reason: "For mod interest forms",

modules/notifs.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,20 @@ defineEvent("guildMemberRemove", async (member) => {
7575

7676
const byes = banned
7777
? [
78-
`Oof… **${member.user.username}** got banned…`,
79-
`There’s no turning back for **${member.user.username}**…`,
80-
`I don’t think this was the best place for **${member.user.username}**…`,
81-
`Oop, **${member.user.username}** angered the mods!`,
82-
`**${member.user.username}** broke the rules and took an 🇱`,
83-
`**${member.user.username}** talked about opacity slider too much.`,
78+
`Oof… **${member.user.displayName}** got banned…`,
79+
`There’s no turning back for **${member.user.displayName}**…`,
80+
`I don’t think this was the best place for **${member.user.displayName}**…`,
81+
`Oop, **${member.user.displayName}** angered the mods!`,
82+
`**${member.user.displayName}** broke the rules and took an 🇱`,
83+
`**${member.user.displayName}** talked about opacity slider too much.`,
8484
]
8585
: [
86-
`Welp… **${member.user.username}** decided to leave… what a shame…`,
87-
`Ahh… **${member.user.username}** left us… hope they’ll have safe travels!`,
88-
`There goes another, bye **${member.user.username}**!`,
89-
`Oop, **${member.user.username}** left… will they ever come back?`,
90-
`Can we get an F in the chat for **${member.user.username}**? They left!`,
91-
`Ope, **${member.user.username}** got eaten by an evil kumquat and left!`,
86+
`Welp… **${member.user.displayName}** decided to leave… what a shame…`,
87+
`Ahh… **${member.user.displayName}** left us… hope they’ll have safe travels!`,
88+
`There goes another, bye **${member.user.displayName}**!`,
89+
`Oop, **${member.user.displayName}** left… will they ever come back?`,
90+
`Can we get an F in the chat for **${member.user.displayName}**? They left!`,
91+
`Ope, **${member.user.displayName}** got eaten by an evil kumquat and left!`,
9292
];
9393

9494
await config.channels.welcome?.send(

modules/punishments/strikes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function getStrikes(
8181
: interaction.reply(newData));
8282
},
8383
{
84-
title: `${member?.displayName ?? user.username}’s strikes`,
84+
title: `${(member ?? user).displayName}’s strikes`,
8585
singular: "",
8686
plural: "",
8787
failMessage: `${selected.toString()} has never been warned!`,
@@ -146,7 +146,7 @@ export async function getStrikeById(
146146
isModerator && strike.mod === "AutoMod"
147147
? strike.mod
148148
: strike.mod && (await client.users.fetch(strike.mod).catch(() => {}));
149-
const nick = member?.displayName ?? user?.username;
149+
const nick = (member ?? user)?.displayName;
150150
const { useMentions } = getSettings(interactor.user);
151151
return {
152152
components: isModerator
@@ -201,7 +201,7 @@ export async function getStrikeById(
201201
? moderator
202202
: useMentions
203203
? moderator.toString()
204-
: moderator.username,
204+
: moderator.displayName,
205205
inline: true,
206206
},
207207
]
@@ -210,7 +210,7 @@ export async function getStrikeById(
210210
? [
211211
{
212212
name: "👤 Target user",
213-
value: useMentions ? user.toString() : user.username,
213+
value: useMentions ? user.toString() : user.displayName,
214214
inline: true,
215215
},
216216
]

modules/purge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ defineCommand(
9393

9494
author: {
9595
icon_url: (last.member ?? last.author).displayAvatarURL(),
96-
name: last.member?.displayName ?? last.author.username,
96+
name: (last.member ?? last.author).displayName,
9797
},
9898

9999
timestamp: last.createdAt.toISOString(),
@@ -113,7 +113,7 @@ defineCommand(
113113

114114
author: {
115115
icon_url: (sliced[0].member ?? sliced[0].author).displayAvatarURL(),
116-
name: sliced[0].member?.displayName ?? sliced[0].author.username,
116+
name: (sliced[0].member ?? sliced[0].author).displayName,
117117
},
118118

119119
timestamp: sliced[0].createdAt.toISOString(),

modules/reminders.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ defineCommand(
234234
? interaction.member
235235
: interaction.user
236236
).displayAvatarURL(),
237-
name:
238-
interaction.member instanceof GuildMember
239-
? interaction.member.displayName
240-
: interaction.user.username,
237+
name: (interaction.member instanceof GuildMember
238+
? interaction.member
239+
: interaction.user
240+
).displayName,
241241
},
242242
footer: {
243243
text: `${reminders.length} reminder${

modules/suggestions/getTop.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export default async function getTop(interaction: ChatInputCommandInteraction<"c
4242
? ""
4343
: ` by ${
4444
useMentions
45-
? `<@${author instanceof User ? author.id : author}>`
45+
? author instanceof User
46+
? author.toString()
47+
: `<@${author}>`
4648
: (author instanceof User
4749
? author
4850
: await client.users
4951
.fetch(author)
50-
.catch(() => ({ username: `<@${author}>` }))
51-
).username
52+
.catch(() => ({ displayName: `<@${author}>` }))
53+
).displayName
5254
}`
5355
}`,
5456
async (data) => await interaction[interaction.replied ? "editReply" : "reply"](data),

modules/tickets/contact.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default async function contactMods(
277277

278278
const date = new Date();
279279
const thread = await config.channels.tickets.threads.create({
280-
name: `${member.user.username} (${date
280+
name: `${member.user.displayName} (${date
281281
.getUTCFullYear()
282282
.toLocaleString("en-us", { useGrouping: false })}-${(
283283
date.getUTCMonth() + 1

modules/tickets/misc.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ export async function getThreadFromMember(
1919
return (
2020
await asyncFilter(
2121
threads.toJSON(),
22-
async (thread) =>
23-
thread.parent?.id === config.channels.tickets?.id &&
24-
(await getUserFromTicket(thread))?.id === user.id &&
25-
thread,
22+
async (thread) => (await getUserFromTicket(thread))?.id === user.id && thread,
2623
).next()
2724
).value;
2825
}

0 commit comments

Comments
 (0)