Browse Source

initial commit

master
ale 3 years ago
commit
75dd7758ce
5 changed files with 111 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +17
    -0
      README.md
  3. +9
    -0
      config.js
  4. +59
    -0
      index.js
  5. +24
    -0
      package.json

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
node_modules
package-lock.json

+ 17
- 0
README.md View File

@ -0,0 +1,17 @@
# bot-recordatorio
## Bot de salas XMPP de recordatorio de eventos, para [ElBinario](https://elbinario.net)
## Install
```
npm i
```
## Config
```
Edit config.js
```
## Run
```
npm start
```
### License MIT

+ 9
- 0
config.js View File

@ -0,0 +1,9 @@
module.exports = {
nick: 'bot-recordatorio',
service: 'xmpp://domain.com',
username: '',
password: '',
room: 'room@rooms.domain.com',
admins: ['ale'],
commands: ['.nuevoevento', '.recordarevento', '.listareventos', '.borrarevento', '.reiniciarbot']
}

+ 59
- 0
index.js View File

@ -0,0 +1,59 @@
const { client, xml } = require('@xmpp/client'),
config = require('./config'),
xmpp = client({
service: config.service,
username: config.username,
password: config.password
}),
sendMessage = async message => {
await xmpp.send(xml(
'message',
{ type: 'groupchat', to: room },
xml('body', {}, message)
))
},
room = config.room,
nick = config.nick,
admins = config.admins,
commands = config.commands,
events = []
let eventInit = false
xmpp.on('error', err => {
console.error(err)
})
xmpp.on('offline', () => {
console.log('Go to offline')
})
xmpp.on('stanza', async stanza => {
if (stanza.is('message') && !stanza.getChild('delay')) {
const user = stanza.attrs.from.replace(/.*\//, '')
if (admins.some(admin => user === admin)) {
const message = stanza.getChildText('body')
if (eventInit) {
} else if (message === '.reiniciarbot') {
sendMessage('Reiniciando bot por ' + user + '...')
await xmpp.stop()
} else if (message === '.help') {
sendMessage('\nAyuda ' + nick + ': \n' + commands.map((c, i) => (i + 1) + ': ' + c).join('\n'))
}
}
}
})
xmpp.on('online', async address => {
await xmpp.send(xml(
'presence',
{ to: room + '/' + nick },
xml('x',
{ xmlns: 'http://jabber.org/protocol/muc' }
)
))
console.log('Connected like: ' + address)
})
xmpp.start().catch(console.error)

+ 24
- 0
package.json View File

@ -0,0 +1,24 @@
{
"name": "bot-recordatorio",
"version": "1.0.0",
"description": "Bot Recordatorio Eventos XMPP",
"main": "index.js",
"private": true,
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "https://gitea.hatthieves.es/manalejandro/bot-recordatorio"
},
"keywords": [
"bot",
"bot-recordatorio",
"xmpp"
],
"author": "ale",
"license": "MIT",
"dependencies": {
"@xmpp/client": "*"
}
}

Loading…
Cancel
Save