Add !edit and !delete with options (disabled by default)
parent
4e9e347b04
commit
3002473905
|
@ -89,6 +89,8 @@ const defaultConfig = {
|
||||||
"typingProxyReverse": false,
|
"typingProxyReverse": false,
|
||||||
"mentionUserInThreadHeader": false,
|
"mentionUserInThreadHeader": false,
|
||||||
"rolesInThreadHeader": false,
|
"rolesInThreadHeader": false,
|
||||||
|
"allowStaffEdit": false,
|
||||||
|
"allowStaffDelete": false,
|
||||||
|
|
||||||
"enableGreeting": false,
|
"enableGreeting": false,
|
||||||
"greetingMessage": null,
|
"greetingMessage": null,
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const { CommandManager, defaultParameterTypes, TypeConversionError } = require('knub-command-manager');
|
const { CommandManager, defaultParameterTypes, TypeConversionError, IParameter, ICommandConfig } = require('knub-command-manager');
|
||||||
|
const Eris = require('eris');
|
||||||
const config = require('./cfg');
|
const config = require('./cfg');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const threads = require('./data/threads');
|
const threads = require('./data/threads');
|
||||||
|
const Thread = require('./data/Thread');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createCommandManager(bot) {
|
createCommandManager(bot) {
|
||||||
|
@ -84,8 +86,19 @@ module.exports = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback InboxThreadCommandHandler
|
||||||
|
* @param {Eris.Message} msg
|
||||||
|
* @param {object} args
|
||||||
|
* @param {Thread} thread
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a command that can only be invoked in a thread on the inbox server
|
* Add a command that can only be invoked in a thread on the inbox server
|
||||||
|
* @param {string|RegExp} trigger
|
||||||
|
* @param {string|IParameter[]} parameters
|
||||||
|
* @param {InboxThreadCommandHandler} handler
|
||||||
|
* @param {ICommandConfig} commandConfig
|
||||||
*/
|
*/
|
||||||
const addInboxThreadCommand = (trigger, parameters, handler, commandConfig = {}) => {
|
const addInboxThreadCommand = (trigger, parameters, handler, commandConfig = {}) => {
|
||||||
const aliases = aliasMap.has(trigger) ? [...aliasMap.get(trigger)] : [];
|
const aliases = aliasMap.has(trigger) ? [...aliasMap.get(trigger)] : [];
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
const attachments = require("../data/attachments");
|
const attachments = require("../data/attachments");
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
|
const config = require('../cfg');
|
||||||
|
const Thread = require('../data/Thread');
|
||||||
|
|
||||||
module.exports = ({ bot, knex, config, commands }) => {
|
module.exports = ({ bot, knex, config, commands }) => {
|
||||||
// Mods can reply to modmail threads using !r or !reply
|
// Mods can reply to modmail threads using !r or !reply
|
||||||
|
@ -16,7 +18,6 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
aliases: ['r']
|
aliases: ['r']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Anonymous replies only show the role, not the username
|
// Anonymous replies only show the role, not the username
|
||||||
commands.addInboxThreadCommand('anonreply', '[text$]', async (msg, args, thread) => {
|
commands.addInboxThreadCommand('anonreply', '[text$]', async (msg, args, thread) => {
|
||||||
if (! args.text && msg.attachments.length === 0) {
|
if (! args.text && msg.attachments.length === 0) {
|
||||||
|
@ -29,4 +30,42 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
}, {
|
}, {
|
||||||
aliases: ['ar']
|
aliases: ['ar']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (config.allowStaffEdit) {
|
||||||
|
commands.addInboxThreadCommand('edit', '<messageNumber:number> <text:string$>', async (msg, args, thread) => {
|
||||||
|
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
|
||||||
|
if (! threadMessage) {
|
||||||
|
utils.postError(msg.channel, 'Unknown message number');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (threadMessage.user_id !== msg.author.id) {
|
||||||
|
utils.postError(msg.channel, 'You can only edit your own replies');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await thread.editStaffReply(msg.member, threadMessage, args.text)
|
||||||
|
}, {
|
||||||
|
aliases: ['e']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.allowStaffDelete) {
|
||||||
|
commands.addInboxThreadCommand('delete', '<messageNumber:number>', async (msg, args, thread) => {
|
||||||
|
const threadMessage = await thread.findThreadMessageByMessageNumber(args.messageNumber);
|
||||||
|
if (! threadMessage) {
|
||||||
|
utils.postError(msg.channel, 'Unknown message number');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (threadMessage.user_id !== msg.author.id) {
|
||||||
|
utils.postError(msg.channel, 'You can only delete your own replies');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await thread.deleteStaffReply(msg.member, threadMessage);
|
||||||
|
}, {
|
||||||
|
aliases: ['d']
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue