This is a child from Zirak's SO-ChatBot. For more info, on how to use the bot, see here.
Build:
run build
The plugin will runs when the bot initialize, you can use the following modes as your plugin bootstrap, it was a common used modes.
module.exports = function (bot) {
bot.addCommand({
name: 'papaya',
description: 'Papaya API',
permissions: {del: 'NONE', use: 'ALL'},
async: true,
fun: (message) => {
message.directReply('Papaya on the action');
}
});
};
module.exports = function (bot) {
bot.registerListener({
name: 'papaya',
listening: [
/(papaya[.!? ]|pawpaw[.!? ])$/i
],
cooldown: 60 * 1,
response: (message, match) => {
if (match[0][0].toLowerCase().startsWith('papaya')) message.directReply('Pawpaw!');
if (match[0][0].toLowerCase().startsWith('pawpaw')) message.directReply('Papaya!');
}
});
};
Add a command into bot.
- string
name
: Command name. - string
description
: Command description. Please be short and clear. - object
permissions
: Permitted user group. example:{del:'NONE',use:'ALL'}
- string
del
: Able to delete.'NONE'
/'ALL'
/'OWNER'
- string
use
: Able to use.'NONE'
/'ALL'
/'OWNER'
- string
- boolean
async
: Can be asynchronous. - function
fun
: A command entry point. example:(message)=>{ message.directReply('Hello'); }
- param
message
- param
·
Add a listener into bot.
- string
name
: Listener name. - RegExp[]
listening
: Listening sentences. - number
cooldown
: Cool down time inside room, in seconds. - function
response
: This will called when sentences matched, example:(message,match)=>{ message.directReply('Hello'); }
- param
message
- param
An event obtained from adapter. It just was an object that holds data, no functions inside.
- string
content
: A raw text of message. - number
event_type
: Type of event. - number
id
: Event Id. - number
message_id
: Id of message, useful when fetching partial message. - number
room_id
: Room Id of event. - string
room_name
: Room name of event. - number
time_stamp
: Time of event. - number
user_id
: User Id of sent message. - string
user_name
: User name of sent message. - more.. (some of them are only exists on some event)
·
An object contains parsed message from invoker, and some useful functions that can be used the most.
- A parsed message, using like string
let text = message
- The message is parsed, without pattern and command name.
- The message was a
full
message whencommand.multilines
was true, else it mightpartial
.
- Sending the
text
to the room.
- Sending the
text
to the room, with ping to theuserName
. - invoker user will be used when
userName
was not provided.
- Edits the message.
- Sending the
text
to the room. (same assend
)
- Sending the
text
to the room, with reply to the invoker message.
- Get the event of invoker message.
- Get the User Id of invoker.
- Get the Room Id of invoker.