mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Merge pull request #454 from ZeppelinBot/metal0-fix-member-cases
Some fixes to !cases (continued)
This commit is contained in:
commit
48507499bc
2 changed files with 50 additions and 50 deletions
|
@ -4,7 +4,6 @@ import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { UnknownUser, emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines } from "../../../utils";
|
import { UnknownUser, emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines } from "../../../utils";
|
||||||
import { asyncMap } from "../../../utils/async";
|
import { asyncMap } from "../../../utils/async";
|
||||||
import { createPaginatedMessage } from "../../../utils/createPaginatedMessage";
|
import { createPaginatedMessage } from "../../../utils/createPaginatedMessage";
|
||||||
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
|
|
||||||
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
||||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||||
import { modActionsCmd } from "../types";
|
import { modActionsCmd } from "../types";
|
||||||
|
@ -52,8 +51,9 @@ export const CasesModCmd = modActionsCmd({
|
||||||
const cases = await casesPlugin.getRecentCasesByMod(modId, casesPerPage, (page - 1) * casesPerPage);
|
const cases = await casesPlugin.getRecentCasesByMod(modId, casesPerPage, (page - 1) * casesPerPage);
|
||||||
const lines = await asyncMap(cases, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
const lines = await asyncMap(cases, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||||
|
|
||||||
|
const isLastPage = page === totalPages;
|
||||||
const firstCaseNum = (page - 1) * casesPerPage + 1;
|
const firstCaseNum = (page - 1) * casesPerPage + 1;
|
||||||
const lastCaseNum = page * casesPerPage;
|
const lastCaseNum = isLastPage ? totalCases : page * casesPerPage;
|
||||||
const title = `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${totalCases} by ${modName}`;
|
const title = `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${totalCases} by ${modName}`;
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
|
@ -61,8 +61,8 @@ export const CasesModCmd = modActionsCmd({
|
||||||
name: title,
|
name: title,
|
||||||
icon_url: mod instanceof UnknownUser ? undefined : mod.displayAvatarURL(),
|
icon_url: mod instanceof UnknownUser ? undefined : mod.displayAvatarURL(),
|
||||||
},
|
},
|
||||||
|
description: lines.join("\n"),
|
||||||
fields: [
|
fields: [
|
||||||
...getChunkedEmbedFields(emptyEmbedValue, lines.join("\n")),
|
|
||||||
{
|
{
|
||||||
name: emptyEmbedValue,
|
name: emptyEmbedValue,
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
import { APIEmbed } from "discord.js";
|
import { APIEmbed, User } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
import { CaseTypes } from "../../../data/CaseTypes";
|
||||||
import { sendErrorMessage } from "../../../pluginUtils";
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
import { CasesPlugin } from "../../../plugins/Cases/CasesPlugin";
|
||||||
import {
|
import { UnknownUser, chunkArray, emptyEmbedValue, renderUsername, resolveMember, resolveUser } from "../../../utils";
|
||||||
UnknownUser,
|
|
||||||
chunkArray,
|
|
||||||
emptyEmbedValue,
|
|
||||||
renderUsername,
|
|
||||||
resolveMember,
|
|
||||||
resolveUser,
|
|
||||||
trimLines,
|
|
||||||
} from "../../../utils";
|
|
||||||
import { asyncMap } from "../../../utils/async";
|
import { asyncMap } from "../../../utils/async";
|
||||||
import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields";
|
import { createPaginatedMessage } from "../../../utils/createPaginatedMessage.js";
|
||||||
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
import { getGuildPrefix } from "../../../utils/getGuildPrefix";
|
||||||
import { modActionsCmd } from "../types";
|
import { modActionsCmd } from "../types";
|
||||||
|
|
||||||
|
@ -29,6 +21,8 @@ const opts = {
|
||||||
unbans: ct.switchOption({ def: false, shortcut: "ub" }),
|
unbans: ct.switchOption({ def: false, shortcut: "ub" }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const casesPerPage = 5;
|
||||||
|
|
||||||
export const CasesUserCmd = modActionsCmd({
|
export const CasesUserCmd = modActionsCmd({
|
||||||
trigger: ["cases", "modlogs"],
|
trigger: ["cases", "modlogs"],
|
||||||
permission: "can_view",
|
permission: "can_view",
|
||||||
|
@ -100,49 +94,55 @@ export const CasesUserCmd = modActionsCmd({
|
||||||
} else {
|
} else {
|
||||||
// Compact view (= regular message with a preview of each case)
|
// Compact view (= regular message with a preview of each case)
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||||
const lines = await asyncMap(casesToDisplay, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
|
||||||
|
|
||||||
|
const totalPages = Math.max(Math.ceil(cases.length / casesPerPage), 1);
|
||||||
const prefix = getGuildPrefix(pluginData);
|
const prefix = getGuildPrefix(pluginData);
|
||||||
const linesPerChunk = 10;
|
|
||||||
const lineChunks = chunkArray(lines, linesPerChunk);
|
|
||||||
|
|
||||||
const footerField = {
|
createPaginatedMessage(
|
||||||
name: emptyEmbedValue,
|
pluginData.client,
|
||||||
value: trimLines(`
|
msg.channel,
|
||||||
Use \`${prefix}case <num>\` to see more information about an individual case
|
totalPages,
|
||||||
`),
|
async (page) => {
|
||||||
};
|
const chunkedCases = chunkArray(cases, casesPerPage)[page - 1];
|
||||||
|
const lines = await asyncMap(chunkedCases, (c) => casesPlugin.getCaseSummary(c, true, msg.author.id));
|
||||||
|
|
||||||
for (const [i, linesInChunk] of lineChunks.entries()) {
|
const isLastPage = page === totalPages;
|
||||||
const isLastChunk = i === lineChunks.length - 1;
|
const firstCaseNum = (page - 1) * casesPerPage + 1;
|
||||||
|
const lastCaseNum = isLastPage ? cases.length : page * casesPerPage;
|
||||||
|
const title =
|
||||||
|
totalPages === 1
|
||||||
|
? `Cases for ${userName} (${lines.length} total)`
|
||||||
|
: `Most recent cases ${firstCaseNum}-${lastCaseNum} of ${cases.length} for ${userName}`;
|
||||||
|
|
||||||
if (isLastChunk && !args.hidden && hiddenCases.length) {
|
const embed = {
|
||||||
if (hiddenCases.length === 1) {
|
author: {
|
||||||
linesInChunk.push(`*+${hiddenCases.length} hidden case, use "-hidden" to show it*`);
|
name: title,
|
||||||
} else {
|
icon_url: user instanceof User ? user.displayAvatarURL() : undefined,
|
||||||
linesInChunk.push(`*+${hiddenCases.length} hidden cases, use "-hidden" to show them*`);
|
},
|
||||||
}
|
description: lines.join("\n"),
|
||||||
}
|
fields: [
|
||||||
|
{
|
||||||
|
name: emptyEmbedValue,
|
||||||
|
value: `Use \`${prefix}case <num>\` to see more information about an individual case`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies APIEmbed;
|
||||||
|
|
||||||
const chunkStart = i * linesPerChunk + 1;
|
if (isLastPage && !args.hidden && hiddenCases.length)
|
||||||
const chunkEnd = Math.min((i + 1) * linesPerChunk, lines.length);
|
embed.fields.push({
|
||||||
|
name: emptyEmbedValue,
|
||||||
|
value:
|
||||||
|
hiddenCases.length === 1
|
||||||
|
? `*+${hiddenCases.length} hidden case, use "-hidden" to show it*`
|
||||||
|
: `*+${hiddenCases.length} hidden cases, use "-hidden" to show them*`,
|
||||||
|
});
|
||||||
|
|
||||||
const embed = {
|
return { embeds: [embed] };
|
||||||
author: {
|
},
|
||||||
name:
|
{
|
||||||
lineChunks.length === 1
|
limitToUserId: msg.author.id,
|
||||||
? `Cases for ${userName} (${lines.length} total)`
|
},
|
||||||
: `Cases ${chunkStart}–${chunkEnd} of ${lines.length} for ${userName}`,
|
);
|
||||||
icon_url: user.displayAvatarURL(),
|
|
||||||
},
|
|
||||||
fields: [
|
|
||||||
...getChunkedEmbedFields(emptyEmbedValue, linesInChunk.join("\n")),
|
|
||||||
...(isLastChunk ? [footerField] : []),
|
|
||||||
],
|
|
||||||
} satisfies APIEmbed;
|
|
||||||
|
|
||||||
msg.channel.send({ embeds: [embed] });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue