1
0
Fork 0

Add bot command /shrug

This commit is contained in:
Alex Kotov 2018-12-07 08:54:59 +05:00
parent 15c192874d
commit a9b3f77466
No known key found for this signature in database
GPG key ID: 4E831250F47DE154

View file

@ -26,10 +26,31 @@ private
record: @telegram_bot
end
def handle_message(message)
def handle_message(message) # rubocop:disable Metrics/MethodLength
return if message.blank?
_telegram_chat = handle_chat message[:chat]
telegram_chat = handle_chat message[:chat]
return if @telegram_bot.username.nil?
expected = case telegram_chat.chat_type
when 'private'
'/shrug'
when 'group', 'supergroup'
"/shrug@#{@telegram_bot.username}"
else
return
end
return unless message[:text] == expected
RestClient.get(
"https://api.telegram.org/bot#{@telegram_bot.api_token}/sendMessage",
params: {
chat_id: telegram_chat.remote_id,
text: '¯\_(ツ)_/¯',
},
)
end
def handle_chat(chat)