项目作者: skyrising

项目描述 :
A bot that handles commands for you
高级语言: JavaScript
项目地址: git://github.com/skyrising/xmpp-bot.git
创建时间: 2017-01-02T20:59:40Z
项目社区:https://github.com/skyrising/xmpp-bot

开源协议:GNU General Public License v3.0

下载


xmpp-bot

A bot that handles commands for you

js-standard-style
license

Usage

  1. const XMPPBot = require('xmpp-bot');
  2. let bot = new XMPPBot({
  3. jid: 'juliet@capulet.tld',
  4. password: 'romeo',
  5. rooms: [
  6. {jid: 'coven@chat.shakespeare.lit', nick: 'juliet'}
  7. ]
  8. })
  9. // register a command
  10. bot.command('name', (answer, args, state, env) => {
  11. ... // do some work
  12. answer(...) // answer with results
  13. })
  14. // or just return answer
  15. bot.command('echo', (answer, args) => args.join(' '))
  16. // disconnect when you're done (automatically done on process exit)
  17. bot.disconnect();

Options

Commands

Command functions are passed 4 arguments:

  • answer: function that sends the provided text or XML element
  • answer.broadcast: broadcast message to all rooms
  • args: array of arguments
  • state: an object that is saved for this command (=env[command-name])
  • env: state shared by all commands

Commands are executed when a message sent to the bot starts with their name
or when the bot is mentioned with @nick <command> [args] in a MUC (multi-user-chat)