From a4452e3272d5eb26a0cfc6904b421b6764cb82e0 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Mon, 24 Dec 2018 12:09:17 -0600 Subject: [PATCH] Modularization --- empyrion-bot.rb | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/empyrion-bot.rb b/empyrion-bot.rb index 46b7bfd..4d47ad9 100755 --- a/empyrion-bot.rb +++ b/empyrion-bot.rb @@ -9,27 +9,29 @@ token = conf['token'] puts 'Bot token: ' + token +def parse_message(message) + reply = 'Empty String' + case message.text + when '/start' + reply = "This bot will eventually (hopefully) be able retrieve information and pass start/stop commands from/to an Empyrion server, to make life easier for meatbags like you.\n\n" + + "Commands available:\n/start (Shows this message)\n/srvstart\n/srvstop\n/status\n/address" + when '/srvstart' + reply = "UNAVAILABLE: This command would start the game server if the code were there." + when '/srvstop' + reply = "UNAVAILABLE: This command would stop the game server if the code were there." + when '/status' + reply = "UNAVAILABLE: This command would provide server status and possibly version... If the code were there." + when '/location', '/ip', '/address' + reply = `curl myip.contegix.com` + end + puts "Sending #{reply.inspect}" + return reply +end + Telegram::Bot::Client.run(token) do |bot| bot.listen do |message| - case message.text - when '/start' - reply = "This bot will eventually (hopefully) be able retrieve information and pass start/stop commands from/to an Empyrion server, to make life easier for meatbags like you.\n\n" + - "Commands available:\n/start\n/srvstart\n/srvstop\n/status" - puts "Sending #{reply.inspect}" - bot.api.send_message(chat_id: message.chat.id, text: "#{reply}") - when '/srvstart' - reply = "UNAVAILABLE: This command would start the game server if the code were there." - puts "Sending #{reply.inspect}" - bot.api.send_message(chat_id: message.chat.id, text: "#{reply}") - when '/srvstop' - reply = "UNAVAILABLE: This command would stop the game server if the code were there." - puts "Sending #{reply.inspect}" - bot.api.send_message(chat_id: message.chat.id, text: "#{reply}") - when '/status' - reply = "UNAVAILABLE: This command would provide server status and possibly version... If the code were there." - puts "Sending #{reply.inspect}" - bot.api.send_message(chat_id: message.chat.id, text: "#{reply}") - end + reply = parse_message message + bot.api.send_message(chat_id: message.chat.id, text: "#{reply}") end end