refactors and checks

This commit is contained in:
ale 2021-01-28 14:10:14 +01:00
parent af131189f9
commit b4fd4f976c

View File

@ -1,3 +1,5 @@
const { delete } = require('got')
const { client, xml } = require('@xmpp/client'), const { client, xml } = require('@xmpp/client'),
got = require('got'), got = require('got'),
config = require('./config'), config = require('./config'),
@ -28,8 +30,6 @@ xmpp.on('stanza', async stanza => {
const message = stanza.getChildText('body') const message = stanza.getChildText('body')
if (message && game.status && game.status.isFinished) { if (message && game.status && game.status.isFinished) {
sendMessage('Jaque mate. Juego terminado.') sendMessage('Jaque mate. Juego terminado.')
} else if (message && game.status && game.status.checkMate) {
sendMessage('Jaque.')
} else if (message && message.split(' ').length === 3 } else if (message && message.split(' ').length === 3
&& message.split(' ')[0] === '.move' && message.split(' ')[0] === '.move'
&& message.split(' ')[1].match(/^[A-H1-8]{2}$/) && message.split(' ')[1].match(/^[A-H1-8]{2}$/)
@ -40,6 +40,9 @@ xmpp.on('stanza', async stanza => {
const d = Date.now() const d = Date.now()
game.aiMove(iaLevel) game.aiMove(iaLevel)
time = Date.now() - d time = Date.now() - d
if (game.status && game.status.checkMate) {
sendMessage('Jaque.')
}
imageGenerator = new ChessImageGenerator({ imageGenerator = new ChessImageGenerator({
size: 720, size: 720,
light: 'rgb(200, 200, 200)', 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, { const req = await got.put(stanza.getChild('slot').getChild('put').attrs.url, {
body: buf body: buf
}).catch(console.error) }).catch(console.error)
if (req && req.url) { if (req && req.url && time) {
sendMessage('Su turno: ' + req.url + ' movimiento IA en ' + (time / 1000) + 's') sendMessage('Su turno: ' + req.url + ' movimiento IA en ' + (time / 1000) + 's')
imageGenerator = null
time = null
} }
} }
} }