Two-Part Logging Implementation #4

Merged
ajohnson merged 7 commits from dev into master 6 years ago

@ -28,16 +28,18 @@ end
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 " +
"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" +
"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"
if message_from_admin?(message, adm)
msg_from_admin = true
end
STDOUT.flush
if is_chat_authorized?(message, @auth_chat)
chat_authorized = true
end
STDOUT.flush
if ! msg_from_admin && ! chat_authorized
if message.from.id == message.chat.id
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}"
button_text = v["loc"].to_s
options.insert(-1, Telegram::Bot::Types::InlineKeyboardButton.new(text: button_text, callback_data: "ZONE|#{k}"))
STDOUT.flush
end
message_text = "Which area would you like to check?\n"

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

@ -1,5 +1,13 @@
SkyfallTech HeatBot
Patch Notes:
v0.1.00
v1.0.02
+ Implemented two-part sent message logging (affects server only)
+ Added /help command (same as /start)
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

Loading…
Cancel
Save