diff --git a/commands.rb b/commands.rb index 4de966b..5f2885e 100644 --- a/commands.rb +++ b/commands.rb @@ -71,6 +71,10 @@ end def process_command_srvstatus(message, command, adm) if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) telnet = @conf['telnet'] + if `nc -zvw3 #{telnet['host']} #{telnet['port']}` + #bot.api.send_message(chat_id: message.chat.id, text: "Server is online!\nGathering server information...") + `./scripts/srvstatus.receipt #{@conf['token']} #{message.chat.id}` + end reply = `./scripts/srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}` else reply = "Refusal: I am not authorized to provide this information here." @@ -78,3 +82,13 @@ def process_command_srvstatus(message, command, adm) return reply end +def process_command_patchnotes(message, command, adm) + if is_chat_authorized?(message, @auth_chat) || message_from_admin?(message, adm) + telnet = @conf['telnet'] + reply = `cat patchnotes.txt` + else + reply = "Refusal: I am not authorized to provide this information here." + end + return reply +end + diff --git a/patchnotes.txt b/patchnotes.txt new file mode 100644 index 0000000..ffbb3c9 --- /dev/null +++ b/patchnotes.txt @@ -0,0 +1,5 @@ +New features: ++ Auto self-resurrection after random bot-suicide. ++ This `/patchnotes` command. ++ Instant message confirmation for `/status` command. + diff --git a/run.rb b/run.rb index 4b4eb6c..21d5cc5 100755 --- a/run.rb +++ b/run.rb @@ -123,6 +123,8 @@ def handle_message(message) #else # reply = "Refusal: I am not authorized to provide this information here." #end + when '/patch', '/patchnotes' + reply = process_command_patchnotes(message, command, adm) when '/location', '/whereareyou' if message_from_admin?(message, adm) || is_chat_authorized?(message, @auth_chat) reply = "I am currently located at:\n\nHost: #{`head -n1 /etc/hostname`}ExtIP: #{`curl myip.contegix.com 2>/dev/null`}" diff --git a/scripts/srvstatus.receipt b/scripts/srvstatus.receipt new file mode 100755 index 0000000..18cf61b --- /dev/null +++ b/scripts/srvstatus.receipt @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin + +KEY=$1 +CHATID=$2 +TIME="4" +URL="https://api.telegram.org/bot$KEY/sendMessage" +MESSAGE="Confirmation: The server appears online! +One moment while I collect some server information..." + +curl -s --max-time $TIME -d "chat_id=${CHATID}&disable_web_page_preview=1&text=${MESSAGE}" $URL >/dev/null +