MessageProcessor

MessageProcessor

Represents a message processor. Message processors cannot be constructed directly. The constructor is shown here due to JSDoc limitations. Message processors are constructed by the MessageProcessorManager which reads the message processor definition modules in your message processors directory (specified as a constructor option to Monochrome) and constructs message processors accordingly. For help constructing a message processor definition, and an example, see MessageProcessor~MessageProcessorDefinition. For a full working example of a message processor, see the example palindrome command.

Constructor

new MessageProcessor()

Source:

Type Definitions

MessageProcessorDefinition

Description:
  • A definition of one message processor. Each message processor definition should be a module in your message processors directory (specified as a constructor option to Monochrome). Each message processor definition file should export one message processor definition.
Source:
Properties:
Name Type Attributes Default Description
name String A name for the message processor. This can be anything, and will not be shown to users. It exists solely for logging purposes.
action MessageProcessor~action A function to examine the message, and decide whether to process it.
logLevel String <optional>
'info' The level to log events to, or 'none' for no logging. Bunyan levels are valid: 'trace', 'debug', 'info', etc.
priority Number <optional>
0 The priority of the message processor. Higher number means higher priority. Higher priority message processors get a chance to process the message before lower priority message processors.
A definition of one message processor. Each message processor definition should be a module in your message processors directory (specified as a constructor option to Monochrome). Each message processor definition file should export one message processor definition.
Type:
  • Object
Example
module.exports = {
   name: 'Palindrome',
   action(bot, msg, monochrome) {
     const text = msg.content;
     if (!text || text.length < 2) {
       return false; // Since we are not interested in handling this message, return false.
     }
     const textBackwards = text.split('').reverse().join('');
     if (text === textBackwards) {
       return msg.channel.createMessage('That\'s a palindrome!'); // Since we are handling this message, return a promise (could also return true)
     } else {
       return false; // Since we are not interested in handling this message, return false.
     }
   }
 };

action(bot, msg, monochrome) → {boolean|Promise}

Description:
  • This function will be invoked with any message that the bot receives that is not handled by a command or another message processor. This function examines the message and either ignores it or takes action on it.
Source:
Parameters:
Name Type Description
bot external:"Eris.Client"
msg external:"Eris.Message" The message to consider handling.
monochrome Monochrome
Returns:
If the message processor will not handle this message, you should return false (not a promise that resolves to false). If a promise is returned, the message processor is assumed to have accepted the message, and it will not be propogated further. True may also be returned. If a promise is returned, it will be resolved, and if it rejects, the error will be handled and logged.
Type
boolean | Promise