From 9def1dc95aad0d98ab1ac791ba2005da95785033 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 30 Oct 2020 20:02:55 -0600 Subject: [PATCH] A few additions to responses and new response filters --- commands/response.js | 26 ++++++++++++++++++++++++++ util/response/filterresponse.js | 6 +++++- util/ts/pagination.ts | 9 ++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/commands/response.js b/commands/response.js index b635930..cf3d5bb 100644 --- a/commands/response.js +++ b/commands/response.js @@ -41,6 +41,32 @@ module.exports = { tr.save(); return message.channel.send(`I removed the response \`${args[1].toLowerCase()}\`.${hadBinding ? `\n\n${bm}` : ''}`); } + if (['list', 'l'].includes(args[0].toLowerCase())) { + let tr = await Responses.findOne({gid: message.guild.id}); + if (!tr && !tr.responses.size) {return message.reply("This server has no responses for me to show you.");} + let s = "This server's response names: "; let resps = Array.from(tr.responses.keys()); + let resp; for (resp of resps) {s += `\`${resp}\`${resps.indexOf(resp) !== resps.length - 1 ? ', ' : ''}`;} + return message.channel.send(s); + } + if (['view', 'v'].includes(args[0].toLowerCase())) { + let tr = await Responses.findOne({gid: message.guild.id}); + if (!tr) {return message.reply("I'd give you information on a response, but this server doesn't have any.");} + if (!tr.responses.has(args[1].toLowerCase())) {return message.reply("I can't find that response.");} + let hasBinding = false; + let bm = ''; + tr.bindings.forEach((v, k) => {if (v === args[1].toLowerCase()) {hasBinding = true; bm += !bm.length ? `\`${k}\`` : `, \`${k}\``}}); + let infoEmbed = new Discord.MessageEmbed() + .setTitle("Response Info") + .setDescription(`Requested by ${message.member.displayName}`) + .addField("Name/ID", args[1].toLowerCase(), true) + .addField("Type", tr.responses.get(args[1].toLowerCase()).embed ? "Embed" : "Message", true) + .setColor('c375f0') + .setFooter("Natsuki", client.user.avatarURL()) + .setTimestamp(); + if (hasBinding) {infoEmbed.addField("Server Bindings", bm);} + return message.channel.send(infoEmbed); + } + return message.channel.send(`Syntax: \`${prefix}response \``); } diff --git a/util/response/filterresponse.js b/util/response/filterresponse.js index 6501ea3..3813574 100644 --- a/util/response/filterresponse.js +++ b/util/response/filterresponse.js @@ -2,6 +2,10 @@ module.exports = async (member, client, text) => { text = text .replace(/(?:{{member}}|{{m}})/gm, member.displayName) .replace(/(?:{{membercount}}|{{mc}})/gm, `${member.guild.members.cache.size}`) - .replace(/(?:{{owner}}|{{o}})/gm, member.guild.owner.displayName); + .replace(/(?:{{owner}}|{{o}})/gm, member.guild.owner.displayName) + .replace(/(?:{{ping}}|{{mp}}|{{memberping}}|{{p}})/gm, `<@${member.id}>`) + .replace(/(?:{{s}}|{{server}}|{{servername}}|{{sn}})/gm, member.guild.name) + .replace(/{{n}}/gm, '\n') + .replace(/{{nn}}/gm, '\n\n'); return text; }; \ No newline at end of file diff --git a/util/ts/pagination.ts b/util/ts/pagination.ts index 3f3ce96..14b1ada 100644 --- a/util/ts/pagination.ts +++ b/util/ts/pagination.ts @@ -18,7 +18,12 @@ export class Pagination { constructor (title: string, pages: Page[], zeroPage: Page | MessageEmbed, client: Client, message: Message, activationMessage: Message, timeout: number, description?: string, pageTemplate?: MessageEmbed) { this.title = title; - this.pages = pages; + + let tpages = []; + tpages.push(zeroPage); + let tpage: Page; for (tpage of pages) {tpages.push(tpage);} + this.pages = tpages; + this.zeroPage = zeroPage; this.message = message; this.timeout = timeout; @@ -77,6 +82,8 @@ export class Pagination { }; public init(): Pagination { + + return this; };