mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Merge pull request #4 from almeidx/yeet
removed unnecessary string literal and simplified stuff
This commit is contained in:
commit
3c6c9ebecf
21 changed files with 33 additions and 51 deletions
|
@ -198,7 +198,7 @@ export async function sendSuccessMessage(
|
|||
return channel
|
||||
.send({ ...content }) // Force line break
|
||||
.catch(err => {
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : `${channel.id}`;
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : channel.id;
|
||||
logger.warn(`Failed to send success message to ${channelInfo}): ${err.code} ${err.message}`);
|
||||
return undefined;
|
||||
});
|
||||
|
@ -219,7 +219,7 @@ export async function sendErrorMessage(
|
|||
return channel
|
||||
.send({ ...content }) // Force line break
|
||||
.catch(err => {
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : `${channel.id}`;
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : channel.id;
|
||||
logger.warn(`Failed to send error message to ${channelInfo}): ${err.code} ${err.message}`);
|
||||
return undefined;
|
||||
});
|
||||
|
|
|
@ -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.tag}`;
|
||||
const userName = user.tag;
|
||||
|
||||
const mod = await resolveUser(pluginData.client, args.modId);
|
||||
const modName = `${mod.tag}`;
|
||||
const modName = mod.tag;
|
||||
|
||||
let ppName: string | null = null;
|
||||
if (args.ppId) {
|
||||
const pp = await resolveUser(pluginData.client, args.ppId);
|
||||
ppName = `${pp.tag}`;
|
||||
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.tag}`;
|
||||
const modName = mod.tag;
|
||||
|
||||
let body = args.body;
|
||||
|
||||
|
|
|
@ -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.tag}` : modId;
|
||||
const modName = mod instanceof User ? mod.tag : modId;
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const totalCases = await casesPlugin.getTotalCasesByMod(modId);
|
||||
|
|
|
@ -61,7 +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.tag}`;
|
||||
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}**`);
|
||||
|
|
|
@ -68,7 +68,7 @@ export const DeleteCaseCmd = modActionsCmd({
|
|||
}
|
||||
}
|
||||
|
||||
const deletedByName = `${message.author.tag}`;
|
||||
const deletedByName = message.author.tag;
|
||||
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
const deletedAt = timeAndDate.inGuildTz().format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||
|
|
|
@ -30,7 +30,7 @@ export const NoteCmd = modActionsCmd({
|
|||
return;
|
||||
}
|
||||
|
||||
const userName = `${user.tag}`;
|
||||
const userName = user.tag;
|
||||
const reason = formatReasonWithAttachments(args.note, msg.attachments.array());
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
|
|
|
@ -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.tag}` : "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";
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ 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.tag}` : args.userId;
|
||||
const user = await pluginData.client.users.fetch(args.userId as Snowflake).catch(() => null);
|
||||
const currentUsername = user ? user.tag : args.userId;
|
||||
|
||||
const nicknameDays = Math.round(NICKNAME_RETENTION_PERIOD / DAYS);
|
||||
const usernameDays = Math.round(NICKNAME_RETENTION_PERIOD / DAYS);
|
||||
|
|
|
@ -138,7 +138,7 @@ export async function actualPostCmd(
|
|||
|
||||
await pluginData.state.scheduledPosts.create({
|
||||
author_id: msg.author.id,
|
||||
author_name: `${msg.author.tag}`,
|
||||
author_name: msg.author.tag,
|
||||
channel_id: targetChannel.id,
|
||||
content,
|
||||
attachments: msg.attachments.array(),
|
||||
|
|
|
@ -17,10 +17,8 @@ export const ButtonInteractionEvt = reactionRolesEvt({
|
|||
event: "interactionCreate",
|
||||
|
||||
async listener(meta) {
|
||||
const int = meta.args.interaction.isMessageComponent()
|
||||
? (meta.args.interaction as MessageComponentInteraction)
|
||||
: null;
|
||||
if (!int) return;
|
||||
const int = meta.args.interaction;
|
||||
if (!int.isMessageComponent()) return;
|
||||
|
||||
const cfg = meta.pluginData.config.get();
|
||||
const split = int.customId.split(BUTTON_CONTEXT_SEPARATOR);
|
||||
|
|
|
@ -18,7 +18,7 @@ export function createStarboardEmbedFromMessage(
|
|||
text: `#${(msg.channel as GuildChannel).name}`,
|
||||
},
|
||||
author: {
|
||||
name: `${msg.author.tag}`,
|
||||
name: msg.author.tag,
|
||||
},
|
||||
fields: [],
|
||||
timestamp: msg.createdTimestamp,
|
||||
|
|
|
@ -4,7 +4,7 @@ import { UsernameSaverPluginType } from "./types";
|
|||
|
||||
export async function updateUsername(pluginData: GuildPluginData<UsernameSaverPluginType>, user: User) {
|
||||
if (!user) return;
|
||||
const newUsername = `${user.tag}`;
|
||||
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);
|
||||
|
|
|
@ -80,7 +80,7 @@ export const HelpCmd = utilityCmd({
|
|||
? `Results (${totalResults} total, showing first ${limitedResults.length}):\n\n`
|
||||
: "";
|
||||
|
||||
message += `${commandSnippets.join("\n\n")}`;
|
||||
message += commandSnippets.join("\n\n");
|
||||
createChunkedMessage(msg.channel, message);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ export const AutoJoinThreadSyncEvt = utilityEvt({
|
|||
|
||||
async listener(meta) {
|
||||
const config = meta.pluginData.config.get();
|
||||
if (config.autojoin_threads) return;
|
||||
if (!config.autojoin_threads) return;
|
||||
for (const thread of meta.args.threads.values()) {
|
||||
if (!thread.joined && thread.joinable) {
|
||||
await thread.join();
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
resolveUser,
|
||||
trimLines,
|
||||
} from "../../../utils";
|
||||
import { idToTimestamp } from "../../../utils/idToTimestamp";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { getGuildPreview } from "./getGuildPreview";
|
||||
|
@ -50,7 +51,7 @@ export async function getServerInfoEmbed(
|
|||
|
||||
// BASIC INFORMATION
|
||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||
const createdAt = moment.utc((guildPreview || restGuild)!.id, "x"); // FIXME ID -> Timestamp
|
||||
const createdAt = moment.utc(idToTimestamp((guildPreview || restGuild)!.id)!, "x");
|
||||
const tzCreatedAt = requestMemberId
|
||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||
: timeAndDate.inGuildTz(createdAt);
|
||||
|
@ -65,7 +66,7 @@ export async function getServerInfoEmbed(
|
|||
|
||||
if (thisServer) {
|
||||
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
||||
const ownerName = `${owner.tag}`;
|
||||
const ownerName = owner.tag;
|
||||
|
||||
basicInformation.push(`Owner: **${ownerName}** (\`${thisServer.ownerId}\`)`);
|
||||
// basicInformation.push(`Voice region: **${thisServer.region}**`); Outdated, as automatic voice regions are fully live
|
||||
|
@ -194,7 +195,7 @@ export async function getServerInfoEmbed(
|
|||
}[restGuild.premiumTier] || 0;
|
||||
|
||||
otherStats.push(`Emojis: **${restGuild.emojis.cache.size}** / ${maxEmojis * 2}`);
|
||||
otherStats.push(`Stickers: ? / ${maxStickers}`); // Wait on DJS: **${restGuild.stickers.cache.size}**
|
||||
otherStats.push(`Stickers: **${restGuild.stickers.cache.size}** / ${maxStickers}`);
|
||||
} else {
|
||||
otherStats.push(`Emojis: **${guildPreview!.emojis.size}**`);
|
||||
// otherStats.push(`Stickers: **${guildPreview!.stickers.size}**`); Wait on DJS
|
||||
|
|
|
@ -103,7 +103,7 @@ export async function getUserInfoEmbed(
|
|||
});
|
||||
const roles = member.roles.cache
|
||||
.map(role => pluginData.guild.roles.cache.get(role.id))
|
||||
.filter(r => r != null) as Role[];
|
||||
.filter((r): r is Role => !!r);
|
||||
roles.sort(sorter("position", "DESC"));
|
||||
|
||||
embed.fields.push({
|
||||
|
@ -119,7 +119,7 @@ export async function getUserInfoEmbed(
|
|||
embed.fields.push({
|
||||
name: preEmbedPadding + "Voice information",
|
||||
value: trimLines(`
|
||||
${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""}
|
||||
${voiceChannel ? `Current voice channel: **${voiceChannel.name ?? "None"}**` : ""}
|
||||
${member.voice.mute ? "Server voice muted: **Yes**" : ""}
|
||||
${member.voice.deaf ? "Server voice deafened: **Yes**" : ""}
|
||||
`),
|
||||
|
|
|
@ -177,17 +177,11 @@ export async function displaySearch(
|
|||
.setEmoji("⬅")
|
||||
.setCustomId(`previousButton:${idMod}`)
|
||||
.setDisabled(currentPage === 1),
|
||||
);
|
||||
|
||||
buttons.push(
|
||||
new MessageButton()
|
||||
.setStyle("SECONDARY")
|
||||
.setEmoji("➡")
|
||||
.setCustomId(`nextButton:${idMod}`)
|
||||
.setDisabled(currentPage === searchResult.lastPage),
|
||||
);
|
||||
|
||||
buttons.push(
|
||||
new MessageButton()
|
||||
.setStyle("SECONDARY")
|
||||
.setEmoji("🔄")
|
||||
|
@ -325,7 +319,7 @@ async function performMemberSearch(
|
|||
}
|
||||
|
||||
if (args.voice) {
|
||||
matchingMembers = matchingMembers.filter(m => m.voice.channelId != null);
|
||||
matchingMembers = matchingMembers.filter(m => m.voice.channelId);
|
||||
}
|
||||
|
||||
if (args.bot) {
|
||||
|
@ -391,7 +385,7 @@ async function performMemberSearch(
|
|||
return true;
|
||||
}
|
||||
|
||||
const fullUsername = `${member.user.tag}`;
|
||||
const fullUsername = member.user.tag;
|
||||
if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true;
|
||||
|
||||
return false;
|
||||
|
@ -458,7 +452,7 @@ async function performBanSearch(
|
|||
|
||||
const execRegExp = getOptimizedRegExpRunner(pluginData, isSafeRegex);
|
||||
matchingBans = await asyncFilter(matchingBans, async user => {
|
||||
const fullUsername = `${user.tag}`;
|
||||
const fullUsername = user.tag;
|
||||
if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true;
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -40,7 +40,7 @@ export interface IConfigAccessibleMember extends IConfigAccessibleUser {
|
|||
}
|
||||
|
||||
export function userToConfigAccessibleUser(user: User | UnknownUser): IConfigAccessibleUser {
|
||||
if (`${user.tag}` === "Unknown#0000") {
|
||||
if (user.tag === "Unknown#0000") {
|
||||
const toReturnPartial: IConfigAccessibleUser = {
|
||||
id: user.id,
|
||||
username: "Unknown",
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
import { Permissions } from "discord.js";
|
||||
|
||||
const camelCaseToTitleCase = str =>
|
||||
str
|
||||
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
.split(" ")
|
||||
.map(w => w[0].toUpperCase() + w.slice(1))
|
||||
.join(" ");
|
||||
|
||||
const permissionNumberToName: Map<bigint, string> = new Map();
|
||||
const ignoredPermissionConstants = ["all", "allGuild", "allText", "allVoice"];
|
||||
|
||||
for (const key in Permissions.FLAGS) {
|
||||
if (ignoredPermissionConstants.includes(key)) continue;
|
||||
permissionNumberToName.set(BigInt(Permissions.FLAGS[key]), camelCaseToTitleCase(key));
|
||||
permissionNumberToName.set(BigInt(Permissions.FLAGS[key]), key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import moment from "moment";
|
||||
|
||||
const EPOCH = 1420070400000;
|
||||
import { Snowflake, SnowflakeUtil } from "discord.js";
|
||||
|
||||
export function idToTimestamp(id: string) {
|
||||
if (typeof id === "number") return null;
|
||||
return moment(+id / 4194304 + EPOCH)
|
||||
.utc()
|
||||
.valueOf();
|
||||
return SnowflakeUtil.deconstruct(id as Snowflake).timestamp;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue