@ -4,9 +4,14 @@ require 'rubygems'
require 'yaml'
require 'telegram/bot'
require 'pp'
require 'time'
require_relative 'commands.rb'
require_relative 'colors.rb'
def timestamp
Time . now . strftime ( " %F %H:%M:%S " ) . yellow
end
#conf = YAML.load(File.read("bot_config.yaml"))
@conf = YAML . load_file ( " bot_config.yaml " )
@botname = @conf [ 'botname' ]
@ -17,6 +22,7 @@ admin = @conf['admin']
@allowed_sources = @conf [ 'allowed_sources' ]
### Begin sanity check ###
STDOUT . sync = true
errcount = 0
puts " Checking if environment is sane... \n \n "
print " Checking bot token ...................... "
@ -55,7 +61,7 @@ if admin.nil?
else
print " OK \n " . green . bold
end
print " Checking authori s ed chats ............... "
print " Checking authori z ed chats ............... "
if @auth_chat . nil?
errcount += 1
print " FAIL! \n \n " . red . bold
@ -71,14 +77,16 @@ if errcount > 0
else
print " Environment appears sane. \n \n " . green . bold
end
STDOUT . sync = false
### End sanity check ###
puts " Starting [ #{ @botname } ]... \n \n "
puts " Empyrion Host: #{ telnet [ 'host' ] } "
puts " Empyrion Telnet Port: #{ telnet [ 'port' ] } "
puts " Authorized administrator IDs: #{ admin } "
puts " Authorized chat IDs: #{ @auth_chat } "
puts " Bot token: #{ token } \n \n \n \n "
puts " Bot token: #{ token } "
puts " Start time: " + timestamp + " \n \n \n \n "
STDOUT . flush
#def process_command_srvstart(message)
# puts "Received command: srvstart"
@ -123,7 +131,7 @@ def handle_message(message)
#conf = YAML.load_file("bot_config.yaml")
telnet = @conf [ 'telnet' ]
adm = @conf [ 'admin' ]
puts " Received command from " + " #{ message . from . username } " . cyan . bold + " : #{ command } "
puts Time . now . strftime ( " %F %H:%M:%S" ) . yellow + " : Received command from " + " #{ message . from . username } " . cyan . bold + " [" + " #{ message . from . id } " . cyan + " ] : " + " #{ command } " . magenta . bold
case command
when '/start'
reply = " Introduction: I am #{ @botname } , and I am here to make life easier for meatbag admins like you. Currently I can retrieve information " +
@ -131,13 +139,19 @@ def handle_message(message)
" Commands available: \n /start (Shows this message) \n /srvstart (Currently non-functional) \n /srvstop \n /status \n /whoami or /chatinfo \n /whereareyou or /location \n \n " +
" Check again later to see if any new functions have been added, or use /patchnotes to learn about recent updates. \n " +
" You can also view the source code at the following location: \n https://git.skyfall.tech/skyfall/empyrion-bot "
if ! message_from_admin? ( message , adm ) && ! is_chat_authorized? ( message , @auth_chat )
if message_from_admin? ( message , adm )
msg_from_admin = true
end
if is_chat_authorized? ( message , @auth_chat )
chat_authorized = true
end
if ! msg_from_admin && ! chat_authorized
if message . from . id == message . chat . id
reply = reply + " \n \n WARNING: I am not authorized to work with you directly. My functionality is limited. "
else
reply = reply + " \n \n WARNING: I am not authorized to participate with this group. My functionality is limited. "
end
elsif message_from_admin? ( message , adm ) && ! is_chat_authorized? ( message , @auth_chat )
elsif m sg_from_admin && ! chat_authorized
reply = reply + " \n \n WARNING: Although you are my master, I have not been authorized to participate in this group. My functionality is limited. "
end
when '/srvstart'
@ -179,7 +193,8 @@ def handle_message(message)
reply = " Mockery: My name is #{ message . from . username } , I am a meatbag, and I think #{ command } is a valid command. "
end
# Verbose output:
puts " Sending #{ reply . inspect } \n \n "
puts timestamp + " : Sending #{ reply . inspect } \n \n "
STDOUT . flush
#puts "End of case"
return reply
end