arg to send cr list in dms
This commit is contained in:
parent
3c3ea9d90d
commit
fd1c4c9b85
51
package.json
51
package.json
@ -1,25 +1,26 @@
|
|||||||
{
|
{
|
||||||
"name": "modmail",
|
"name": "modmail",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Navy <navydotgif@gmail.com>",
|
"author": "Navy <navydotgif@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Modmail bot with eventual integration with Galactic Bot's API",
|
"description": "Modmail bot with eventual integration with Galactic Bot's API",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev": "nodemon --ignore *.json 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",
|
"devDependencies": {
|
||||||
"nodemon": "^2.0.7"
|
"eslint": "^7.28.0",
|
||||||
},
|
"nodemon": "^2.0.7"
|
||||||
"dependencies": {
|
},
|
||||||
"chalk": "^4.0.0",
|
"dependencies": {
|
||||||
"diagnostics": "^2.0.2",
|
"chalk": "^4.0.0",
|
||||||
"discord.js": "^12.5.3",
|
"diagnostics": "^2.0.2",
|
||||||
"moment": "^2.29.4",
|
"discord.js": "^12.5.3",
|
||||||
"winston": "^3.3.3",
|
"moment": "^2.29.4",
|
||||||
"winston-transport": "^4.4.0"
|
"winston": "^3.3.3",
|
||||||
}
|
"winston-transport": "^4.4.0"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -1,88 +1,89 @@
|
|||||||
const Command = require('../Command');
|
const Command = require('../Command');
|
||||||
|
|
||||||
class CannedReply extends Command {
|
class CannedReply extends Command {
|
||||||
|
|
||||||
constructor (client) {
|
constructor (client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'cannedreply',
|
name: 'cannedreply',
|
||||||
aliases: [ 'cr', 'canned' ],
|
aliases: [ 'cr', 'canned' ],
|
||||||
showUsage: true,
|
showUsage: true,
|
||||||
usage: `<canned response name>`
|
usage: `<canned response name>`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute (message, { args }) {
|
async execute (message, { args }) {
|
||||||
|
|
||||||
const [ first ] = args.map((a) => a);
|
const [ first, second ] = args.map((a) => a);
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let { channel, content, _caller } = message,
|
let { channel, content, _caller } = message,
|
||||||
anon = false;
|
anon = false;
|
||||||
content = content.replace(`${this.client.prefix}${_caller}`, '');
|
content = content.replace(`${this.client.prefix}${_caller}`, '');
|
||||||
const op = args.shift().toLowerCase();
|
const op = args.shift().toLowerCase();
|
||||||
|
|
||||||
if (op === 'anon') {
|
if (op === 'anon') {
|
||||||
anon = true;
|
anon = true;
|
||||||
content = content.replace(first, '');
|
content = content.replace(first, '');
|
||||||
} else if ([ 'create', 'delete' ].includes(op)) {
|
} else if ([ 'create', 'delete' ].includes(op)) {
|
||||||
return this.createCanned(op, args, message);
|
return this.createCanned(op, args, message);
|
||||||
} else if ([ 'list' ].includes(first.toLowerCase())) {
|
} else if ([ 'list' ].includes(first.toLowerCase())) {
|
||||||
|
|
||||||
const list = Object.entries(this.client.modmail.replies);
|
const list = Object.entries(this.client.modmail.replies);
|
||||||
let str = '';
|
let str = '';
|
||||||
// eslint-disable-next-line no-shadow
|
if (second.toLowerCase() === '-dm') channel = await message.author.createDM();
|
||||||
for (const [ name, content ] of list) {
|
// eslint-disable-next-line no-shadow
|
||||||
const substr = `**${name}:** ${content}\n`;
|
for (const [ name, content ] of list) {
|
||||||
if (str.length + substr.length > 2000) {
|
const substr = `**${name}:** ${content}\n`;
|
||||||
await channel.send(str);
|
if (str.length + substr.length > 2000) {
|
||||||
str = '';
|
await channel.send(str);
|
||||||
}
|
str = '';
|
||||||
str += substr;
|
}
|
||||||
}
|
str += substr;
|
||||||
if (str.length) return channel.send(str);
|
}
|
||||||
return '**__None__**';
|
if (str.length) return channel.send(str);
|
||||||
|
return '**__None__**';
|
||||||
}
|
|
||||||
|
}
|
||||||
return this.client.modmail.sendCannedResponse({ message, responseName: content.trim(), anon });
|
|
||||||
|
return this.client.modmail.sendCannedResponse({ message, responseName: content.trim(), anon });
|
||||||
}
|
|
||||||
|
}
|
||||||
async createCanned (op, args, { channel, author }) {
|
|
||||||
|
async createCanned (op, args, { channel, author }) {
|
||||||
if (args.length < 1) return {
|
|
||||||
error: true,
|
if (args.length < 1) return {
|
||||||
msg: 'Missing reply name'
|
error: true,
|
||||||
};
|
msg: 'Missing reply name'
|
||||||
const [ _name, ...rest ] = args;
|
};
|
||||||
|
const [ _name, ...rest ] = args;
|
||||||
const name = _name.toLowerCase();
|
|
||||||
const canned = this.client.modmail.replies;
|
const name = _name.toLowerCase();
|
||||||
let confirmation = null;
|
const canned = this.client.modmail.replies;
|
||||||
|
let confirmation = null;
|
||||||
if (op === 'create') {
|
|
||||||
if (!rest.length) return {
|
if (op === 'create') {
|
||||||
error: true,
|
if (!rest.length) return {
|
||||||
msg: 'Missing content'
|
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 (canned[name]) {
|
||||||
if (!confirmation) return 'Timed out.';
|
confirmation = await this.client.prompt(`A canned reply by the name ${name} already exists, would you like to overwrite it?`, { channel, author });
|
||||||
confirmation = [ 'y', 'yes', 'ok' ].includes(confirmation.content.toLowerCase());
|
if (!confirmation) return 'Timed out.';
|
||||||
if (!confirmation) return 'Cancelled';
|
confirmation = [ 'y', 'yes', 'ok' ].includes(confirmation.content.toLowerCase());
|
||||||
}
|
if (!confirmation) return 'Cancelled';
|
||||||
|
}
|
||||||
canned[name] = rest.join(' ');
|
|
||||||
|
canned[name] = rest.join(' ');
|
||||||
} else {
|
|
||||||
delete canned[name];
|
} else {
|
||||||
}
|
delete canned[name];
|
||||||
|
}
|
||||||
this.client.modmail.saveReplies();
|
|
||||||
return `Updated ${_name}`;
|
this.client.modmail.saveReplies();
|
||||||
|
return `Updated ${_name}`;
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = CannedReply;
|
module.exports = CannedReply;
|
Loading…
Reference in New Issue
Block a user