Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/commands/prefixed/info/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Snowflake } from 'detritus-utils';

import { BooleanEmojis, ChannelTypesText, CommandCategories, DateMomentLogFormat } from '../../../constants';
import { GuildChannelsStored } from '../../../stores/guildchannels';
import { Parameters, createTimestampMomentFromGuild, editOrReply } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -154,9 +154,9 @@ export default class ChannelCommand extends BaseCommand {

const owner = channel.owner;
if (owner) {
description.push(`**Owner**: ${(insideDm) ? owner.mention : owner}`);
}
const users = channel.recipients.map((user: Structures.User) => (insideDm) ? user.mention : user.toString());
description.push(`**Owner**: ${(insideDm) ? owner.mention : createUserDisplayName(owner)}`);
}
const users = channel.recipients.map((user: Structures.User) => (insideDm) ? user.mention : createUserDisplayName(user));
description.push(`**Recipients (${users.length})**: ${users.join(', ')}`);

embed.addField('DM Information', description.join('\n'));
Expand Down
9 changes: 5 additions & 4 deletions src/commands/prefixed/info/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
import {
DefaultParameters,
Paginator,
Parameters,
createTimestampMomentFromGuild,
editOrReply,
Parameters,
createTimestampMomentFromGuild,
createUserDisplayName,
editOrReply,
getMemberJoinPosition,
toTitleCase,
} from '../../../utils';
Expand Down Expand Up @@ -136,7 +137,7 @@ export default class UsersCommand extends BaseCommand {
const user = ((isMember) ? member.user : memberOrUser) as Structures.User;

const embed = new Embed();
embed.setAuthor(user.toString(), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink);
embed.setAuthor(createUserDisplayName(user), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink);
embed.setColor(PresenceStatusColors['offline']);
embed.setDescription(member.mention);
embed.setThumbnail(member.avatarUrlFormat(null, {size: 1024}));
Expand Down
12 changes: 6 additions & 6 deletions src/commands/prefixed/moderation/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Permissions } from 'detritus-client/lib/constants';
import { Markup } from 'detritus-client/lib/utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import { Parameters, createTimestampMomentFromGuild, createUserEmbed, editOrReply } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -97,7 +97,7 @@ export default class BanCommand extends BaseCommand {
let reason: string | undefined;
{
const description: Array<string> = [];
description.push(`Admin: ${context.user} (${context.user.id})`);
description.push(`Admin: ${createUserDisplayName(context.user)} (${context.user.id})`);
description.push(`Reason: ${(payload.text) ? Markup.escape.all(payload.text) : '[Unspecified Reason]'}`);
{
const timestamp = createTimestampMomentFromGuild(Date.now(), context.guildId);
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class BanCommand extends BaseCommand {
{
const description: Array<string> = [];
if (canEdit.length) {
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
for (let member of members) {
description.push(`-> ${member}`);
}
Expand All @@ -163,15 +163,15 @@ export default class BanCommand extends BaseCommand {
const description: Array<string> = [];
if (cannotEdit.length || clientCannotEdit.length) {
if (clientCannotEdit.length) {
const members = clientCannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = clientCannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Couldn\'t ban due to Bot\'s Role Position');
for (let member of members) {
description.push(`-> ${member}`);
}
}
description.push('');
if (cannotEdit.length) {
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Couldn\'t ban due to Your Role Position');
for (let member of members) {
description.push(`-> ${member}`);
Expand All @@ -181,7 +181,7 @@ export default class BanCommand extends BaseCommand {
}

if (us.length) {
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Cannot Ban Yourself or Myself');
for (let member of members) {
description.push(`-> ${member}`);
Expand Down
12 changes: 6 additions & 6 deletions src/commands/prefixed/moderation/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Permissions } from 'detritus-client/lib/constants';
import { Markup } from 'detritus-client/lib/utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import { Parameters, createTimestampMomentFromGuild, createUserEmbed } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -92,7 +92,7 @@ export default class KickCommand extends BaseCommand {
let reason: string | undefined;
{
const description: Array<string> = [];
description.push(`Admin: ${context.user} (${context.user.id})`);
description.push(`Admin: ${createUserDisplayName(context.user)} (${context.user.id})`);
description.push(`Reason: ${(payload.text) ? Markup.escape.all(payload.text) : '[Unspecified Reason]'}`);
{
const timestamp = createTimestampMomentFromGuild(Date.now(), context.guildId);
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class KickCommand extends BaseCommand {
{
const description: Array<string> = [];
if (canEdit.length) {
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
for (let member of members) {
description.push(`-> ${member}`);
}
Expand All @@ -139,15 +139,15 @@ export default class KickCommand extends BaseCommand {
const description: Array<string> = [];
if (cannotEdit.length || clientCannotEdit.length) {
if (clientCannotEdit.length) {
const members = clientCannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = clientCannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Couldn\'t kick due to Bot\'s Role Position');
for (let member of members) {
description.push(`-> ${member}`);
}
}
description.push('');
if (cannotEdit.length) {
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Couldn\'t kick due to Your Role Position');
for (let member of members) {
description.push(`-> ${member}`);
Expand All @@ -157,7 +157,7 @@ export default class KickCommand extends BaseCommand {
}

if (us.length) {
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Cannot Kick Yourself or Myself');
for (let member of members) {
description.push(`-> ${member}`);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/prefixed/moderation/nick.mass.reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Timers } from 'detritus-utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import ServerExecutionsStore, { ServerExecutionsStored } from '../../../stores/serverexecutions';
import { Parameters, createTimestampMomentFromGuild, createUserEmbed, editOrReply } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -138,7 +138,7 @@ export default class NickMassResetCommand extends BaseCommand {
skipped: 0,
};
const errors: Array<any> = [];
const reason = `Mass Nickname Reset by ${context.user} (${context.user.id})`;
const reason = `Mass Nickname Reset by ${createUserDisplayName(context.user)} (${context.user.id})`;

{
embed.setDescription(`Ok, starting to clear ${membersThatWillBeEdited.toLocaleString()} member\'s nicknames. (Should take about ${((membersThatWillBeEdited / amount) * time).toLocaleString()} seconds)`);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/prefixed/moderation/nick.mass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Timers } from 'detritus-utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import ServerExecutionsStore, { ServerExecutionsStored } from '../../../stores/serverexecutions';
import { Parameters, createTimestampMomentFromGuild, createUserEmbed, editOrReply } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -146,7 +146,7 @@ export default class NickMassCommand extends BaseCommand {
skipped: 0,
};
const errors: Array<any> = [];
const reason = `Mass Nickname change by ${context.user} (${context.user.id})`;
const reason = `Mass Nickname change by ${createUserDisplayName(context.user)} (${context.user.id})`;

{
embed.setDescription(`Ok, starting to edit ${members.length.toLocaleString()} member\'s nicknames. (Should take about ${((members.length / amount) * time).toLocaleString()} seconds)`);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/prefixed/moderation/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Timers } from 'detritus-utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import ServerExecutionsStore from '../../../stores/serverexecutions';
import { DefaultParameters, Parameters, createTimestampMomentFromGuild, createUserEmbed, editOrReply } from '../../../utils';
import { DefaultParameters, Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -348,7 +348,7 @@ export default class PruneCommand extends BaseCommand {
const manualToDelete = manual.filter((message) => message.canDelete && !message.deleted).map((message) => message.id);
deletedTotal += manualToDelete.length;

const reason = `Pruning of ${deletedTotal.toLocaleString()} messages by ${context.user} (${context.user.id})`;
const reason = `Pruning of ${deletedTotal.toLocaleString()} messages by ${createUserDisplayName(context.user)} (${context.user.id})`;
for (let messageId of manualToDelete) {
await context.rest.deleteMessage(channelId, messageId, {reason});
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/prefixed/moderation/unban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Permissions } from 'detritus-client/lib/constants';
import { Markup } from 'detritus-client/lib/utils';

import { CommandCategories, DateMomentLogFormat, EmbedColors } from '../../../constants';
import { Parameters, createTimestampMomentFromGuild, createUserEmbed, editOrReply } from '../../../utils';
import { Parameters, createTimestampMomentFromGuild, createUserDisplayName, createUserEmbed, editOrReply } from '../../../utils';

import { BaseCommand } from '../basecommand';

Expand Down Expand Up @@ -105,7 +105,7 @@ export default class UnbanCommand extends BaseCommand {
let reason: string | undefined;
{
const description: Array<string> = [];
description.push(`Admin: ${context.user} (${context.user.id})`);
description.push(`Admin: ${createUserDisplayName(context.user)} (${context.user.id})`);
description.push(`Reason: ${(payload.text) ? Markup.escape.all(payload.text) : '[Unspecified Reason]'}`);
{
const timestamp = createTimestampMomentFromGuild(Date.now(), context.guildId);
Expand All @@ -126,7 +126,7 @@ export default class UnbanCommand extends BaseCommand {
{
const description: Array<string> = [];
if (canEdit.length) {
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = canEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
for (let member of members) {
description.push(`-> ${member}`);
}
Expand All @@ -146,7 +146,7 @@ export default class UnbanCommand extends BaseCommand {
if (cannotEdit.length) {
description.push('');
if (cannotEdit.length) {
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = cannotEdit.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Couldn\'t unban because they ain\'t banned');
for (let member of members) {
description.push(`-> ${member}`);
Expand All @@ -156,7 +156,7 @@ export default class UnbanCommand extends BaseCommand {
}

if (us.length) {
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${member})`)}`);
const members = us.map((member) => `${member.mention} ${Markup.spoiler(`(${createUserDisplayName(member)})`)}`);
description.push('Cannot Unban Yourself or Myself');
for (let member of members) {
description.push(`-> ${member}`);
Expand Down
9 changes: 5 additions & 4 deletions src/commands/prefixed/owner/seenon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { CommandCategories, DateMomentLogFormat } from '../../../constants';
import {
DefaultParameters,
Paginator,
Parameters,
createTimestampMomentFromGuild,
editOrReply,
Parameters,
createTimestampMomentFromGuild,
createUserDisplayName,
editOrReply,
toTitleCase,
} from '../../../utils';

Expand Down Expand Up @@ -144,7 +145,7 @@ export default class SeenOnCommand extends BaseCommand {
pageLimit,
onPage: (page) => {
const embed = new Embed();
embed.setAuthor(user.toString(), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink);
embed.setAuthor(createUserDisplayName(user), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink);
embed.setColor(Colors.BLURPLE);

const resultNumber = page - 1;
Expand Down
9 changes: 5 additions & 4 deletions src/stores/guildlogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import {
import { RedisSpewer } from '../redis';
import {
createColorUrl,
createTimestampMomentFromGuild,
createTimestampStringFromGuild,
createUserEmbed,
createTimestampMomentFromGuild,
createTimestampStringFromGuild,
createUserDisplayName,
createUserEmbed,
createUserString,
permissionsToObject,
} from '../utils';
Expand Down Expand Up @@ -1734,7 +1735,7 @@ export function createLogPayload(
if (MAX_MENTIONS <= message.mentions.length) {
text.push(`${message.mentions.length.toLocaleString()} Users`);
} else {
text.push(message.mentions.map((user) => `**${Markup.codestring(String(user))}**`).join(', '));
text.push(message.mentions.map((user) => `**${Markup.codestring(createUserDisplayName(user))}**`).join(', '));
}
}
embed.addField('Mentions', `- ${text.join(', ')}`);
Expand Down
11 changes: 6 additions & 5 deletions src/utils/formatter/commands/info.user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
PRESENCE_CLIENT_STATUS_KEYS,
} from '../../../constants';
import {
Paginator,
createTimestampMomentFromContext,
getMemberJoinPosition,
Paginator,
createTimestampMomentFromContext,
createUserDisplayName,
getMemberJoinPosition,
toTitleCase,
} from '../../../utils';

Expand Down Expand Up @@ -100,10 +101,10 @@ export async function createMessage(

if (files.length) {
const file = files[0]!;
embed.setAuthor(user.toString(), `attachment://${file.filename}`, user.jumpLink);
embed.setAuthor(createUserDisplayName(user), `attachment://${file.filename}`, user.jumpLink);
embed.setThumbnail(`attachment://${file.filename}`);
} else {
embed.setAuthor(user.toString(), avatarUrl, user.jumpLink);
embed.setAuthor(createUserDisplayName(user), avatarUrl, user.jumpLink);
embed.setThumbnail(avatarUrl);
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/formatter/commands/media.av.tools.identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DateMomentLogFormat, EmbedBrands, EmbedColors } from '../../../constant
import {
Paginator,
createTimestampMomentFromGuild,
createUserDisplayName,
createUserEmbed,
createUserString,
editOrReply,
Expand Down Expand Up @@ -147,7 +148,7 @@ export async function createMessage(
isEphemeral: args.isEphemeral,
onPage: (page) => {
const embed = new Embed();
embed.setAuthor(user.toString(), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink);
embed.setAuthor(createUserDisplayName(user), user.avatarUrlFormat(null, {size: 1024}), user.jumpLink); // future proofing
embed.setColor(PresenceStatusColors['offline']);
embed.setDescription(user.mention);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/formatter/commands/reminder.list.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function createMessage(
const user = context.users.get(reminder.user.id)!;
noun = createUserString(reminder.user.id, user);
} else {
const name = `${reminder.user.username}#${reminder.user.discriminator}`;
const name = reminder.user.username;
noun = createUserString(reminder.user.id, null, name);
}
text = `${text} by ${noun} (Id: ${reminder.position})`;
Expand Down
30 changes: 20 additions & 10 deletions src/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,30 @@ export function createTimestampStringFromGuild(timestamp: number | string, guild
}


export function createUserEmbed(user: Structures.User, embed: Embed = new Embed()) {
embed.setAuthor(
(user.bot) ? `${user} (BOT)` : user.toString(),
user.avatarUrlFormat(null, {size: 1024}),
user.jumpLink,
);
export function createUserDisplayName(user: Structures.Member | Structures.User): string {
if (user.bot && user.discriminator && user.discriminator !== '0') {
return `${user.username}#${user.discriminator}`;
}
return user.username;
}


export function createUserEmbed(user: Structures.User, embed: Embed = new Embed()) {
const name = createUserDisplayName(user);
embed.setAuthor(
(user.bot) ? `${name} (BOT)` : name,
user.avatarUrlFormat(null, {size: 1024}),
user.jumpLink,
);
return embed;
}


export function createUserString(userId: string = '1', user?: Structures.User | null, name?: string): string {
if (user || name) {
return `<@${userId}> ${Markup.spoiler(`(${Markup.escape.all(String(user || name))})`)}`;
}
export function createUserString(userId: string = '1', user?: Structures.User | null, name?: string): string {
if (user || name) {
const displayName = (user) ? createUserDisplayName(user) : name!;
return `<@${userId}> ${Markup.spoiler(`(${Markup.escape.all(displayName)})`)}`;
}
return `<@${userId}>`;
}

Expand Down