refactors and checks
This commit is contained in:
parent
af131189f9
commit
b4fd4f976c
11
index.js
11
index.js
@ -1,3 +1,5 @@
|
||||
const { delete } = require('got')
|
||||
|
||||
const { client, xml } = require('@xmpp/client'),
|
||||
got = require('got'),
|
||||
config = require('./config'),
|
||||
@ -28,8 +30,6 @@ xmpp.on('stanza', async stanza => {
|
||||
const message = stanza.getChildText('body')
|
||||
if (message && game.status && game.status.isFinished) {
|
||||
sendMessage('Jaque mate. Juego terminado.')
|
||||
} else if (message && game.status && game.status.checkMate) {
|
||||
sendMessage('Jaque.')
|
||||
} else if (message && message.split(' ').length === 3
|
||||
&& message.split(' ')[0] === '.move'
|
||||
&& message.split(' ')[1].match(/^[A-H1-8]{2}$/)
|
||||
@ -40,6 +40,9 @@ xmpp.on('stanza', async stanza => {
|
||||
const d = Date.now()
|
||||
game.aiMove(iaLevel)
|
||||
time = Date.now() - d
|
||||
if (game.status && game.status.checkMate) {
|
||||
sendMessage('Jaque.')
|
||||
}
|
||||
imageGenerator = new ChessImageGenerator({
|
||||
size: 720,
|
||||
light: 'rgb(200, 200, 200)',
|
||||
@ -73,8 +76,10 @@ xmpp.on('stanza', async stanza => {
|
||||
const req = await got.put(stanza.getChild('slot').getChild('put').attrs.url, {
|
||||
body: buf
|
||||
}).catch(console.error)
|
||||
if (req && req.url) {
|
||||
if (req && req.url && time) {
|
||||
sendMessage('Su turno: ' + req.url + ' movimiento IA en ' + (time / 1000) + 's')
|
||||
imageGenerator = null
|
||||
time = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user