From 3c8fe2778281b7ef31828f9aad57909196c3f305 Mon Sep 17 00:00:00 2001 From: Matheus sampaio Queiroga Date: Tue, 29 Dec 2020 20:43:42 -0300 Subject: [PATCH 1/2] Update telegram_bot.js --- Services/telegram/telegram_bot.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Services/telegram/telegram_bot.js b/Services/telegram/telegram_bot.js index 9e1bb86..00816fd 100644 --- a/Services/telegram/telegram_bot.js +++ b/Services/telegram/telegram_bot.js @@ -2,14 +2,28 @@ 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(``) }) 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){ + 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`) -- 2.47.1 From 557246d3c327fb6fadd0a185b9bcd4c249fe290f Mon Sep 17 00:00:00 2001 From: Matheus sampaio Queiroga Date: Wed, 30 Dec 2020 11:57:54 -0300 Subject: [PATCH 2/2] The telegram module was activated the commands modified: Services/command.js modified: Services/telegram/telegram_bot.js modified: index.js --- Services/command.js | 2 +- Services/telegram/telegram_bot.js | 54 +++++++++++++++++++++++++++---- index.js | 2 +- 3 files changed, 49 insertions(+), 9 deletions(-) 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 00816fd..0ca58a0 100644 --- a/Services/telegram/telegram_bot.js +++ b/Services/telegram/telegram_bot.js @@ -12,15 +12,19 @@ Commands: /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(``) + 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)){ const bds_status = require('../../index').detect() if (!bds_status){ - require('../../index').start() + 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`) @@ -31,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()}` }; } -- 2.47.1