You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
#!/usr/bin/env ruby
|
|
|
|
require 'rubygems'
|
|
require 'yaml'
|
|
require 'telegram/bot'
|
|
|
|
#conf = YAML.load(File.read("bot_config.yaml"))
|
|
conf = YAML.load_file("bot_config.yaml")
|
|
token = conf['token']
|
|
telnet = conf['telnet']
|
|
puts conf['telnet']
|
|
puts "Empyrion Host: #{telnet['host']}"
|
|
puts "Bot token: #{token}"
|
|
|
|
def handle_message(message)
|
|
reply = 'Empty String'
|
|
conf = YAML.load_file("bot_config.yaml")
|
|
telnet = conf['telnet']
|
|
case message.text.split(" ")[0].split("@")[0].downcase #Strip command from arguments and @tags
|
|
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 = `./srvstart`
|
|
when '/srvstop'
|
|
reply = `./srvstop`
|
|
when '/status'
|
|
reply = `./srvstatus #{telnet['host']} #{telnet['port']} #{telnet['pass']}`
|
|
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|
|
|
reply = handle_message message
|
|
bot.api.send_message(chat_id: message.chat.id, text: "#{reply}")
|
|
end
|
|
end
|
|
|