From fd1c4c9b85110d89f906e2afb766ef8811581773 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 13 Aug 2023 20:34:04 +0300 Subject: [PATCH] arg to send cr list in dms --- package.json | 51 ++++----- structure/commands/CannedReply.js | 175 +++++++++++++++--------------- 2 files changed, 114 insertions(+), 112 deletions(-) diff --git a/package.json b/package.json index a7d2c08..60f6720 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,26 @@ -{ - "name": "modmail", - "version": "1.0.0", - "main": "index.js", - "author": "Navy ", - "license": "MIT", - "private": false, - "description": "Modmail bot with eventual integration with Galactic Bot's API", - "scripts": { - "start": "node index.js", - "dev": "nodemon --ignore *.json index.js" - }, - "devDependencies": { - "eslint": "^7.28.0", - "nodemon": "^2.0.7" - }, - "dependencies": { - "chalk": "^4.0.0", - "diagnostics": "^2.0.2", - "discord.js": "^12.5.3", - "moment": "^2.29.4", - "winston": "^3.3.3", - "winston-transport": "^4.4.0" - } -} +{ + "name": "modmail", + "version": "1.0.0", + "main": "index.js", + "author": "Navy ", + "license": "MIT", + "private": false, + "description": "Modmail bot with eventual integration with Galactic Bot's API", + "scripts": { + "start": "node index.js", + "dev": "nodemon --ignore *.json index.js", + "dockerpub": "tsc && docker build . --tag navydotgif/modmail:latest && docker push navydotgif/modmail:latest " + }, + "devDependencies": { + "eslint": "^7.28.0", + "nodemon": "^2.0.7" + }, + "dependencies": { + "chalk": "^4.0.0", + "diagnostics": "^2.0.2", + "discord.js": "^12.5.3", + "moment": "^2.29.4", + "winston": "^3.3.3", + "winston-transport": "^4.4.0" + } +} diff --git a/structure/commands/CannedReply.js b/structure/commands/CannedReply.js index 4b22caa..35c1f59 100644 --- a/structure/commands/CannedReply.js +++ b/structure/commands/CannedReply.js @@ -1,88 +1,89 @@ -const Command = require('../Command'); - -class CannedReply extends Command { - - constructor (client) { - super(client, { - name: 'cannedreply', - aliases: [ 'cr', 'canned' ], - showUsage: true, - usage: `` - }); - } - - async execute (message, { args }) { - - const [ first ] = args.map((a) => a); - // eslint-disable-next-line prefer-const - let { channel, content, _caller } = message, - anon = false; - content = content.replace(`${this.client.prefix}${_caller}`, ''); - const op = args.shift().toLowerCase(); - - if (op === 'anon') { - anon = true; - content = content.replace(first, ''); - } else if ([ 'create', 'delete' ].includes(op)) { - return this.createCanned(op, args, message); - } else if ([ 'list' ].includes(first.toLowerCase())) { - - const list = Object.entries(this.client.modmail.replies); - let str = ''; - // eslint-disable-next-line no-shadow - for (const [ name, content ] of list) { - const substr = `**${name}:** ${content}\n`; - if (str.length + substr.length > 2000) { - await channel.send(str); - str = ''; - } - str += substr; - } - if (str.length) return channel.send(str); - return '**__None__**'; - - } - - return this.client.modmail.sendCannedResponse({ message, responseName: content.trim(), anon }); - - } - - async createCanned (op, args, { channel, author }) { - - if (args.length < 1) return { - error: true, - msg: 'Missing reply name' - }; - const [ _name, ...rest ] = args; - - const name = _name.toLowerCase(); - const canned = this.client.modmail.replies; - let confirmation = null; - - if (op === 'create') { - if (!rest.length) return { - error: true, - msg: 'Missing content' - }; - - if (canned[name]) { - confirmation = await this.client.prompt(`A canned reply by the name ${name} already exists, would you like to overwrite it?`, { channel, author }); - if (!confirmation) return 'Timed out.'; - confirmation = [ 'y', 'yes', 'ok' ].includes(confirmation.content.toLowerCase()); - if (!confirmation) return 'Cancelled'; - } - - canned[name] = rest.join(' '); - - } else { - delete canned[name]; - } - - this.client.modmail.saveReplies(); - return `Updated ${_name}`; - - } - -} - +const Command = require('../Command'); + +class CannedReply extends Command { + + constructor (client) { + super(client, { + name: 'cannedreply', + aliases: [ 'cr', 'canned' ], + showUsage: true, + usage: `` + }); + } + + async execute (message, { args }) { + + const [ first, second ] = args.map((a) => a); + // eslint-disable-next-line prefer-const + let { channel, content, _caller } = message, + anon = false; + content = content.replace(`${this.client.prefix}${_caller}`, ''); + const op = args.shift().toLowerCase(); + + if (op === 'anon') { + anon = true; + content = content.replace(first, ''); + } else if ([ 'create', 'delete' ].includes(op)) { + return this.createCanned(op, args, message); + } else if ([ 'list' ].includes(first.toLowerCase())) { + + const list = Object.entries(this.client.modmail.replies); + let str = ''; + if (second.toLowerCase() === '-dm') channel = await message.author.createDM(); + // eslint-disable-next-line no-shadow + for (const [ name, content ] of list) { + const substr = `**${name}:** ${content}\n`; + if (str.length + substr.length > 2000) { + await channel.send(str); + str = ''; + } + str += substr; + } + if (str.length) return channel.send(str); + return '**__None__**'; + + } + + return this.client.modmail.sendCannedResponse({ message, responseName: content.trim(), anon }); + + } + + async createCanned (op, args, { channel, author }) { + + if (args.length < 1) return { + error: true, + msg: 'Missing reply name' + }; + const [ _name, ...rest ] = args; + + const name = _name.toLowerCase(); + const canned = this.client.modmail.replies; + let confirmation = null; + + if (op === 'create') { + if (!rest.length) return { + error: true, + msg: 'Missing content' + }; + + if (canned[name]) { + confirmation = await this.client.prompt(`A canned reply by the name ${name} already exists, would you like to overwrite it?`, { channel, author }); + if (!confirmation) return 'Timed out.'; + confirmation = [ 'y', 'yes', 'ok' ].includes(confirmation.content.toLowerCase()); + if (!confirmation) return 'Cancelled'; + } + + canned[name] = rest.join(' '); + + } else { + delete canned[name]; + } + + this.client.modmail.saveReplies(); + return `Updated ${_name}`; + + } + +} + module.exports = CannedReply; \ No newline at end of file