3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Reformat all files with Prettier

This commit is contained in:
Dragory 2021-09-11 19:06:51 +03:00
parent 0cde0d46d2
commit ac79eb09f5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
206 changed files with 727 additions and 888 deletions

View file

@ -55,10 +55,7 @@ export const AboutCmd = utilityCmd({
];
const loadedPlugins = Array.from(
pluginData
.getKnubInstance()
.getLoadedGuild(pluginData.guild.id)!
.loadedPlugins.keys(),
pluginData.getKnubInstance().getLoadedGuild(pluginData.guild.id)!.loadedPlugins.keys(),
);
loadedPlugins.sort();
@ -100,9 +97,9 @@ export const AboutCmd = utilityCmd({
// For the embed color, find the highest colored role the bot has - this is their color on the server as well
const botMember = await resolveMember(pluginData.client, pluginData.guild, pluginData.client.user!.id);
let botRoles = botMember?.roles.cache.map(r => (msg.channel as GuildChannel).guild.roles.cache.get(r.id)!) || [];
botRoles = botRoles.filter(r => !!r); // Drop any unknown roles
botRoles = botRoles.filter(r => r.color); // Filter to those with a color
let botRoles = botMember?.roles.cache.map((r) => (msg.channel as GuildChannel).guild.roles.cache.get(r.id)!) || [];
botRoles = botRoles.filter((r) => !!r); // Drop any unknown roles
botRoles = botRoles.filter((r) => r.color); // Filter to those with a color
botRoles.sort(sorter("position", "DESC")); // Sort by position (highest first)
if (botRoles.length) {
aboutContent.embeds![0].color = botRoles[0].color;

View file

@ -30,10 +30,10 @@ export async function cleanMessages(
// Delete & archive in ID order
savedMessages = Array.from(savedMessages).sort((a, b) => (a.id > b.id ? 1 : -1));
const idsToDelete = savedMessages.map(m => m.id) as Snowflake[];
const idsToDelete = savedMessages.map((m) => m.id) as Snowflake[];
// Make sure the deletions aren't double logged
idsToDelete.forEach(id => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
idsToDelete.forEach((id) => pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id));
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE_BULK, idsToDelete[0]);
// Actually delete the messages
@ -171,12 +171,12 @@ export async function cleanCmd(pluginData: GuildPluginData<UtilityPluginType>, a
let responseMsg: Message | undefined;
if (messagesToClean.length > 0) {
// Save to-be-deleted messages that were missing from the database
const existingStored = await pluginData.state.savedMessages.getMultiple(messagesToClean.map(m => m.id));
const alreadyStored = existingStored.map(stored => stored.id);
const messagesToStore = messagesToClean.filter(potentialMsg => !alreadyStored.includes(potentialMsg.id));
const existingStored = await pluginData.state.savedMessages.getMultiple(messagesToClean.map((m) => m.id));
const alreadyStored = existingStored.map((stored) => stored.id);
const messagesToStore = messagesToClean.filter((potentialMsg) => !alreadyStored.includes(potentialMsg.id));
await pluginData.state.savedMessages.createFromMessages(messagesToStore);
const savedMessagesToClean = await pluginData.state.savedMessages.getMultiple(messagesToClean.map(m => m.id));
const savedMessagesToClean = await pluginData.state.savedMessages.getMultiple(messagesToClean.map((m) => m.id));
const cleanResult = await cleanMessages(pluginData, targetChannel, savedMessagesToClean, msg.author);
let responseText = `Cleaned ${messagesToClean.length} ${messagesToClean.length === 1 ? "message" : "messages"}`;

View file

@ -58,10 +58,7 @@ export const HelpCmd = utilityCmd({
const description = command.config!.extra!.blueprint.description;
const usage = command.config!.extra!.blueprint.usage;
const commandSlug = trigger
.trim()
.toLowerCase()
.replace(/\s/g, "-");
const commandSlug = trigger.trim().toLowerCase().replace(/\s/g, "-");
let snippet = `**${prefix}${trigger}**`;
if (description) snippet += `\n${description}`;

View file

@ -28,7 +28,7 @@ export const RolesCmd = utilityCmd({
if (args.search) {
const searchStr = args.search.toLowerCase();
roles = roles.filter(r => r.name.toLowerCase().includes(searchStr) || r.id === searchStr);
roles = roles.filter((r) => r.name.toLowerCase().includes(searchStr) || r.id === searchStr);
}
if (args.counts) {
@ -75,7 +75,7 @@ export const RolesCmd = utilityCmd({
} else if (sort === "memberCount" && args.counts) {
roles.sort(sorter("_memberCount", sortDir));
} else if (sort === "name") {
roles.sort(sorter(r => r.name.toLowerCase(), sortDir));
roles.sort(sorter((r) => r.name.toLowerCase(), sortDir));
} else {
sendErrorMessage(pluginData, msg.channel, "Unknown sorting method");
return;
@ -85,7 +85,7 @@ export const RolesCmd = utilityCmd({
const chunks = chunkArray(roles, 20);
for (const [i, chunk] of chunks.entries()) {
const roleLines = chunk.map(role => {
const roleLines = chunk.map((role) => {
const paddedId = role.id.padEnd(longestId, " ");
let line = `${paddedId} ${role.name}`;
if (role._memberCount != null) {

View file

@ -50,7 +50,7 @@ export const VcmoveCmd = utilityCmd({
const voiceChannels = [...pluginData.guild.channels.cache.values()].filter(
(c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE,
);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, ch => ch.name);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");
return;
@ -129,7 +129,7 @@ export const VcmoveAllCmd = utilityCmd({
const voiceChannels = [...pluginData.guild.channels.cache.values()].filter(
(c): c is VoiceChannel => c.type === ChannelTypeStrings.VOICE,
);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, ch => ch.name);
const closestMatch = simpleClosestStringMatch(args.channel, voiceChannels, (ch) => ch.name);
if (!closestMatch) {
sendErrorMessage(pluginData, msg.channel, "No matching voice channels");
return;

View file

@ -96,8 +96,8 @@ export async function getChannelInfoEmbed(
if (channel.type === ChannelTypeStrings.VOICE || channel.type === ChannelTypeStrings.STAGE) {
const voiceMembers = Array.from((channel as VoiceChannel | StageChannel).members.values());
const muted = voiceMembers.filter(vm => vm.voice.mute || vm.voice.selfMute);
const deafened = voiceMembers.filter(vm => vm.voice.deaf || vm.voice.selfDeaf);
const muted = voiceMembers.filter((vm) => vm.voice.mute || vm.voice.selfMute);
const deafened = voiceMembers.filter((vm) => vm.voice.deaf || vm.voice.selfDeaf);
const voiceOrStage = channel.type === ChannelTypeStrings.VOICE ? "Voice" : "Stage";
embed.fields.push({
@ -112,10 +112,10 @@ export async function getChannelInfoEmbed(
if (channel.type === ChannelTypeStrings.CATEGORY) {
const textChannels = pluginData.guild.channels.cache.filter(
ch => ch.parentId === channel.id && ch.type !== ChannelTypeStrings.VOICE,
(ch) => ch.parentId === channel.id && ch.type !== ChannelTypeStrings.VOICE,
);
const voiceChannels = pluginData.guild.channels.cache.filter(
ch =>
(ch) =>
ch.parentId === channel.id && (ch.type === ChannelTypeStrings.VOICE || ch.type === ChannelTypeStrings.STAGE),
);

View file

@ -7,7 +7,7 @@ export async function getEmojiInfoEmbed(
pluginData: GuildPluginData<UtilityPluginType>,
emojiId: string,
): Promise<MessageEmbedOptions | null> {
const emoji = pluginData.guild.emojis.cache.find(e => e.id === emojiId);
const emoji = pluginData.guild.emojis.cache.find((e) => e.id === emojiId);
if (!emoji) {
return null;
}

View file

@ -120,9 +120,7 @@ export async function getInviteInfoEmbed(
/*if (invite.channel.icon) {
embed.author.icon_url = `https://cdn.discordapp.com/channel-icons/${invite.channel.id}/${invite.channel.icon}.png?size=256`;
}*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(
invite.channel.id,
);
}*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x");
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
largest: 2,

View file

@ -35,13 +35,13 @@ export async function getRoleInfoEmbed(
round: true,
});
const rolePerms = Object.keys(role.permissions.toJSON()).map(p =>
const rolePerms = Object.keys(role.permissions.toJSON()).map((p) =>
p
// Voice channel related permission names start with 'voice'
.replace(/^voice/i, "")
.replace(/([a-z])([A-Z])/g, "$1 $2")
.toLowerCase()
.replace(/(^\w{1})|(\s{1}\w{1})/g, l => l.toUpperCase()),
.replace(/(^\w{1})|(\s{1}\w{1})/g, (l) => l.toUpperCase()),
);
// -1 because of the @everyone role
@ -54,10 +54,7 @@ export async function getRoleInfoEmbed(
ID: \`${role.id}\`
Created: **${roleAge} ago** (\`${prettyCreatedAt}\`)
Position: **${role.position} / ${totalGuildRoles}**
Color: **#${role.color
.toString(16)
.toUpperCase()
.padStart(6, "0")}**
Color: **#${role.color.toString(16).toUpperCase().padStart(6, "0")}**
Mentionable: **${role.mentionable ? "Yes" : "No"}**
Hoisted: **${role.hoist ? "Yes" : "No"}**
Permissions: \`${rolePerms.length ? rolePerms.join(", ") : "None"}\`

View file

@ -134,7 +134,7 @@ export async function getServerInfoEmbed(
}
if (!onlineMemberCount && thisServer) {
onlineMemberCount = thisServer.members.cache.filter(m => m.presence?.status !== "offline").size; // Extremely inaccurate fallback
onlineMemberCount = thisServer.members.cache.filter((m) => m.presence?.status !== "offline").size; // Extremely inaccurate fallback
}
const offlineMemberCount = totalMembers - onlineMemberCount;
@ -162,9 +162,9 @@ export async function getServerInfoEmbed(
// CHANNEL COUNTS
if (thisServer) {
const totalChannels = thisServer.channels.cache.size;
const categories = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.CATEGORY);
const textChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.TEXT);
const voiceChannels = thisServer.channels.cache.filter(channel => channel.type === ChannelTypeStrings.VOICE);
const categories = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.CATEGORY);
const textChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.TEXT);
const voiceChannels = thisServer.channels.cache.filter((channel) => channel.type === ChannelTypeStrings.VOICE);
embed.fields.push({
name: preEmbedPadding + "Channels",

View file

@ -102,14 +102,14 @@ export async function getUserInfoEmbed(
largest: 2,
round: true,
});
const roles = Array.from(member.roles.cache.values()).filter(r => r.id !== pluginData.guild.id);
const roles = Array.from(member.roles.cache.values()).filter((r) => r.id !== pluginData.guild.id);
roles.sort(sorter("position", "DESC"));
embed.fields.push({
name: preEmbedPadding + "Member information",
value: trimLines(`
${user.bot ? "Added" : "Joined"}: **${joinAge} ago** (\`${prettyJoinedAt}\`)
${roles.length > 0 ? "Roles: " + roles.map(r => `<@&${r.id}>`).join(", ") : ""}
${roles.length > 0 ? "Roles: " + roles.map((r) => `<@&${r.id}>`).join(", ") : ""}
`),
});
@ -130,14 +130,14 @@ export async function getUserInfoEmbed(
value: `${user.bot ? "Bot" : "User"} is not on the server`,
});
}
const cases = (await pluginData.state.cases.getByUserId(user.id)).filter(c => !c.is_hidden);
const cases = (await pluginData.state.cases.getByUserId(user.id)).filter((c) => !c.is_hidden);
if (cases.length > 0) {
cases.sort((a, b) => {
return a.created_at < b.created_at ? 1 : -1;
});
const caseSummary = cases.slice(0, 3).map(c => {
const caseSummary = cases.slice(0, 3).map((c) => {
const summaryText = `${CaseTypes[c.type]} (#${c.case_number})`;
if (c.log_message_id) {

View file

@ -90,7 +90,7 @@ export async function displaySearch(
const perPage = args.ids ? SEARCH_ID_RESULTS_PER_PAGE : SEARCH_RESULTS_PER_PAGE;
const loadSearchPage = async page => {
const loadSearchPage = async (page) => {
if (searching) return;
searching = true;
@ -101,7 +101,7 @@ export async function displaySearch(
searchMsgPromise = originalSearchMsg.edit("Searching...");
} else {
searchMsgPromise = msg.channel.send("Searching...");
searchMsgPromise.then(m => (originalSearchMsg = m));
searchMsgPromise.then((m) => (originalSearchMsg = m));
}
let searchResult;
@ -182,10 +182,7 @@ export async function displaySearch(
.setEmoji("➡")
.setCustomId(`nextButton:${idMod}`)
.setDisabled(currentPage === searchResult.lastPage),
new MessageButton()
.setStyle("SECONDARY")
.setEmoji("🔄")
.setCustomId(`reloadButton:${idMod}`),
new MessageButton().setStyle("SECONDARY").setEmoji("🔄").setCustomId(`reloadButton:${idMod}`),
);
const row = new MessageActionRow().addComponents(buttons);
@ -308,7 +305,7 @@ async function performMemberSearch(
if (args.role) {
const roleIds = args.role.split(",");
matchingMembers = matchingMembers.filter(member => {
matchingMembers = matchingMembers.filter((member) => {
for (const role of roleIds) {
if (!member.roles.cache.has(role as Snowflake)) return false;
}
@ -318,11 +315,11 @@ async function performMemberSearch(
}
if (args.voice) {
matchingMembers = matchingMembers.filter(m => m.voice.channelId);
matchingMembers = matchingMembers.filter((m) => m.voice.channelId);
}
if (args.bot) {
matchingMembers = matchingMembers.filter(m => m.user.bot);
matchingMembers = matchingMembers.filter((m) => m.user.bot);
}
if (args.query) {
@ -379,7 +376,7 @@ async function performMemberSearch(
});
} else {
*/
matchingMembers = await asyncFilter(matchingMembers, async member => {
matchingMembers = await asyncFilter(matchingMembers, async (member) => {
if (member.nickname && (await execRegExp(queryRegex, member.nickname).catch(allowTimeout))) {
return true;
}
@ -396,12 +393,12 @@ async function performMemberSearch(
const realSortDir = sortDir === "-" ? "DESC" : "ASC";
if (sortBy === "id") {
matchingMembers.sort(sorter(m => BigInt(m.id), realSortDir));
matchingMembers.sort(sorter((m) => BigInt(m.id), realSortDir));
} else {
matchingMembers.sort(
multiSorter([
[m => m.user.username.toLowerCase(), realSortDir],
[m => m.discriminator, realSortDir],
[(m) => m.user.username.toLowerCase(), realSortDir],
[(m) => m.discriminator, realSortDir],
]),
);
}
@ -435,7 +432,7 @@ async function performBanSearch(
throw new SearchError(`Unable to search bans: missing "Ban Members" permission`);
}
let matchingBans = (await pluginData.guild.bans.fetch({ cache: false })).map(x => x.user);
let matchingBans = (await pluginData.guild.bans.fetch({ cache: false })).map((x) => x.user);
if (args.query) {
let isSafeRegex = true;
@ -450,7 +447,7 @@ async function performBanSearch(
}
const execRegExp = getOptimizedRegExpRunner(pluginData, isSafeRegex);
matchingBans = await asyncFilter(matchingBans, async user => {
matchingBans = await asyncFilter(matchingBans, async (user) => {
const fullUsername = user.tag;
if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true;
return false;
@ -461,12 +458,12 @@ async function performBanSearch(
const realSortDir = sortDir === "-" ? "DESC" : "ASC";
if (sortBy === "id") {
matchingBans.sort(sorter(m => BigInt(m.id), realSortDir));
matchingBans.sort(sorter((m) => BigInt(m.id), realSortDir));
} else {
matchingBans.sort(
multiSorter([
[m => m.username.toLowerCase(), realSortDir],
[m => m.discriminator, realSortDir],
[(m) => m.username.toLowerCase(), realSortDir],
[(m) => m.discriminator, realSortDir],
]),
);
}
@ -491,7 +488,7 @@ async function performBanSearch(
function formatSearchResultList(members: Array<GuildMember | User>): string {
const longestId = members.reduce((longest, member) => Math.max(longest, member.id.length), 0);
const lines = members.map(member => {
const lines = members.map((member) => {
const paddedId = member.id.padEnd(longestId, " ");
let line;
if (member instanceof GuildMember) {
@ -506,5 +503,5 @@ function formatSearchResultList(members: Array<GuildMember | User>): string {
}
function formatSearchResultIdList(members: Array<GuildMember | User>): string {
return members.map(m => m.id).join(" ");
return members.map((m) => m.id).join(" ");
}