3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Add optional 'expanded' param to !cases

This commit is contained in:
Dragory 2018-08-02 03:01:22 +03:00
parent 2aaacef2c3
commit 9769e38f17

View file

@ -691,9 +691,9 @@ export class ModActionsPlugin extends Plugin {
this.displayCase(theCase.id, msg.channel.id); this.displayCase(theCase.id, msg.channel.id);
} }
@d.command(/cases|usercases/, "<userId:userId>") @d.command(/cases|usercases/, "<userId:userId> [expanded:string]")
@d.permission("view") @d.permission("view")
async usercasesCmd(msg: Message, args: { userId: string }) { async usercasesCmd(msg: Message, args: { userId: string; expanded?: string }) {
const cases = await this.cases.getByUserId(args.userId); const cases = await this.cases.getByUserId(args.userId);
const user = this.bot.users.get(args.userId); const user = this.bot.users.get(args.userId);
const userName = user ? `${user.username}#${user.discriminator}` : "Unknown#0000"; const userName = user ? `${user.username}#${user.discriminator}` : "Unknown#0000";
@ -702,27 +702,34 @@ export class ModActionsPlugin extends Plugin {
if (cases.length === 0) { if (cases.length === 0) {
msg.channel.createMessage("No cases found for the specified user!"); msg.channel.createMessage("No cases found for the specified user!");
} else { } else {
const lines = []; if (args.expanded === "expanded") {
for (const theCase of cases) { // Expanded view (= individual case embeds)
const firstNote = await this.cases.findFirstCaseNote(theCase.id); for (const theCase of cases) {
let reason = firstNote ? firstNote.body : ""; await this.displayCase(theCase.id, msg.channel.id);
}
} else {
// Compact view (= regular message with a preview of each case)
const lines = [];
for (const theCase of cases) {
const firstNote = await this.cases.findFirstCaseNote(theCase.id);
let reason = firstNote ? firstNote.body : "";
if (reason.length > CASE_LIST_REASON_MAX_LENGTH) { if (reason.length > CASE_LIST_REASON_MAX_LENGTH) {
const match = reason.slice(CASE_LIST_REASON_MAX_LENGTH, 20).match(/(?:[.,!?\s]|$)/); const match = reason.slice(CASE_LIST_REASON_MAX_LENGTH, 20).match(/(?:[.,!?\s]|$)/);
const nextWhitespaceIndex = match const nextWhitespaceIndex = match
? CASE_LIST_REASON_MAX_LENGTH + match.index ? CASE_LIST_REASON_MAX_LENGTH + match.index
: CASE_LIST_REASON_MAX_LENGTH; : CASE_LIST_REASON_MAX_LENGTH;
if (nextWhitespaceIndex < reason.length) { if (nextWhitespaceIndex < reason.length) {
reason = reason.slice(0, nextWhitespaceIndex - 1) + "..."; reason = reason.slice(0, nextWhitespaceIndex - 1) + "...";
}
} }
reason = disableLinkPreviews(reason);
lines.push(`Case \`#${theCase.case_number}\` __${CaseType[theCase.type]}__ ${reason}`);
} }
reason = disableLinkPreviews(reason); const finalMessage = trimLines(`
lines.push(`Case \`#${theCase.case_number}\` __${CaseType[theCase.type]}__ ${reason}`);
}
const finalMessage = trimLines(`
Cases for **${userName}**: Cases for **${userName}**:
${lines.join("\n")} ${lines.join("\n")}
@ -730,7 +737,8 @@ export class ModActionsPlugin extends Plugin {
Use \`${prefix}case <num>\` to see more info about individual cases Use \`${prefix}case <num>\` to see more info about individual cases
`); `);
msg.channel.createMessage(finalMessage); msg.channel.createMessage(finalMessage);
}
} }
} }
@ -838,7 +846,7 @@ export class ModActionsPlugin extends Plugin {
} }
const channel = this.guild.channels.get(channelId) as TextChannel; const channel = this.guild.channels.get(channelId) as TextChannel;
channel.createMessage({ embed }); await channel.createMessage({ embed });
} }
/** /**