diff --git a/Services/command.js b/Services/command.js index 3ab932f..752cdc0 100644 --- a/Services/command.js +++ b/Services/command.js @@ -1,5 +1,5 @@ module.exports.command = (command) => { - if (bds_server_string == undefined) { + if (typeof bds_server_string === 'undefined') { console.error('Start Server!') } else { if (command == undefined) { diff --git a/Services/telegram/telegram_bot.js b/Services/telegram/telegram_bot.js index 9e1bb86..0ca58a0 100644 --- a/Services/telegram/telegram_bot.js +++ b/Services/telegram/telegram_bot.js @@ -2,14 +2,32 @@ const { Telegraf } = require('telegraf') const token = require('../../index').token const bot = new Telegraf(token) bot.start((ctx) => { - ctx.reply(`Hello ${ctx.message.from.username}\nWe have some things still being done in the programming of the new bot more works πŸ‘:\n\nCommands:\n/server_start\n/server_stop\n/server_restart\n/log\n/command: Commands are not working in this version, wait until it is broken\n\nThe messages are re-transmitted to the minecraft chat if it is already connected: βœ”\nMessage Control: ❌`) + const amenssagem = `Hello ${ctx.message.from.username} +We have some things still being done in the programming of the new bot more works πŸ‘: +Commands: +/server_start +/server_stop +/server_restart +/log +/command: Commands are not working in this version, wait until it is broken +The messages are re-transmitted to the minecraft chat if it is already connected: βœ” +Message Control: ❌` + ctx.reply(amenssagem) }) -bot.help((ctx) => ctx.reply('Use o/start')) +bot.help((ctx) => ctx.reply('Use o /start')) bot.action('delete', ({ deleteMessage }) => deleteMessage()) bot.command('server_start', (ctx) => { if (require('./check').checkUser(ctx.message.from.username)){ - console.log('Sucess') - ctx.reply(`Under maintenance ${ctx.message.from.username}`) + const bds_status = require('../../index').detect() + if (!bds_status){ + if (require('../../index').electron){ + document.getElementById('startButtom').click() + } else { + require('../../index').start() + }; + ctx.reply(`The server has started`) + } else + ctx.reply(`${ctx.message.from.username} already started`) } else { console.log('Erro'); ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`) @@ -17,16 +35,52 @@ bot.command('server_start', (ctx) => { }); bot.command('server_stop', (ctx) => { if (require('./check').checkUser(ctx.message.from.username)){ - console.log('Sucess') - ctx.reply(`Under maintenance ${ctx.message.from.username}`) + const bds_status = require('../../index').detect() + if (bds_status){ + require('../../index').stop() + ctx.reply(`O servidor esta parando`) + } else + ctx.reply(`${ctx.message.from.username} o servidor estΓ‘ parado`) } else { console.log('Erro'); ctx.reply(`Please contact the Server Administrator, You are not on the list, I count to add your username \(${ctx.message.from.username}\) on the whitelist`) }; }); bot.command('command', (ctx) =>{ - let commands = 'Commands are disabled globally, wait for some version that supports'; - ctx.reply(commands) + const bds_command = require('../../index').command + var command = ctx.message.text.replace('/command ', ''); + console.log(`Comandos para o servidor foram recebidos: ${command}`) + const fs = require('fs'); + const bds = require('../../index'); + const detect_log_file = fs.existsSync(bds.log_file); + bds_command(command) + if (detect_log_file){ + const old = fs.readFileSync(bds.log_file, 'utf8'); + setTimeout(() => { + var out = fs.readFileSync(bds.log_file, 'utf8'); + var name = out.replace(old, ''); + ctx.reply(name) + }, 1000); + } else { + ctx.reply('NΓ£o temos um arquivo log') + } +}); +bot.command('list', (ctx) =>{ + const bds_command = require('../../index').command + const fs = require('fs'); + const bds = require('../../index'); + const detect_log_file = fs.existsSync(bds.log_file); + bds_command('list') + if (detect_log_file){ + const old = fs.readFileSync(bds.log_file, 'utf8'); + setTimeout(() => { + var out = fs.readFileSync(bds.log_file, 'utf8'); + var name = out.replace(old, ''); + ctx.reply(name) + }, 1000); + } else { + ctx.reply('NO log file to get list player') + } }); bot.command('log', (ctx) => { const file_log_path = require('../../index').log_file; diff --git a/index.js b/index.js index 510b376..0e46bb1 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ function date(fu) { } else if (fu == 'hour'){ return `${today.getHours()}_${today.getMinutes()}` } else { - return `${String(today.getDate()).padStart(2, '0')}-${String(today.getMonth() + 1).padStart(2, '0')}-${today.getFullYear()}` + return `${String(today.getDate()).padStart(2, '0')}-${String(today.getMonth() + 1).padStart(2, '0')}-${today.getFullYear()}_${today.getHours()}-${today.getSeconds()}` }; }