2022-04-20 19:01:58 +00:00
|
|
|
const fsPromises = require("fs/promises");
|
2022-11-08 20:23:13 +00:00
|
|
|
import dir from 'path';
|
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
2022-04-20 19:01:58 +00:00
|
|
|
|
2022-11-08 20:23:13 +00:00
|
|
|
import ListUsersService from "../services/UserServices/ListUsersService"
|
2022-04-20 19:01:58 +00:00
|
|
|
|
|
|
|
const _botIsOnQueue = async (botName: string) => {
|
|
|
|
|
2022-11-08 20:23:13 +00:00
|
|
|
const botInfoFile = dir.join(os.tmpdir(), `botInfo.json`);
|
|
|
|
|
|
|
|
console.log('The bot botInfoFile: ', botInfoFile)
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (fs.existsSync(botInfoFile)) {
|
|
|
|
|
|
|
|
console.log('botInfo.json file exists');
|
2022-04-20 19:01:58 +00:00
|
|
|
|
2022-11-08 20:23:13 +00:00
|
|
|
const botInfo = fs.readFileSync(botInfoFile, {encoding:'utf8', flag:'r'});
|
|
|
|
|
|
|
|
return JSON.parse(botInfo)
|
2022-04-20 19:01:58 +00:00
|
|
|
|
2022-11-08 20:23:13 +00:00
|
|
|
} else {
|
|
|
|
console.log('botInfo.json file not found!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.log('There was an error on try to read the botInfo.json file: ',error)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ')
|
|
|
|
|
|
|
|
const { users, count, hasMore } = await ListUsersService({ searchParam: `${botName}`, pageNumber: 1 });
|
|
|
|
let botIsOnQueue = false
|
|
|
|
let userIdBot = null
|
|
|
|
let queueId = null
|
|
|
|
|
|
|
|
if (users.length > 0) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
console.log('----------------- bot queue id: ', Object(users)[0]["queues"][0].id)
|
|
|
|
queueId = Object(users)[0]["queues"][0].id;
|
|
|
|
userIdBot = Object(users)[0].id
|
|
|
|
botIsOnQueue = true
|
|
|
|
|
|
|
|
fs.writeFileSync(botInfoFile, JSON.stringify({ userIdBot: userIdBot, botQueueId: queueId, isOnQueue: botIsOnQueue }), "utf8");
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.log('O usuário botqueue não está em nenhuma fila err: ', err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('Usuário botqueue não existe!')
|
|
|
|
|
|
|
|
fs.writeFileSync(botInfoFile, JSON.stringify({ isOnQueue: false, botQueueId: 0, userIdBot: 0 }), "utf8");
|
|
|
|
|
2022-04-20 19:01:58 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 20:23:13 +00:00
|
|
|
return { userIdBot: userIdBot, botQueueId: queueId, isOnQueue: botIsOnQueue }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default _botIsOnQueue;
|