mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
commit
392e7fc56e
66 changed files with 142 additions and 212 deletions
|
@ -1,6 +1,6 @@
|
|||
import util from "util";
|
||||
|
||||
export class ErisError extends Error {
|
||||
export class DiscordJSError extends Error {
|
||||
code: number | string | undefined;
|
||||
shardId: number;
|
||||
|
||||
|
@ -11,6 +11,6 @@ export class ErisError extends Error {
|
|||
}
|
||||
|
||||
[util.inspect.custom]() {
|
||||
return `[ERIS] [ERROR CODE ${this.code || "?"}] [SHARD ${this.shardId}] ${this.message}`;
|
||||
return `[DISCORDJS] [ERROR CODE ${this.code ?? "?"}] [SHARD ${this.shardId}] ${this.message}`;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
import { Client, Intents, TextChannel } from "discord.js";
|
||||
import fs from "fs";
|
||||
import yaml from "js-yaml";
|
||||
import { Knub, PluginError } from "knub";
|
||||
import { PluginLoadError } from "knub/dist/plugins/PluginLoadError";
|
||||
|
@ -11,7 +10,7 @@ import { Configs } from "./data/Configs";
|
|||
import { connect } from "./data/db";
|
||||
import { GuildLogs } from "./data/GuildLogs";
|
||||
import { LogType } from "./data/LogType";
|
||||
import { ErisError } from "./ErisError";
|
||||
import { DiscordJSError } from "./DiscordJSError";
|
||||
import "./loadEnv";
|
||||
import { logger } from "./logger";
|
||||
import { baseGuildPlugins, globalPlugins, guildPlugins } from "./plugins/availablePlugins";
|
||||
|
@ -21,8 +20,6 @@ import { ZeppelinGlobalConfig, ZeppelinGuildConfig } from "./types";
|
|||
import { startUptimeCounter } from "./uptime";
|
||||
import { errorMessage, isDiscordAPIError, isDiscordHTTPError, successMessage } from "./utils";
|
||||
|
||||
const fsp = fs.promises;
|
||||
|
||||
if (!process.env.KEY) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.error("Project root .env with KEY is required!");
|
||||
|
@ -81,7 +78,7 @@ function errorHandler(err) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (err instanceof ErisError) {
|
||||
if (err instanceof DiscordJSError) {
|
||||
if (err.code && SAFE_TO_IGNORE_ERIS_ERROR_CODES.includes(err.code)) {
|
||||
return;
|
||||
}
|
||||
|
@ -176,14 +173,12 @@ connect().then(async () => {
|
|||
});
|
||||
client.setMaxListeners(200);
|
||||
|
||||
client.on("debug", message => {
|
||||
if (message.includes(" 429 ")) {
|
||||
logger.info(`[429] ${message}`);
|
||||
}
|
||||
client.on("rateLimit", rateLimitData => {
|
||||
logger.info(`[429] ${JSON.stringify(rateLimitData)}`);
|
||||
});
|
||||
|
||||
client.on("error", err => {
|
||||
errorHandler(new ErisError(err.message, (err as any).code, 0));
|
||||
errorHandler(new DiscordJSError(err.message, (err as any).code, 0));
|
||||
});
|
||||
|
||||
const allowedGuilds = new AllowedGuilds();
|
||||
|
@ -266,5 +261,5 @@ connect().then(async () => {
|
|||
bot.initialize();
|
||||
logger.info("Bot Initialized");
|
||||
logger.info("Logging in...");
|
||||
await client.login(process.env.token);
|
||||
await client.login(process.env.TOKEN);
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ export function runAutomodOnMessage(
|
|||
message: SavedMessage,
|
||||
isEdit: boolean,
|
||||
) {
|
||||
const user = pluginData.client.users.cache!.get(message.user_id as Snowflake);
|
||||
const user = pluginData.client.users.cache.get(message.user_id as Snowflake);
|
||||
const member = pluginData.guild.members.cache.get(message.user_id as Snowflake);
|
||||
|
||||
const context: AutomodContext = {
|
||||
|
|
|
@ -37,7 +37,7 @@ export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
|||
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
const memberName = `**${member.user.tag}** (\`${member.id}\`)`;
|
||||
return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was added to ${memberName}`;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@ export const RoleRemovedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
|||
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake);
|
||||
const roleName = role?.name || "Unknown";
|
||||
const member = contexts[0].member!;
|
||||
const memberName = `**${member.user.username}#${member.user.discriminator}** (\`${member.id}\`)`;
|
||||
const memberName = `**${member.user.tag}** (\`${member.id}\`)`;
|
||||
return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was removed from ${memberName}`;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -35,9 +35,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, user.id, [ApiPermissions.EditConfig]);
|
||||
}
|
||||
|
||||
const userNameList = args.users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
const userNameList = args.users.map(user => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
|
|
|
@ -46,7 +46,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
|
||||
// If we have user, always display which guilds they have permissions in (or only specified guild permissions)
|
||||
if (args.user) {
|
||||
const userInfo = `**${args.user.username}#${args.user.discriminator}** (\`${args.user.id}\`)`;
|
||||
const userInfo = `**${args.user.tag}** (\`${args.user.id}\`)`;
|
||||
|
||||
for (const assignment of existingUserAssignment!) {
|
||||
if (guild != null && assignment.guild_id !== args.guildId) continue;
|
||||
|
@ -82,9 +82,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
finalMessage += `The server ${guildInfo} has the following assigned permissions:\n`; // Double \n for consistency with AddDashboardUserCmd
|
||||
for (const assignment of existingGuildAssignment) {
|
||||
const user = await resolveUser(pluginData.client, assignment.target_id);
|
||||
finalMessage += `\n**${user.username}#${user.discriminator}**, \`${
|
||||
assignment.target_id
|
||||
}\`: ${assignment.permissions.join(", ")}`;
|
||||
finalMessage += `\n**${user.tag}**, \`${assignment.target_id}\`: ${assignment.permissions.join(", ")}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,7 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
|
||||
const dashboardUsers = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
|
||||
const users = await Promise.all(dashboardUsers.map(perm => resolveUser(pluginData.client, perm.target_id)));
|
||||
const userNameList = users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
const userNameList = users.map(user => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
|
|
|
@ -34,9 +34,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
await pluginData.state.apiPermissionAssignments.removeUser(args.guildId, user.id);
|
||||
}
|
||||
|
||||
const userNameList = args.users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
const userNameList = args.users.map(user => `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
|
|
|
@ -49,7 +49,7 @@ export const ServersCmd = botControlCmd({
|
|||
const lines = filteredGuilds.map(g => {
|
||||
const paddedId = g.id.padEnd(longestId, " ");
|
||||
const owner = getUser(pluginData.client, g.ownerId);
|
||||
return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${owner.username}#${owner.discriminator}** \`${owner.id}\`)`;
|
||||
return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${owner.tag}** \`${owner.id}\`)`;
|
||||
});
|
||||
createChunkedMessage(msg.channel as TextChannel, lines.join("\n"));
|
||||
} else {
|
||||
|
|
|
@ -7,15 +7,15 @@ import { postCaseToCaseLogChannel } from "./postToCaseLogChannel";
|
|||
|
||||
export async function createCase(pluginData: GuildPluginData<CasesPluginType>, args: CaseArgs) {
|
||||
const user = await resolveUser(pluginData.client, args.userId);
|
||||
const userName = `${user.username}#${user.discriminator}`;
|
||||
const userName = `${user.tag}`;
|
||||
|
||||
const mod = await resolveUser(pluginData.client, args.modId);
|
||||
const modName = `${mod.username}#${mod.discriminator}`;
|
||||
const modName = `${mod.tag}`;
|
||||
|
||||
let ppName: string | null = null;
|
||||
if (args.ppId) {
|
||||
const pp = await resolveUser(pluginData.client, args.ppId);
|
||||
ppName = `${pp.username}#${pp.discriminator}`;
|
||||
ppName = `${pp.tag}`;
|
||||
}
|
||||
|
||||
if (args.auditLogId) {
|
||||
|
|
|
@ -16,7 +16,7 @@ export async function createCaseNote(pluginData: GuildPluginData<CasesPluginType
|
|||
throw new RecoverablePluginError(ERRORS.INVALID_USER);
|
||||
}
|
||||
|
||||
const modName = `${mod.username}#${mod.discriminator}`;
|
||||
const modName = `${mod.tag}`;
|
||||
|
||||
let body = args.body;
|
||||
|
||||
|
|
|
@ -60,10 +60,10 @@ export const ArchiveChannelCmd = channelArchiverCmd({
|
|||
|
||||
while (archivedMessages < maxMessagesToArchive) {
|
||||
const messagesToFetch = Math.min(MAX_MESSAGES_PER_FETCH, maxMessagesToArchive - archivedMessages);
|
||||
const messages = (await args.channel.messages.fetch({
|
||||
const messages = await args.channel.messages.fetch({
|
||||
limit: messagesToFetch,
|
||||
before: previousId as Snowflake,
|
||||
})) as Collection<Snowflake, Message>;
|
||||
});
|
||||
if (messages.size === 0) break;
|
||||
|
||||
for (const message of messages.values()) {
|
||||
|
|
|
@ -16,7 +16,7 @@ export const LogsGuildBanAddEvt = logsEvt({
|
|||
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
|
||||
user.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||
const mod = relevantAuditLogEntry?.executor ?? null;
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MEMBER_BAN,
|
||||
|
@ -41,7 +41,7 @@ export const LogsGuildBanRemoveEvt = logsEvt({
|
|||
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
|
||||
user.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||
const mod = relevantAuditLogEntry?.executor ?? null;
|
||||
|
||||
pluginData.state.guildLogs.log(
|
||||
LogType.MEMBER_UNBAN,
|
||||
|
|
|
@ -52,7 +52,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
GuildAuditLogs.Actions.MEMBER_ROLE_UPDATE as number,
|
||||
member.id,
|
||||
);
|
||||
const mod = relevantAuditLogEntry ? relevantAuditLogEntry.executor : null;
|
||||
const mod = relevantAuditLogEntry?.executor ?? null;
|
||||
|
||||
if (addedRoles.length && removedRoles.length) {
|
||||
// Roles added *and* removed
|
||||
|
@ -61,11 +61,11 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
addedRoles: addedRoles
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.join(", "),
|
||||
removedRoles: removedRoles
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.join(", "),
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||
|
@ -79,7 +79,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
roles: addedRoles
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.join(", "),
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||
|
@ -93,7 +93,7 @@ export const LogsGuildMemberUpdateEvt = logsEvt({
|
|||
{
|
||||
member: logMember,
|
||||
roles: removedRoles
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) || { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(roleId => pluginData.guild.roles.cache.get(roleId) ?? { id: roleId, name: `Unknown (${roleId})` })
|
||||
.map(r => r.name)
|
||||
.join(", "),
|
||||
mod: mod ? userToConfigAccessibleUser(mod) : {},
|
||||
|
|
|
@ -73,11 +73,7 @@ export const AddCaseCmd = modActionsCmd({
|
|||
});
|
||||
|
||||
if (user) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Case #${theCase.case_number} created for **${user.username}#${user.discriminator}**`,
|
||||
);
|
||||
sendSuccessMessage(pluginData, msg.channel, `Case #${theCase.case_number} created for **${user.tag}**`);
|
||||
} else {
|
||||
sendSuccessMessage(pluginData, msg.channel, `Case #${theCase.case_number} created`);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ export const BanCmd = modActionsCmd({
|
|||
// Confirm the action to the moderator
|
||||
let response = "";
|
||||
if (!forceban) {
|
||||
response = `Banned **${user.username}#${user.discriminator}** ${forTime}(Case #${banResult.case.case_number})`;
|
||||
response = `Banned **${user.tag}** ${forTime}(Case #${banResult.case.case_number})`;
|
||||
if (banResult.notifyResult.text) response += ` (${banResult.notifyResult.text})`;
|
||||
} else {
|
||||
response = `Member forcebanned ${forTime}(Case #${banResult.case.case_number})`;
|
||||
|
|
|
@ -29,7 +29,7 @@ export const CasesModCmd = modActionsCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const modId = args.mod || msg.author.id;
|
||||
const mod = await resolveUser(pluginData.client, modId);
|
||||
const modName = mod instanceof User ? `${mod.username}#${mod.discriminator}` : modId;
|
||||
const modName = mod instanceof User ? `${mod.tag}` : modId;
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const totalCases = await casesPlugin.getTotalCasesByMod(modId);
|
||||
|
@ -57,7 +57,7 @@ export const CasesModCmd = modActionsCmd({
|
|||
const embed: MessageEmbedOptions = {
|
||||
author: {
|
||||
name: title,
|
||||
iconURL: mod instanceof User ? mod.avatarURL() || mod.defaultAvatarURL : undefined,
|
||||
iconURL: mod instanceof User ? mod.displayAvatarURL() : undefined,
|
||||
},
|
||||
fields: [
|
||||
...getChunkedEmbedFields(emptyEmbedValue, lines.join("\n")),
|
||||
|
|
|
@ -61,10 +61,7 @@ export const CasesUserCmd = modActionsCmd({
|
|||
const normalCases = cases.filter(c => !c.is_hidden);
|
||||
const hiddenCases = cases.filter(c => c.is_hidden);
|
||||
|
||||
const userName =
|
||||
user instanceof UnknownUser && cases.length
|
||||
? cases[cases.length - 1].user_name
|
||||
: `${user.username}#${user.discriminator}`;
|
||||
const userName = user instanceof UnknownUser && cases.length ? cases[cases.length - 1].user_name : `${user.tag}`;
|
||||
|
||||
if (cases.length === 0) {
|
||||
msg.channel.send(`No cases found for **${userName}**`);
|
||||
|
@ -119,7 +116,7 @@ export const CasesUserCmd = modActionsCmd({
|
|||
lineChunks.length === 1
|
||||
? `Cases for ${userName} (${lines.length} total)`
|
||||
: `Cases ${chunkStart}–${chunkEnd} of ${lines.length} for ${userName}`,
|
||||
icon_url: user instanceof User ? user.avatarURL() || user.defaultAvatarURL : undefined,
|
||||
icon_url: user instanceof User ? user.displayAvatarURL() : undefined,
|
||||
},
|
||||
fields: [
|
||||
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
|
||||
|
|
|
@ -68,7 +68,7 @@ export const DeleteCaseCmd = modActionsCmd({
|
|||
}
|
||||
}
|
||||
|
||||
const deletedByName = `${message.author.username}#${message.author.discriminator}`;
|
||||
const deletedByName = `${message.author.tag}`;
|
||||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
const deletedAt = timeAndDate.inGuildTz().format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
|
|
|
@ -70,7 +70,7 @@ export const ForcebanCmd = modActionsCmd({
|
|||
// FIXME: Use banUserId()?
|
||||
await pluginData.guild.bans.create(user.id as Snowflake, {
|
||||
days: 1,
|
||||
reason: reason != null ? encodeURIComponent(reason) : undefined,
|
||||
reason: reason ?? undefined,
|
||||
});
|
||||
} catch {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to forceban member");
|
||||
|
|
|
@ -95,7 +95,7 @@ export const MassbanCmd = modActionsCmd({
|
|||
|
||||
await pluginData.guild.bans.create(userId as Snowflake, {
|
||||
days: deleteDays,
|
||||
reason: banReason != null ? encodeURIComponent(banReason) : undefined,
|
||||
reason: banReason ?? undefined,
|
||||
});
|
||||
|
||||
await casesPlugin.createCase({
|
||||
|
|
|
@ -60,10 +60,7 @@ export const MassunbanCmd = modActionsCmd({
|
|||
}
|
||||
|
||||
try {
|
||||
await pluginData.guild.bans.remove(
|
||||
userId as Snowflake,
|
||||
unbanReason != null ? encodeURIComponent(unbanReason) : undefined,
|
||||
);
|
||||
await pluginData.guild.bans.remove(userId as Snowflake, unbanReason ?? undefined);
|
||||
|
||||
await casesPlugin.createCase({
|
||||
userId,
|
||||
|
|
|
@ -30,7 +30,7 @@ export const NoteCmd = modActionsCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const userName = `${user.username}#${user.discriminator}`;
|
||||
const userName = `${user.tag}`;
|
||||
const reason = formatReasonWithAttachments(args.note, msg.attachments.array());
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
|
|
|
@ -51,7 +51,7 @@ export const UnbanCmd = modActionsCmd({
|
|||
|
||||
try {
|
||||
ignoreEvent(pluginData, IgnoredEventType.Unban, user.id);
|
||||
await pluginData.guild.bans.remove(user.id as Snowflake, reason != null ? encodeURIComponent(reason) : undefined);
|
||||
await pluginData.guild.bans.remove(user.id as Snowflake, reason ?? undefined);
|
||||
} catch {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?");
|
||||
return;
|
||||
|
|
|
@ -107,7 +107,7 @@ export const WarnCmd = modActionsCmd({
|
|||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
||||
`Warned **${memberToWarn.user.tag}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -44,7 +44,7 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt({
|
|||
const config = mod instanceof UnknownUser ? pluginData.config.get() : await pluginData.config.getForUser(mod);
|
||||
|
||||
if (config.create_cases_for_manual_actions) {
|
||||
reason = relevantAuditLogEntry.reason || "";
|
||||
reason = relevantAuditLogEntry.reason ?? "";
|
||||
createdCase = await casesPlugin.createCase({
|
||||
userId: user.id,
|
||||
modId,
|
||||
|
|
|
@ -47,7 +47,7 @@ export const PostAlertOnMemberJoinEvt = modActionsEvt({
|
|||
}
|
||||
|
||||
await alertChannel.send(
|
||||
`<@!${member.id}> (${member.user.username}#${member.user.discriminator} \`${member.id}\`) joined with ${actions.length} prior record(s)`,
|
||||
`<@!${member.id}> (${member.user.tag} \`${member.id}\`) joined with ${actions.length} prior record(s)`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -82,7 +82,7 @@ export async function actualKickMemberCmd(
|
|||
ignoreEvent(pluginData, IgnoredEventType.Ban, memberToKick.id);
|
||||
|
||||
try {
|
||||
await memberToKick.ban({ days: 1, reason: encodeURIComponent("kick -clean") });
|
||||
await memberToKick.ban({ days: 1, reason: "kick -clean" });
|
||||
} catch {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)");
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export async function actualKickMemberCmd(
|
|||
ignoreEvent(pluginData, IgnoredEventType.Unban, memberToKick.id);
|
||||
|
||||
try {
|
||||
await pluginData.guild.bans.remove(memberToKick.id, encodeURIComponent("kick -clean"));
|
||||
await pluginData.guild.bans.remove(memberToKick.id, "kick -clean");
|
||||
} catch {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)");
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ export async function actualKickMemberCmd(
|
|||
}
|
||||
|
||||
// Confirm the action to the moderator
|
||||
let response = `Kicked **${memberToKick.user.username}#${memberToKick.user.discriminator}** (Case #${kickResult.case.case_number})`;
|
||||
let response = `Kicked **${memberToKick.user.tag}** (Case #${kickResult.case.case_number})`;
|
||||
|
||||
if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`;
|
||||
sendSuccessMessage(pluginData, msg.channel, response);
|
||||
|
|
|
@ -85,24 +85,24 @@ export async function actualMuteUserCmd(
|
|||
if (args.time) {
|
||||
if (muteResult.updatedExistingMute) {
|
||||
response = asSingleLine(`
|
||||
Updated **${user.username}#${user.discriminator}**'s
|
||||
Updated **${user.tag}**'s
|
||||
mute to ${timeUntilUnmute} (Case #${muteResult.case.case_number})
|
||||
`);
|
||||
} else {
|
||||
response = asSingleLine(`
|
||||
Muted **${user.username}#${user.discriminator}**
|
||||
Muted **${user.tag}**
|
||||
for ${timeUntilUnmute} (Case #${muteResult.case.case_number})
|
||||
`);
|
||||
}
|
||||
} else {
|
||||
if (muteResult.updatedExistingMute) {
|
||||
response = asSingleLine(`
|
||||
Updated **${user.username}#${user.discriminator}**'s
|
||||
Updated **${user.tag}**'s
|
||||
mute to indefinite (Case #${muteResult.case.case_number})
|
||||
`);
|
||||
} else {
|
||||
response = asSingleLine(`
|
||||
Muted **${user.username}#${user.discriminator}**
|
||||
Muted **${user.tag}**
|
||||
indefinitely (Case #${muteResult.case.case_number})
|
||||
`);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export async function actualUnmuteCmd(
|
|||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
asSingleLine(`
|
||||
Unmuting **${user.username}#${user.discriminator}**
|
||||
Unmuting **${user.tag}**
|
||||
in ${timeUntilUnmute} (Case #${result.case.case_number})
|
||||
`),
|
||||
);
|
||||
|
@ -57,7 +57,7 @@ export async function actualUnmuteCmd(
|
|||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
asSingleLine(`
|
||||
Unmuted **${user.username}#${user.discriminator}**
|
||||
Unmuted **${user.tag}**
|
||||
(Case #${result.case.case_number})
|
||||
`),
|
||||
);
|
||||
|
|
|
@ -80,7 +80,7 @@ export async function banUserId(
|
|||
const deleteMessageDays = Math.min(30, Math.max(0, banOptions.deleteMessageDays ?? 1));
|
||||
await pluginData.guild.bans.create(userId as Snowflake, {
|
||||
days: deleteMessageDays,
|
||||
reason: reason != null ? encodeURIComponent(reason) : undefined,
|
||||
reason: reason ?? undefined,
|
||||
});
|
||||
} catch (e) {
|
||||
let errorMessage;
|
||||
|
|
|
@ -49,7 +49,7 @@ export async function kickMember(
|
|||
pluginData.state.serverLogs.ignoreLog(LogType.MEMBER_KICK, member.id);
|
||||
ignoreEvent(pluginData, IgnoredEventType.Kick, member.id);
|
||||
try {
|
||||
await member.kick(reason != null ? encodeURIComponent(reason) : undefined);
|
||||
await member.kick(reason ?? undefined);
|
||||
} catch (e) {
|
||||
return {
|
||||
status: "failed",
|
||||
|
|
|
@ -32,10 +32,7 @@ export async function outdatedTempbansLoop(pluginData: GuildPluginData<ModAction
|
|||
);
|
||||
try {
|
||||
ignoreEvent(pluginData, IgnoredEventType.Unban, tempban.user_id);
|
||||
await pluginData.guild.bans.remove(
|
||||
tempban.user_id as Snowflake,
|
||||
reason != null ? encodeURIComponent(reason) : undefined,
|
||||
);
|
||||
await pluginData.guild.bans.remove(tempban.user_id as Snowflake, reason ?? undefined);
|
||||
} catch (e) {
|
||||
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
|
||||
body: `Encountered an error trying to automatically unban ${tempban.user_id} after tempban timeout`,
|
||||
|
|
|
@ -12,7 +12,7 @@ export const ClearBannedMutesCmd = mutesCmd({
|
|||
|
||||
const activeMutes = await pluginData.state.mutes.getActiveMutes();
|
||||
|
||||
const bans: Array<{ reason: string; user: User }> = (await pluginData.guild.bans.fetch({ cache: true })) as any;
|
||||
const bans = await pluginData.guild.bans.fetch({ cache: true });
|
||||
const bannedIds = bans.map(b => b.user.id);
|
||||
|
||||
await msg.channel.send(`Found ${activeMutes.length} mutes and ${bannedIds.length} bans, cross-referencing...`);
|
||||
|
|
|
@ -67,7 +67,7 @@ export const MutesCmd = mutesCmd({
|
|||
totalMutes = manuallyMutedMembers.length;
|
||||
|
||||
lines = manuallyMutedMembers.map(member => {
|
||||
return `<@!${member.id}> (**${member.user.username}#${member.user.discriminator}**, \`${member.id}\`) 🔧 Manual mute`;
|
||||
return `<@!${member.id}> (**${member.user.tag}**, \`${member.id}\`) 🔧 Manual mute`;
|
||||
});
|
||||
} else {
|
||||
// Show filtered active mutes (but not manual mutes)
|
||||
|
@ -119,7 +119,7 @@ export const MutesCmd = mutesCmd({
|
|||
|
||||
lines = filteredMutes.map(mute => {
|
||||
const user = pluginData.client.users.resolve(mute.user_id as Snowflake);
|
||||
const username = user ? `${user.username}#${user.discriminator}` : "Unknown#0000";
|
||||
const username = user ? `${user.tag}` : "Unknown#0000";
|
||||
const theCase = muteCasesById.get(mute.case_id);
|
||||
const caseName = theCase ? `Case #${theCase.case_number}` : "No case";
|
||||
|
||||
|
@ -225,14 +225,11 @@ export const MutesCmd = mutesCmd({
|
|||
interaction.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true });
|
||||
} else {
|
||||
collector.resetTimer();
|
||||
await interaction.deferUpdate();
|
||||
if (interaction.customId === `previousButton:${idMod}` && currentPage > 1) {
|
||||
await interaction.deferUpdate();
|
||||
await drawListPage(currentPage - 1);
|
||||
} else if (interaction.customId === `nextButton:${idMod}` && currentPage < totalPages) {
|
||||
await interaction.deferUpdate();
|
||||
await drawListPage(currentPage + 1);
|
||||
} else {
|
||||
await interaction.deferUpdate();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -90,7 +90,7 @@ export async function muteUser(
|
|||
try {
|
||||
await member.roles.add(muteRole as Snowflake);
|
||||
} catch (e) {
|
||||
const actualMuteRole = pluginData.guild.roles.cache.find(x => x.id === muteRole);
|
||||
const actualMuteRole = pluginData.guild.roles.cache.get(muteRole as Snowflake);
|
||||
if (!actualMuteRole) {
|
||||
lock.unlock();
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
|
|
|
@ -31,7 +31,7 @@ export const NamesCmd = nameHistoryCmd({
|
|||
const usernameRows = usernames.map(r => `\`[${r.timestamp}]\` **${disableCodeBlocks(r.username)}**`);
|
||||
|
||||
const user = await pluginData.client.users.fetch(args.userId as Snowflake);
|
||||
const currentUsername = user ? `${user.username}#${user.discriminator}` : args.userId;
|
||||
const currentUsername = user ? `${user.tag}` : args.userId;
|
||||
|
||||
const nicknameDays = Math.round(NICKNAME_RETENTION_PERIOD / DAYS);
|
||||
const usernameDays = Math.round(NICKNAME_RETENTION_PERIOD / DAYS);
|
||||
|
|
|
@ -6,10 +6,7 @@ export const ChannelJoinEvt = nameHistoryEvt({
|
|||
|
||||
async listener(meta) {
|
||||
meta.pluginData.state.updateQueue.add(() =>
|
||||
updateNickname(
|
||||
meta.pluginData,
|
||||
meta.args.newState.member ? meta.args.newState.member : meta.args.oldState.member!,
|
||||
),
|
||||
updateNickname(meta.pluginData, meta.args.newState.member ?? meta.args.oldState.member!),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -138,7 +138,7 @@ export async function actualPostCmd(
|
|||
|
||||
await pluginData.state.scheduledPosts.create({
|
||||
author_id: msg.author.id,
|
||||
author_name: `${msg.author.username}#${msg.author.discriminator}`,
|
||||
author_name: `${msg.author.tag}`,
|
||||
channel_id: targetChannel.id,
|
||||
content,
|
||||
attachments: msg.attachments.array(),
|
||||
|
|
|
@ -55,7 +55,7 @@ export const ButtonInteractionEvt = reactionRolesEvt({
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, group **${context.groupName}** not found in config`,
|
||||
`**A configuration error occurred** on buttons for message ${int.message.id}, group **${context.groupName}** not found in config`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export const ButtonInteractionEvt = reactionRolesEvt({
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A internal error occured** on buttons for message ${int.message.id}, action **${context.action}** is not known`,
|
||||
`**A internal error occurred** on buttons for message ${int.message.id}, action **${context.action}** is not known`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,7 @@ export async function addMemberPendingRoleChange(
|
|||
"Reaction roles",
|
||||
);
|
||||
} catch (e) {
|
||||
logger.warn(
|
||||
`Failed to apply role changes to ${member.user.username}#${member.user.discriminator} (${member.id}): ${e.message}`,
|
||||
);
|
||||
logger.warn(`Failed to apply role changes to ${member.user.tag} (${member.id}): ${e.message}`);
|
||||
}
|
||||
}
|
||||
lock.unlock();
|
||||
|
|
|
@ -22,7 +22,7 @@ export async function handleOpenMenu(
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, no menus found in config`,
|
||||
`**A configuration error occurred** on buttons for message ${int.message.id}, no menus found in config`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -52,14 +52,13 @@ export async function handleOpenMenu(
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, menu **${context.roleOrMenu}** not found in config`,
|
||||
`**A configuration error occurred** on buttons for message ${int.message.id}, menu **${context.roleOrMenu}** not found in config`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const rows = splitButtonsIntoRows(menuButtons, Object.values(group.button_menus[context.roleOrMenu])); // new MessageActionRow().addComponents(menuButtons);
|
||||
|
||||
int.reply({ content: `Click to add/remove a role`, components: rows, ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
export async function handleModifyRole(
|
||||
|
@ -78,7 +77,7 @@ export async function handleModifyRole(
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, role **${context.roleOrMenu}** not found on server`,
|
||||
`**A configuration error occurred** on buttons for message ${int.message.id}, role **${context.roleOrMenu}** not found on server`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -101,10 +100,7 @@ export async function handleModifyRole(
|
|||
.getPlugin(LogsPlugin)
|
||||
.log(
|
||||
LogType.BOT_ALERT,
|
||||
`**A configuration error occured** on buttons for message ${int.message.id}, error: ${e}. We might be missing permissions!`,
|
||||
`**A configuration error occurred** on buttons for message ${int.message.id}, error: ${e}. We might be missing permissions!`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ export const SlowmodeClearCmd = slowmodeCmd({
|
|||
pluginData,
|
||||
msg.channel,
|
||||
asSingleLine(`
|
||||
Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>:
|
||||
Failed to clear slowmode from **${args.user.tag}** in <#${args.channel.id}>:
|
||||
Threads cannot have Bot Slowmode
|
||||
`),
|
||||
);
|
||||
|
@ -56,17 +56,13 @@ export const SlowmodeClearCmd = slowmodeCmd({
|
|||
pluginData,
|
||||
msg.channel,
|
||||
asSingleLine(`
|
||||
Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>:
|
||||
Failed to clear slowmode from **${args.user.tag}** in <#${args.channel.id}>:
|
||||
\`${disableInlineCode(e.message)}\`
|
||||
`),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Slowmode cleared from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>`,
|
||||
);
|
||||
sendSuccessMessage(pluginData, msg.channel, `Slowmode cleared from **${args.user.tag}** in <#${args.channel.id}>`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -89,7 +89,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
|
||||
if (mode === "native") {
|
||||
const missingPermissions = getMissingPermissions(
|
||||
channelPermissions ? channelPermissions : new Permissions(),
|
||||
channelPermissions ?? new Permissions(),
|
||||
NATIVE_SLOWMODE_PERMISSIONS,
|
||||
);
|
||||
if (missingPermissions) {
|
||||
|
@ -104,7 +104,7 @@ export const SlowmodeSetCmd = slowmodeCmd({
|
|||
|
||||
if (mode === "bot") {
|
||||
const missingPermissions = getMissingPermissions(
|
||||
channelPermissions ? channelPermissions : new Permissions(),
|
||||
channelPermissions ?? new Permissions(),
|
||||
BOT_SLOWMODE_PERMISSIONS,
|
||||
);
|
||||
if (missingPermissions) {
|
||||
|
|
|
@ -21,7 +21,7 @@ export async function applyBotSlowmodeToUserId(
|
|||
await channel.permissionOverwrites.create(userId as Snowflake, { SEND_MESSAGES: false }, { type: 1 });
|
||||
}
|
||||
} catch (e) {
|
||||
const user = (await pluginData.client.users.fetch(userId as Snowflake)) || new UnknownUser({ id: userId });
|
||||
const user = await pluginData.client.users.fetch(userId as Snowflake).catch(() => new UnknownUser({ id: userId }));
|
||||
|
||||
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||
logger.warn(
|
||||
|
|
|
@ -21,8 +21,9 @@ export async function clearExpiredSlowmodes(pluginData: GuildPluginData<Slowmode
|
|||
} catch (e) {
|
||||
logger.error(e);
|
||||
|
||||
const realUser =
|
||||
pluginData.client.users!.fetch(user.user_id as Snowflake) || new UnknownUser({ id: user.user_id });
|
||||
const realUser = await pluginData.client
|
||||
.users!.fetch(user.user_id as Snowflake)
|
||||
.catch(() => new UnknownUser({ id: user.user_id }));
|
||||
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
|
||||
|
|
|
@ -120,8 +120,8 @@ export async function logAndDetectMessageSpam(
|
|||
// Then, if enabled, remove the spam messages
|
||||
if (spamConfig.clean !== false) {
|
||||
msgIds.forEach(id => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
|
||||
(pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake)! as TextChannel)
|
||||
.bulkDelete(msgIds as Snowflake[])
|
||||
(pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake)! as TextChannel | undefined)
|
||||
?.bulkDelete(msgIds as Snowflake[])
|
||||
.catch(noop);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,19 +18,17 @@ export function createStarboardEmbedFromMessage(
|
|||
text: `#${(msg.channel as GuildChannel).name}`,
|
||||
},
|
||||
author: {
|
||||
name: `${msg.author.username}#${msg.author.discriminator}`,
|
||||
name: `${msg.author.tag}`,
|
||||
},
|
||||
fields: [],
|
||||
timestamp: msg.createdAt,
|
||||
timestamp: msg.createdTimestamp,
|
||||
};
|
||||
|
||||
if (color != null) {
|
||||
embed.color = color;
|
||||
}
|
||||
|
||||
if (msg.author.avatarURL()) {
|
||||
embed.author.icon_url = msg.author.avatarURL()!;
|
||||
}
|
||||
embed.author.icon_url = msg.author.displayAvatarURL({ dynamic: true });
|
||||
|
||||
// The second condition here checks for messages with only an image link that is then embedded.
|
||||
// The message content in that case is hidden by the Discord client, so we hide it here too.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Message, MessageEmbed, Snowflake, TextChannel } from "discord.js";
|
||||
import { Message, MessageEmbedOptions, Snowflake, TextChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { StarboardPluginType, TStarboardOpts } from "../types";
|
||||
import { createStarboardEmbedFromMessage } from "./createStarboardEmbedFromMessage";
|
||||
|
@ -16,6 +16,6 @@ export async function saveMessageToStarboard(
|
|||
const embed = createStarboardEmbedFromMessage(msg, Boolean(starboard.copy_full_embed), starboard.color);
|
||||
embed.fields!.push(createStarboardPseudoFooterForMessage(starboard, msg, starboard.star_emoji![0], starCount));
|
||||
|
||||
const starboardMessage = await (channel as TextChannel).send({ embeds: [embed as MessageEmbed] });
|
||||
const starboardMessage = await (channel as TextChannel).send({ embeds: [embed as MessageEmbedOptions] });
|
||||
await pluginData.state.starboardMessages.createStarboardMessage(channel.id, msg.id, starboardMessage.id);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { UsernameSaverPluginType } from "./types";
|
|||
|
||||
export async function updateUsername(pluginData: GuildPluginData<UsernameSaverPluginType>, user: User) {
|
||||
if (!user) return;
|
||||
const newUsername = `${user.username}#${user.discriminator}`;
|
||||
const newUsername = `${user.tag}`;
|
||||
const latestEntry = await pluginData.state.usernameHistory.getLastEntry(user.id);
|
||||
if (!latestEntry || newUsername !== latestEntry.username) {
|
||||
await pluginData.state.usernameHistory.addEntry(user.id, newUsername);
|
||||
|
|
|
@ -39,8 +39,6 @@ export const AboutCmd = utilityCmd({
|
|||
version = "?";
|
||||
}
|
||||
|
||||
// const shard = pluginData.client.shards.get(pluginData.client.guildShardMap[pluginData.guild.id])!; FIXME Sharding stuff
|
||||
|
||||
const lastReload = humanizeDuration(Date.now() - pluginData.state.lastReload, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
|
@ -51,7 +49,7 @@ export const AboutCmd = utilityCmd({
|
|||
["Last reload", `${lastReload} ago`],
|
||||
["Last update", lastUpdate],
|
||||
["Version", version],
|
||||
// ["API latency", `${shard.latency}ms`],
|
||||
["API latency", `${pluginData.client.ws.ping}ms`],
|
||||
["Server timezone", timeAndDate.getGuildTz()],
|
||||
];
|
||||
|
||||
|
@ -70,11 +68,7 @@ export const AboutCmd = utilityCmd({
|
|||
fields: [
|
||||
{
|
||||
name: "Status",
|
||||
value: basicInfoRows
|
||||
.map(([label, value]) => {
|
||||
return `${label}: **${value}**`;
|
||||
})
|
||||
.join("\n"),
|
||||
value: basicInfoRows.map(([label, value]) => `${label}: **${value}**`).join("\n"),
|
||||
},
|
||||
{
|
||||
name: `Loaded plugins on this server (${loadedPlugins.length})`,
|
||||
|
|
|
@ -16,15 +16,12 @@ export const AvatarCmd = utilityCmd({
|
|||
async run({ message: msg, args, pluginData }) {
|
||||
const user = args.user || msg.author;
|
||||
if (!(user instanceof UnknownUser)) {
|
||||
const avatar = user.avatarURL() || user.defaultAvatarURL;
|
||||
let extension = avatar.slice(avatar.lastIndexOf("."), avatar.lastIndexOf("?"));
|
||||
// Some pngs can have the .jpg extention for some reason, so we always use .png for static images
|
||||
extension = extension === ".gif" ? extension : ".png";
|
||||
const avatarUrl = avatar.slice(0, avatar.lastIndexOf("."));
|
||||
const embed: MessageEmbedOptions = {
|
||||
image: { url: avatarUrl + `${extension}?size=2048` },
|
||||
image: {
|
||||
url: user.displayAvatarURL({ dynamic: true, format: "png", size: 2048 }),
|
||||
},
|
||||
title: `Avatar of ${user.tag}:`,
|
||||
};
|
||||
embed.title = `Avatar of ${user.username}#${user.discriminator}:`;
|
||||
msg.channel.send({ embeds: [embed] });
|
||||
} else {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid user ID");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { MessageAttachment } from "discord.js";
|
||||
import fs from "fs";
|
||||
import sharp from "sharp";
|
||||
import twemoji from "twemoji";
|
||||
|
@ -39,8 +40,8 @@ export const JumboCmd = utilityCmd({
|
|||
const size = config.jumbo_size > 2048 ? 2048 : config.jumbo_size;
|
||||
const emojiRegex = new RegExp(`(<.*:).*:(\\d+)`);
|
||||
const results = emojiRegex.exec(args.emoji);
|
||||
let extention = ".png";
|
||||
let file;
|
||||
let extension = ".png";
|
||||
let file: MessageAttachment | undefined;
|
||||
|
||||
if (!isEmoji(args.emoji)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
|
||||
|
@ -50,25 +51,19 @@ export const JumboCmd = utilityCmd({
|
|||
if (results) {
|
||||
let url = "https://cdn.discordapp.com/emojis/";
|
||||
if (results[1] === "<a:") {
|
||||
extention = ".gif";
|
||||
extension = ".gif";
|
||||
}
|
||||
url += `${results[2]}${extention}`;
|
||||
if (extention === ".png") {
|
||||
url += `${results[2]}${extension}`;
|
||||
if (extension === ".png") {
|
||||
const image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
file = {
|
||||
name: `emoji${extention}`,
|
||||
file: image,
|
||||
};
|
||||
file = new MessageAttachment(image, `emoji${extension}`);
|
||||
} else {
|
||||
const image = await getBufferFromUrl(url);
|
||||
file = {
|
||||
name: `emoji${extention}`,
|
||||
file: image,
|
||||
};
|
||||
file = new MessageAttachment(image, `emoji${extension}`);
|
||||
}
|
||||
} else {
|
||||
let url = CDN_URL + `/${twemoji.convert.toCodePoint(args.emoji)}.svg`;
|
||||
let image;
|
||||
let image: Buffer | undefined;
|
||||
try {
|
||||
image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
} catch {
|
||||
|
@ -77,12 +72,14 @@ export const JumboCmd = utilityCmd({
|
|||
image = await resizeBuffer(await getBufferFromUrl(url), size, size);
|
||||
}
|
||||
}
|
||||
file = {
|
||||
name: `emoji.png`,
|
||||
file: image,
|
||||
};
|
||||
if (!image) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid emoji");
|
||||
return;
|
||||
}
|
||||
|
||||
file = new MessageAttachment(image, "emoji.png");
|
||||
}
|
||||
|
||||
msg.channel.send({ content: "", files: [file] });
|
||||
msg.channel.send({ files: [file] });
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,8 +17,6 @@ export const LevelCmd = utilityCmd({
|
|||
run({ message, args, pluginData }) {
|
||||
const member = args.member || message.member;
|
||||
const level = getMemberLevel(pluginData, member);
|
||||
message.channel.send(
|
||||
`The permission level of ${member.user.username}#${member.user.discriminator} is **${level}**`,
|
||||
);
|
||||
message.channel.send(`The permission level of ${member.user.tag} is **${level}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -29,8 +29,6 @@ export const PingCmd = utilityCmd({
|
|||
const lowest = Math.round(Math.min(...times));
|
||||
const mean = Math.round(times.reduce((total, ms) => total + ms, 0) / times.length);
|
||||
|
||||
// const shard = pluginData.client.shards.get(pluginData.client.guildShardMap[pluginData.guild.id])!; FIXME sharding stuff
|
||||
|
||||
msg.channel.send(
|
||||
trimLines(`
|
||||
**Ping:**
|
||||
|
@ -38,7 +36,8 @@ export const PingCmd = utilityCmd({
|
|||
Highest: **${highest}ms**
|
||||
Mean: **${mean}ms**
|
||||
Time between ping command and first reply: **${msgToMsgDelay!}ms**
|
||||
`), // Omitted line: Shard latency: **${shard.latency}ms**
|
||||
Shard latency: **${pluginData.client.ws.ping}ms**
|
||||
`),
|
||||
);
|
||||
|
||||
// Clean up test messages
|
||||
|
|
|
@ -25,7 +25,7 @@ export const VcdisconnectCmd = utilityCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
if (!args.member.voice || !args.member.voice.channelId) {
|
||||
if (!args.member.voice?.channelId) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
|
||||
return;
|
||||
}
|
||||
|
@ -44,10 +44,6 @@ export const VcdisconnectCmd = utilityCmd({
|
|||
oldChannel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`**${args.member.user.username}#${args.member.user.discriminator}** disconnected from **${channel.name}**`,
|
||||
);
|
||||
sendSuccessMessage(pluginData, msg.channel, `**${args.member.user.tag}** disconnected from **${channel.name}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -57,7 +57,7 @@ export const VcmoveCmd = utilityCmd({
|
|||
channel = closestMatch;
|
||||
}
|
||||
|
||||
if (!args.member.voice || !args.member.voice.channelId) {
|
||||
if (!args.member.voice?.channelId) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Member is not in a voice channel");
|
||||
return;
|
||||
}
|
||||
|
@ -85,11 +85,7 @@ export const VcmoveCmd = utilityCmd({
|
|||
newChannel: channelToConfigAccessibleChannel(channel),
|
||||
});
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`**${args.member.user.username}#${args.member.user.discriminator}** moved to **${channel.name}**`,
|
||||
);
|
||||
sendSuccessMessage(pluginData, msg.channel, `**${args.member.user.tag}** moved to **${channel.name}**`);
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -162,7 +158,7 @@ export const VcmoveAllCmd = utilityCmd({
|
|||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Failed to move ${currMember.user.username}#${currMember.user.discriminator} (${currMember.id}): You cannot act on this member`,
|
||||
`Failed to move ${currMember.user.tag} (${currMember.id}): You cannot act on this member`,
|
||||
);
|
||||
errAmt++;
|
||||
continue;
|
||||
|
@ -177,11 +173,7 @@ export const VcmoveAllCmd = utilityCmd({
|
|||
sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members");
|
||||
return;
|
||||
}
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Failed to move ${currMember.user.username}#${currMember.user.discriminator} (${currMember.id})`,
|
||||
);
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to move ${currMember.user.tag} (${currMember.id})`);
|
||||
errAmt++;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export const AutoJoinThreadEvt = utilityEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const config = meta.pluginData.config.get();
|
||||
if (config.autojoin_threads && meta.args.thread.joinable && !meta.args.thread.joined) {
|
||||
if (config.autojoin_threads && meta.args.thread.joinable) {
|
||||
await meta.args.thread.join();
|
||||
}
|
||||
},
|
||||
|
@ -16,11 +16,10 @@ export const AutoJoinThreadSyncEvt = utilityEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const config = meta.pluginData.config.get();
|
||||
if (config.autojoin_threads) {
|
||||
for (const thread of meta.args.threads.values()) {
|
||||
if (!thread.joined && thread.joinable) {
|
||||
await thread.join();
|
||||
}
|
||||
if (config.autojoin_threads) return;
|
||||
for (const thread of meta.args.threads.values()) {
|
||||
if (!thread.joined && thread.joinable) {
|
||||
await thread.join();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -96,7 +96,7 @@ export async function getInviteInfoEmbed(
|
|||
embed.fields.push({
|
||||
name: preEmbedPadding + "Invite creator",
|
||||
value: trimLines(`
|
||||
Name: **${invite.inviter.username}#${invite.inviter.discriminator}**
|
||||
Name: **${invite.inviter.tag}**
|
||||
ID: \`${invite.inviter.id}\`
|
||||
Mention: <@!${invite.inviter.id}>
|
||||
`),
|
||||
|
@ -143,7 +143,7 @@ export async function getInviteInfoEmbed(
|
|||
embed.fields.push({
|
||||
name: preEmbedPadding + "Invite creator",
|
||||
value: trimLines(`
|
||||
Name: **${invite.inviter.username}#${invite.inviter.discriminator}**
|
||||
Name: **${invite.inviter.tag}**
|
||||
ID: \`${invite.inviter.id}\`
|
||||
Mention: <@!${invite.inviter.id}>
|
||||
`),
|
||||
|
|
|
@ -112,7 +112,7 @@ export async function getMessageInfoEmbed(
|
|||
embed.fields.push({
|
||||
name: preEmbedPadding + "Author information",
|
||||
value: trimLines(`
|
||||
Name: **${message.author.username}#${message.author.discriminator}**
|
||||
Name: **${message.author.tag}**
|
||||
ID: \`${message.author.id}\`
|
||||
Created: **${authorAccountAge} ago** (\`${prettyAuthorCreatedAt}\`)
|
||||
${authorJoinedAt ? `Joined: **${authorServerAge} ago** (\`${prettyAuthorJoinedAt}\`)` : ""}
|
||||
|
|
|
@ -65,7 +65,7 @@ export async function getServerInfoEmbed(
|
|||
|
||||
if (thisServer) {
|
||||
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
||||
const ownerName = `${owner.username}#${owner.discriminator}`;
|
||||
const ownerName = `${owner.tag}`;
|
||||
|
||||
basicInformation.push(`Owner: **${ownerName}** (\`${thisServer.ownerId}\`)`);
|
||||
// basicInformation.push(`Voice region: **${thisServer.region}**`); Outdated, as automatic voice regions are fully live
|
||||
|
|
|
@ -36,10 +36,10 @@ export async function getUserInfoEmbed(
|
|||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
|
||||
embed.author = {
|
||||
name: `User: ${user.username}#${user.discriminator}`,
|
||||
name: `User: ${user.tag}`,
|
||||
};
|
||||
|
||||
const avatarURL = user.avatarURL() || user.defaultAvatarURL;
|
||||
const avatarURL = user.displayAvatarURL();
|
||||
embed.author.icon_url = avatarURL;
|
||||
|
||||
const createdAt = moment.utc(user.createdAt, "x");
|
||||
|
@ -84,7 +84,7 @@ export async function getUserInfoEmbed(
|
|||
embed.fields.push({
|
||||
name: preEmbedPadding + "User information",
|
||||
value: trimLines(`
|
||||
Name: **${user.username}#${user.discriminator}**
|
||||
Name: **${user.tag}**
|
||||
ID: \`${user.id}\`
|
||||
Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)
|
||||
Mention: <@!${user.id}>
|
||||
|
|
|
@ -391,7 +391,7 @@ async function performMemberSearch(
|
|||
return true;
|
||||
}
|
||||
|
||||
const fullUsername = `${member.user.username}#${member.user.discriminator}`;
|
||||
const fullUsername = `${member.user.tag}`;
|
||||
if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true;
|
||||
|
||||
return false;
|
||||
|
@ -458,7 +458,7 @@ async function performBanSearch(
|
|||
|
||||
const execRegExp = getOptimizedRegExpRunner(pluginData, isSafeRegex);
|
||||
matchingBans = await asyncFilter(matchingBans, async user => {
|
||||
const fullUsername = `${user.username}#${user.discriminator}`;
|
||||
const fullUsername = `${user.tag}`;
|
||||
if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true;
|
||||
return false;
|
||||
});
|
||||
|
@ -502,10 +502,10 @@ function formatSearchResultList(members: Array<GuildMember | User>): string {
|
|||
const paddedId = member.id.padEnd(longestId, " ");
|
||||
let line;
|
||||
if (member instanceof GuildMember) {
|
||||
line = `${paddedId} ${member.user.username}#${member.user.discriminator}`;
|
||||
line = `${paddedId} ${member.user.tag}`;
|
||||
if (member.nickname) line += ` (${member.nickname})`;
|
||||
} else {
|
||||
line = `${paddedId} ${member.username}#${member.discriminator}`;
|
||||
line = `${paddedId} ${member.tag}`;
|
||||
}
|
||||
return line;
|
||||
});
|
||||
|
|
|
@ -1099,6 +1099,7 @@ export class UnknownUser {
|
|||
public id: string;
|
||||
public username = "Unknown";
|
||||
public discriminator = "0000";
|
||||
public tag = "Unknown#0000";
|
||||
|
||||
constructor(props = {}) {
|
||||
for (const key in props) {
|
||||
|
@ -1353,18 +1354,18 @@ export function messageSummary(msg: SavedMessage) {
|
|||
|
||||
export function verboseUserMention(user: User | UnknownUser): string {
|
||||
if (user.id == null) {
|
||||
return `**${user.username}#${user.discriminator}**`;
|
||||
return `**${user.tag}**`;
|
||||
}
|
||||
|
||||
return `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`;
|
||||
return `<@!${user.id}> (**${user.tag}**, \`${user.id}\`)`;
|
||||
}
|
||||
|
||||
export function verboseUserName(user: User | UnknownUser): string {
|
||||
if (user.id == null) {
|
||||
return `**${user.username}#${user.discriminator}**`;
|
||||
return `**${user.tag}**`;
|
||||
}
|
||||
|
||||
return `**${user.username}#${user.discriminator}** (\`${user.id}\`)`;
|
||||
return `**${user.tag}** (\`${user.id}\`)`;
|
||||
}
|
||||
|
||||
export function verboseChannelMention(channel: GuildChannel): string {
|
||||
|
|
|
@ -40,7 +40,7 @@ export interface IConfigAccessibleMember extends IConfigAccessibleUser {
|
|||
}
|
||||
|
||||
export function userToConfigAccessibleUser(user: User | UnknownUser): IConfigAccessibleUser {
|
||||
if (`${user.username}#${user.discriminator}` === "Unknown#0000") {
|
||||
if (`${user.tag}` === "Unknown#0000") {
|
||||
const toReturnPartial: IConfigAccessibleUser = {
|
||||
id: user.id,
|
||||
username: "Unknown",
|
||||
|
|
Loading…
Add table
Reference in a new issue