https://github.com/skyrising/xmpp-bot
A bot that handles commands for you
https://github.com/skyrising/xmpp-bot
bot xmpp
Last synced: 5 months ago
JSON representation
A bot that handles commands for you
- Host: GitHub
- URL: https://github.com/skyrising/xmpp-bot
- Owner: skyrising
- License: gpl-3.0
- Created: 2017-01-02T20:59:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T12:37:10.000Z (over 9 years ago)
- Last Synced: 2025-10-24T14:21:01.653Z (8 months ago)
- Topics: bot, xmpp
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xmpp-bot
A bot that handles commands for you
[](http://standardjs.com/)
[](https://raw.githubusercontent.com/skyrising/xmpp-bot/master/LICENSE)
### Usage
```javascript
const XMPPBot = require('xmpp-bot');
let bot = new XMPPBot({
jid: 'juliet@capulet.tld',
password: 'romeo',
rooms: [
{jid: 'coven@chat.shakespeare.lit', nick: 'juliet'}
]
})
// register a command
bot.command('name', (answer, args, state, env) => {
... // do some work
answer(...) // answer with results
})
// or just return answer
bot.command('echo', (answer, args) => args.join(' '))
// disconnect when you're done (automatically done on process exit)
bot.disconnect();
```
#### Options
- [node-xmpp-client](http://node-xmpp.org/doc/client.html)'s
- `rooms`: List of rooms `{jid, nick}` the bot should join
#### 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 [args]` in a MUC (multi-user-chat)