1
0

Add pause / unpause command via chat to bot

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-06-27 13:27:21 -07:00
parent 1fcc9f0928
commit ee87f635e4

View File

@ -193,6 +193,8 @@ const tryBuild = () => {
};
let sleeping = false;
let paused = false;
const sleep = async (delay) => {
if (sleeping) {
return;
@ -773,6 +775,39 @@ const message = async (data) => {
case 'game-update':
/* Keep game updated with the latest information */
Object.assign(game, data.update);
if (data.update.chat) {
let newState = paused;
const rePause = new RegExp(`${name}: pause`, 'i');
const reUnpause = new RegExp(`${name}: unpause`, 'i');
for (let i = 0; i < data.update.chat.length; i++) {
if (data.update.chat[i].message.match(rePause)) {
newState = true;
continue;
}
if (data.update.chat[i].message.match(reUnpause)) {
newState = false;
continue;
}
}
if (newState !== paused) {
paused = newState;
send({
type: 'chat',
message: `Robot AI is now ${paused ? '' : 'un'}paused.`
});
}
}
if (paused) {
if (waitingFor) {
Object.assign(received, data.update);
}
return;
}
if (sleeping) {
if (waitingFor) {
Object.assign(received, data.update);