feat: new username support
This commit is contained in:
parent
514e93aa23
commit
0e70412bc4
8 changed files with 42 additions and 20 deletions
|
@ -3,7 +3,7 @@ import moment from "moment-timezone";
|
||||||
import { isDefaultSticker } from "src/utils/isDefaultSticker";
|
import { isDefaultSticker } from "src/utils/isDefaultSticker";
|
||||||
import { Repository, getRepository } from "typeorm";
|
import { Repository, getRepository } from "typeorm";
|
||||||
import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter";
|
import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter";
|
||||||
import { trimLines } from "../utils";
|
import { renderUsername, trimLines } from "../utils";
|
||||||
import { decrypt, encrypt } from "../utils/crypt";
|
import { decrypt, encrypt } from "../utils/crypt";
|
||||||
import { channelToTemplateSafeChannel, guildToTemplateSafeGuild } from "../utils/templateSafeObjects";
|
import { channelToTemplateSafeChannel, guildToTemplateSafeGuild } from "../utils/templateSafeObjects";
|
||||||
import { BaseGuildRepository } from "./BaseGuildRepository";
|
import { BaseGuildRepository } from "./BaseGuildRepository";
|
||||||
|
@ -16,7 +16,7 @@ const MESSAGE_ARCHIVE_HEADER_FORMAT = trimLines(`
|
||||||
Server: {guild.name} ({guild.id})
|
Server: {guild.name} ({guild.id})
|
||||||
`);
|
`);
|
||||||
const MESSAGE_ARCHIVE_MESSAGE_FORMAT =
|
const MESSAGE_ARCHIVE_MESSAGE_FORMAT =
|
||||||
"[#{channel.name}] [{user.id}] [{timestamp}] {user.username}#{user.discriminator}: {content}{attachments}{stickers}";
|
"[#{channel.name}] [{user.id}] [{timestamp}] {username}: {content}{attachments}{stickers}";
|
||||||
|
|
||||||
export class GuildArchives extends BaseGuildRepository<ArchiveEntry> {
|
export class GuildArchives extends BaseGuildRepository<ArchiveEntry> {
|
||||||
protected archives: Repository<ArchiveEntry>;
|
protected archives: Repository<ArchiveEntry>;
|
||||||
|
@ -97,6 +97,7 @@ export class GuildArchives extends BaseGuildRepository<ArchiveEntry> {
|
||||||
}),
|
}),
|
||||||
user: partialUser,
|
user: partialUser,
|
||||||
channel: channel ? channelToTemplateSafeChannel(channel) : null,
|
channel: channel ? channelToTemplateSafeChannel(channel) : null,
|
||||||
|
username: renderUsername(msg.data.author.username, msg.data.author.discriminator),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { ActivityType, Embed } from "discord.js";
|
import { ActivityType, Embed } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
import { SavedMessage } from "../../../data/entities/SavedMessage";
|
||||||
import { resolveMember } from "../../../utils";
|
import { renderUsername, resolveMember } from "../../../utils";
|
||||||
import { DeepMutable } from "../../../utils/typeUtils.js";
|
import { DeepMutable } from "../../../utils/typeUtils.js";
|
||||||
import { AutomodPluginType } from "../types";
|
import { AutomodPluginType } from "../types";
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export async function* matchMultipleTextTypesOnMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.match_usernames) {
|
if (trigger.match_usernames) {
|
||||||
yield ["username", `${msg.data.author.username}#${msg.data.author.discriminator}`];
|
yield ["username", renderUsername(msg.data.author.username, msg.data.author.discriminator)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.match_nicknames && member.nickname) {
|
if (trigger.match_nicknames && member.nickname) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Snowflake } from "discord.js";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { isOwner, sendErrorMessage } from "../../../pluginUtils";
|
import { isOwner, sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { SECONDS, confirm, noop } from "../../../utils";
|
import { SECONDS, confirm, noop, renderUsername } from "../../../utils";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||||
import { rehostAttachment } from "../rehostAttachment";
|
import { rehostAttachment } from "../rehostAttachment";
|
||||||
import { channelArchiverCmd } from "../types";
|
import { channelArchiverCmd } from "../types";
|
||||||
|
@ -68,9 +68,10 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
||||||
|
|
||||||
for (const message of messages.values()) {
|
for (const message of messages.values()) {
|
||||||
const ts = moment.utc(message.createdTimestamp).format("YYYY-MM-DD HH:mm:ss");
|
const ts = moment.utc(message.createdTimestamp).format("YYYY-MM-DD HH:mm:ss");
|
||||||
let content = `[${ts}] [${message.author.id}] [${message.author.username}#${message.author.discriminator}]: ${
|
let content = `[${ts}] [${message.author.id}] [${renderUsername(
|
||||||
message.content || "<no text content>"
|
message.author.username,
|
||||||
}`;
|
message.author.discriminator,
|
||||||
|
)}]: ${message.content || "<no text content>"}`;
|
||||||
|
|
||||||
if (message.attachments.size) {
|
if (message.attachments.size) {
|
||||||
if (args["attachment-channel"]) {
|
if (args["attachment-channel"]) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
isGroupDMInvite,
|
isGroupDMInvite,
|
||||||
isGuildInvite,
|
isGuildInvite,
|
||||||
preEmbedPadding,
|
preEmbedPadding,
|
||||||
|
renderUsername,
|
||||||
resolveInvite,
|
resolveInvite,
|
||||||
trimLines,
|
trimLines,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
|
@ -93,7 +94,7 @@ export async function getInviteInfoEmbed(
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Invite creator",
|
name: preEmbedPadding + "Invite creator",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${invite.inviter.tag}**
|
Name: **${renderUsername(invite.inviter.username, invite.inviter.discriminator)}**
|
||||||
ID: \`${invite.inviter.id}\`
|
ID: \`${invite.inviter.id}\`
|
||||||
Mention: <@!${invite.inviter.id}>
|
Mention: <@!${invite.inviter.id}>
|
||||||
`),
|
`),
|
||||||
|
@ -139,7 +140,7 @@ export async function getInviteInfoEmbed(
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Invite creator",
|
name: preEmbedPadding + "Invite creator",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${invite.inviter.tag}**
|
Name: **${renderUsername(invite.inviter.username, invite.inviter.discriminator)}**
|
||||||
ID: \`${invite.inviter.id}\`
|
ID: \`${invite.inviter.id}\`
|
||||||
Mention: <@!${invite.inviter.id}>
|
Mention: <@!${invite.inviter.id}>
|
||||||
`),
|
`),
|
||||||
|
|
|
@ -2,7 +2,15 @@ import { APIEmbed, MessageType, Snowflake, TextChannel } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub";
|
import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { EmbedWith, chunkMessageLines, messageLink, preEmbedPadding, trimEmptyLines, trimLines } from "../../../utils";
|
import {
|
||||||
|
EmbedWith,
|
||||||
|
chunkMessageLines,
|
||||||
|
messageLink,
|
||||||
|
preEmbedPadding,
|
||||||
|
renderUsername,
|
||||||
|
trimEmptyLines,
|
||||||
|
trimLines,
|
||||||
|
} from "../../../utils";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
|
|
||||||
|
@ -109,7 +117,7 @@ export async function getMessageInfoEmbed(
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Author information",
|
name: preEmbedPadding + "Author information",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${message.author.tag}**
|
Name: **${renderUsername(message.author.username, message.author.discriminator)}**
|
||||||
ID: \`${message.author.id}\`
|
ID: \`${message.author.id}\`
|
||||||
Created: **${authorAccountAge} ago** (\`${prettyAuthorCreatedAt}\`)
|
Created: **${authorAccountAge} ago** (\`${prettyAuthorCreatedAt}\`)
|
||||||
${authorJoinedAt ? `Joined: **${authorServerAge} ago** (\`${prettyAuthorJoinedAt}\`)` : ""}
|
${authorJoinedAt ? `Joined: **${authorServerAge} ago** (\`${prettyAuthorJoinedAt}\`)` : ""}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
inviteHasCounts,
|
inviteHasCounts,
|
||||||
memoize,
|
memoize,
|
||||||
preEmbedPadding,
|
preEmbedPadding,
|
||||||
|
renderUsername,
|
||||||
resolveInvite,
|
resolveInvite,
|
||||||
resolveUser,
|
resolveUser,
|
||||||
trimLines,
|
trimLines,
|
||||||
|
@ -66,7 +67,7 @@ export async function getServerInfoEmbed(
|
||||||
|
|
||||||
if (thisServer) {
|
if (thisServer) {
|
||||||
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
||||||
const ownerName = owner.tag;
|
const ownerName = renderUsername(owner.username, owner.discriminator);
|
||||||
|
|
||||||
basicInformation.push(`Owner: **${ownerName}** (\`${thisServer.ownerId}\`)`);
|
basicInformation.push(`Owner: **${ownerName}** (\`${thisServer.ownerId}\`)`);
|
||||||
// basicInformation.push(`Voice region: **${thisServer.region}**`); Outdated, as automatic voice regions are fully live
|
// basicInformation.push(`Voice region: **${thisServer.region}**`); Outdated, as automatic voice regions are fully live
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
messageLink,
|
messageLink,
|
||||||
preEmbedPadding,
|
preEmbedPadding,
|
||||||
|
renderUsername,
|
||||||
resolveMember,
|
resolveMember,
|
||||||
resolveUser,
|
resolveUser,
|
||||||
sorter,
|
sorter,
|
||||||
|
@ -43,7 +44,7 @@ export async function getUserInfoEmbed(
|
||||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||||
|
|
||||||
embed.author = {
|
embed.author = {
|
||||||
name: `${user.bot ? "Bot" : "User"}: ${user.tag}`,
|
name: `${user.bot ? "Bot" : "User"}: ${renderUsername(user.username, user.discriminator)}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
const avatarURL = user.displayAvatarURL();
|
const avatarURL = user.displayAvatarURL();
|
||||||
|
@ -89,14 +90,16 @@ export async function getUserInfoEmbed(
|
||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userInfoLines = [`ID: \`${user.id}\``, `Username: **${user.username}**`];
|
||||||
|
if (user.discriminator !== "0") {
|
||||||
|
userInfoLines.push(`Discriminator: **${user.discriminator}**`);
|
||||||
|
}
|
||||||
|
userInfoLines.push(`Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)`);
|
||||||
|
userInfoLines.push(`Mention: <@!${user.id}>`);
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`,
|
name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`,
|
||||||
value: trimLines(`
|
value: userInfoLines.join("\n"),
|
||||||
Name: **${user.tag}**
|
|
||||||
ID: \`${user.id}\`
|
|
||||||
Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)
|
|
||||||
Mention: <@!${user.id}>
|
|
||||||
`),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (member) {
|
if (member) {
|
||||||
|
|
|
@ -1602,3 +1602,10 @@ export function isTruthy<T>(value: T): value is Exclude<T, false | null | undefi
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DBDateFormat = "YYYY-MM-DD HH:mm:ss";
|
export const DBDateFormat = "YYYY-MM-DD HH:mm:ss";
|
||||||
|
|
||||||
|
export function renderUsername(username: string, discriminator: string) {
|
||||||
|
if (discriminator === "0") {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
return `${username}#${discriminator}`;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue