From 12d8b19561415bf5a05a80cccc371d813e4fb9c3 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Sat, 11 Jan 2020 01:39:02 +1100 Subject: [PATCH 1/3] Added compact switch to !info --- backend/src/plugins/Utility.ts | 113 ++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/backend/src/plugins/Utility.ts b/backend/src/plugins/Utility.ts index 0a81aaa1..51c85815 100644 --- a/backend/src/plugins/Utility.ts +++ b/backend/src/plugins/Utility.ts @@ -792,9 +792,16 @@ export class UtilityPlugin extends ZeppelinPlugin { basicUsage: "!info 106391128718245888", }, }, + options: [ + { + name: "compact", + shortcut: "c", + isSwitch: true, + } + ] }) @d.permission("can_info") - async infoCmd(msg: Message, args: { user?: User | UnknownUser }) { + async infoCmd(msg: Message, args: { user?: User | UnknownUser, compact?: boolean }) { const user = args.user || msg.author; let member; @@ -816,15 +823,27 @@ export class UtilityPlugin extends ZeppelinPlugin { embed.title = `${user.username}#${user.discriminator}`; embed.thumbnail = { url: user.avatarURL }; - embed.fields.push({ - name: "User information", - value: - trimLines(` - ID: **${user.id}** - Profile: <@!${user.id}> - Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})** - `) + embedPadding, - }); + if(args.compact){ + embed.fields.push({ + name: "User information", + value: + trimLines(` + Profile: <@!${user.id}> + Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})** + `), + }); + } + else{ + embed.fields.push({ + name: "User information", + value: + trimLines(` + ID: **${user.id}** + Profile: <@!${user.id}> + Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})** + `) + embedPadding, + }); + } } else { embed.title = `Unknown user`; } @@ -837,56 +856,62 @@ export class UtilityPlugin extends ZeppelinPlugin { }); const roles = member.roles.map(id => this.guild.roles.get(id)).filter(r => !!r); - embed.fields.push({ - name: "Member information", - value: - trimLines(` - Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})** - ${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""} - `) + embedPadding, - }); - - const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null; - if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) { + if(args.compact){ + embed.fields[0].value += `\n` + trimLines(`Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**`); + } + else{ embed.fields.push({ - name: "Voice information", + name: "Member information", value: trimLines(` - ${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""} - ${member.voiceState.mute ? "Server voice muted: **Yes**" : ""} - ${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""} - `) + embedPadding, + Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})** + ${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""} + `) + embedPadding, }); } + if(!args.compact){ + const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null; + if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) { + embed.fields.push({ + name: "Voice information", + value: + trimLines(` + ${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""} + ${member.voiceState.mute ? "Server voice muted: **Yes**" : ""} + ${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""} + `) + embedPadding, + }); + } + } } else { embed.fields.push({ name: "!! USER IS NOT ON THE SERVER !!", value: embedPadding, }); } + if(!args.compact){ + const cases = (await this.cases.getByUserId(user.id)).filter(c => !c.is_hidden); - const cases = (await this.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; + }); - 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 => { + return `${CaseTypes[c.type]} (#${c.case_number})`; + }); - const caseSummary = cases.slice(0, 3).map(c => { - return `${CaseTypes[c.type]} (#${c.case_number})`; - }); + const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary"; - const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary"; - - embed.fields.push({ - name: "Cases", - value: trimLines(` - Total cases: **${cases.length}** - ${summaryText}: ${caseSummary.join(", ")} - `), - }); + embed.fields.push({ + name: "Cases", + value: trimLines(` + Total cases: **${cases.length}** + ${summaryText}: ${caseSummary.join(", ")} + `), + }); + } } - msg.channel.createMessage({ embed }); } From 4623475fb5d03d7f187b2d315ccbb1d731b93a09 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Sat, 11 Jan 2020 02:05:54 +1100 Subject: [PATCH 2/3] Cleaned up code --- backend/src/plugins/Utility.ts | 86 ++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/backend/src/plugins/Utility.ts b/backend/src/plugins/Utility.ts index 51c85815..ce89b98e 100644 --- a/backend/src/plugins/Utility.ts +++ b/backend/src/plugins/Utility.ts @@ -832,6 +832,21 @@ export class UtilityPlugin extends ZeppelinPlugin { Created: **${accountAge} ago (${createdAt.format("YYYY-MM-DD[T]HH:mm:ss")})** `), }); + if (member) { + const joinedAt = moment(member.joinedAt); + const joinAge = humanizeDuration(moment().valueOf() - member.joinedAt, { + largest: 2, + round: true, + }); + embed.fields[0].value += `\nJoined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**` + } else { + embed.fields.push({ + name: "!! USER IS NOT ON THE SERVER !!", + value: embedPadding, + }); + } + msg.channel.createMessage({ embed }); + return; } else{ embed.fields.push({ @@ -856,61 +871,52 @@ export class UtilityPlugin extends ZeppelinPlugin { }); const roles = member.roles.map(id => this.guild.roles.get(id)).filter(r => !!r); - if(args.compact){ - embed.fields[0].value += `\n` + trimLines(`Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})**`); - } - else{ + embed.fields.push({ + name: "Member information", + value: + trimLines(` + Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})** + ${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""} + `) + embedPadding, + }); + const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null; + if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) { embed.fields.push({ - name: "Member information", + name: "Voice information", value: trimLines(` - Joined: **${joinAge} ago (${joinedAt.format("YYYY-MM-DD[T]HH:mm:ss")})** - ${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""} - `) + embedPadding, + ${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""} + ${member.voiceState.mute ? "Server voice muted: **Yes**" : ""} + ${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""} + `) + embedPadding, }); } - if(!args.compact){ - const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null; - if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) { - embed.fields.push({ - name: "Voice information", - value: - trimLines(` - ${voiceChannel ? `Current voice channel: **${voiceChannel ? voiceChannel.name : "None"}**` : ""} - ${member.voiceState.mute ? "Server voice muted: **Yes**" : ""} - ${member.voiceState.deaf ? "Server voice deafened: **Yes**" : ""} - `) + embedPadding, - }); - } - } } else { embed.fields.push({ name: "!! USER IS NOT ON THE SERVER !!", value: embedPadding, }); } - if(!args.compact){ - const cases = (await this.cases.getByUserId(user.id)).filter(c => !c.is_hidden); + const cases = (await this.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; - }); + 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 => { - return `${CaseTypes[c.type]} (#${c.case_number})`; - }); + const caseSummary = cases.slice(0, 3).map(c => { + return `${CaseTypes[c.type]} (#${c.case_number})`; + }); - const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary"; + const summaryText = cases.length > 3 ? "Last 3 cases" : "Summary"; - embed.fields.push({ - name: "Cases", - value: trimLines(` - Total cases: **${cases.length}** - ${summaryText}: ${caseSummary.join(", ")} - `), - }); - } + embed.fields.push({ + name: "Cases", + value: trimLines(` + Total cases: **${cases.length}** + ${summaryText}: ${caseSummary.join(", ")} + `), + }); } msg.channel.createMessage({ embed }); } From 1d1de40e35390863c448fdd1de87b9f1e582fd9d Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Sat, 11 Jan 2020 10:26:47 +1100 Subject: [PATCH 3/3] fixed whitespace --- backend/src/plugins/Utility.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/plugins/Utility.ts b/backend/src/plugins/Utility.ts index ce89b98e..c083b988 100644 --- a/backend/src/plugins/Utility.ts +++ b/backend/src/plugins/Utility.ts @@ -879,6 +879,7 @@ export class UtilityPlugin extends ZeppelinPlugin { ${roles.length > 0 ? "Roles: " + roles.map(r => r.name).join(", ") : ""} `) + embedPadding, }); + const voiceChannel = member.voiceState.channelID ? this.guild.channels.get(member.voiceState.channelID) : null; if (voiceChannel || member.voiceState.mute || member.voiceState.deaf) { embed.fields.push({ @@ -896,6 +897,7 @@ export class UtilityPlugin extends ZeppelinPlugin { name: "!! USER IS NOT ON THE SERVER !!", value: embedPadding, }); + } const cases = (await this.cases.getByUserId(user.id)).filter(c => !c.is_hidden); @@ -918,6 +920,7 @@ export class UtilityPlugin extends ZeppelinPlugin { `), }); } + msg.channel.createMessage({ embed }); }