Fixed logging delays, added /help alias (#3)

dev^2
Aaron Johnson 6 years ago committed by Gitea
parent e90740bee6
commit 6e56303346

@ -28,16 +28,18 @@ end
def process_command_start(message, command, adm) def process_command_start(message, command, adm)
reply = "I am #{@botname}, and I am here to provide temperature information from various sensors. Currently I can retrieve information " + reply = "I am #{@botname}, and I am here to provide temperature information from various sensors. Currently I can retrieve information " +
"from temperature sensors. In a future version, I will also report when temperatures are out of a specified range through regular checks.\n\n" + "from temperature sensors. In a future version, I will also report when temperatures are out of a specified range through regular checks.\n\n" +
"Commands available:\n/start (Shows this message)\n/check or /c (Show a specific temperature interactively)\n/report or /r (Show all temperatures)\n" + "Commands available:\n/start or /help (Shows this message)\n/check or /c (Show a specific temperature interactively)\n/report or /r (Show all temperatures)\n" +
"/simple or /s (Show a simplified report)\n\nExtra functions:\n/whoami or /chatinfo (Provides IDs for internal use)\n/whereareyou or /location (Provides hostname for bot server)\n\n" + "/simple or /s (Show a simplified report)\n\nExtra functions:\n/whoami or /chatinfo (Provides IDs for internal use)\n/whereareyou or /location (Provides hostname for bot server)\n\n" +
"Check again later to see if any new functions have been added, or use /patchnotes to learn about recent updates.\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:\nhttps://git.skyfall.tech/skyfall/heatbot" "You can also view the source code at the following location:\nhttps://git.skyfall.tech/skyfall/heatbot"
if message_from_admin?(message, adm) if message_from_admin?(message, adm)
msg_from_admin = true msg_from_admin = true
end end
STDOUT.flush
if is_chat_authorized?(message, @auth_chat) if is_chat_authorized?(message, @auth_chat)
chat_authorized = true chat_authorized = true
end end
STDOUT.flush
if ! msg_from_admin && ! chat_authorized if ! msg_from_admin && ! chat_authorized
if message.from.id == message.chat.id if message.from.id == message.chat.id
reply = reply + "\n\nWARNING: I am not authorized to work with you directly. My functionality is limited." reply = reply + "\n\nWARNING: I am not authorized to work with you directly. My functionality is limited."
@ -82,6 +84,7 @@ def process_command_check(message, command, adm, simple=false)
puts " Option: #{k} is #{v["loc"].to_s}" puts " Option: #{k} is #{v["loc"].to_s}"
button_text = v["loc"].to_s button_text = v["loc"].to_s
options.insert(-1, Telegram::Bot::Types::InlineKeyboardButton.new(text: button_text, callback_data: "ZONE|#{k}")) options.insert(-1, Telegram::Bot::Types::InlineKeyboardButton.new(text: button_text, callback_data: "ZONE|#{k}"))
STDOUT.flush
end end
message_text = "Which area would you like to check?\n" message_text = "Which area would you like to check?\n"

@ -287,18 +287,20 @@ def send_message(chatid, message_text, imageurl = nil)
if imageurl != nil if imageurl != nil
#Send message with text as html link to image #Send message with text as html link to image
message = Telegram::Bot::Client.run(@token) {|bot| message = bot.api.send_message(chat_id: chatid, text: "#{message_text}<a href=\"#{imageurl}\">.</a>", parse_mode: "HTML") } message = Telegram::Bot::Client.run(@token) {|bot| message = bot.api.send_message(chat_id: chatid, text: "#{message_text}<a href=\"#{imageurl}\">.</a>", parse_mode: "HTML") }
puts timestamp + ": Sent: #{message_text.inspect}\n\n"
STDOUT.flush
#puts timestamp + ": Sent: #{message_text.inspect}\n\n" #puts timestamp + ": Sent: #{message_text.inspect}\n\n"
return message return message
else else
#Send a plain-text message #Send a plain-text message
message = Telegram::Bot::Client.run(@token) {|bot| bot.api.send_message(chat_id: chatid, text: message_text) } message = Telegram::Bot::Client.run(@token) {|bot| bot.api.send_message(chat_id: chatid, text: message_text) }
puts timestamp + ": Sent: #{message_text.inspect}\n\n" puts timestamp + ": Sent: #{message_text.inspect}\n\n"
STDOUT.flush
#puts message #puts message
#message = message["results"] #message = message["results"]
#puts message #puts message
return message return message
end end
STDOUT.flush
end end
def send_message_markdown(chatid, message_text) def send_message_markdown(chatid, message_text)
@ -352,8 +354,9 @@ def handle_message(message)
reply = 'Empty String' reply = 'Empty String'
adm = @conf['admin'] adm = @conf['admin']
puts timestamp + ": Received command from " + "#{message.from.username}".cyan.bold + " [" + "#{message.from.id}".cyan + "]: " + "#{command}".magenta.bold puts timestamp + ": Received command from " + "#{message.from.username}".cyan.bold + " [" + "#{message.from.id}".cyan + "]: " + "#{command}".magenta.bold
STDOUT.flush
case command case command
when '/start' when '/start', '/help'
process_command_start(message, command, adm) process_command_start(message, command, adm)
when '/patch', '/patchnotes', '/version', '/versioninfo' when '/patch', '/patchnotes', '/version', '/versioninfo'
process_command_patchnotes(message, command, adm) process_command_patchnotes(message, command, adm)
@ -426,6 +429,7 @@ def handle_exception(e, message, notify_users)
puts "PRINTING BACKTRACE...".yellow.bold puts "PRINTING BACKTRACE...".yellow.bold
puts e.backtrace puts e.backtrace
puts "=" * 60 puts "=" * 60
STDOUT.flush
if notify_users == true then if notify_users == true then
#is this a callback query or a message #is this a callback query or a message
case message case message

@ -1,5 +1,9 @@
SkyfallTech HeatBot SkyfallTech HeatBot
Patch Notes: Patch Notes:
v0.1.00 v1.0.01
+ Added /help as an alias for /start
+ Fixed logging delays related to a missing/misplaced STDOUT.flush calls
v1.0.00
+ Initial Release + Initial Release

Loading…
Cancel
Save