Module: Rubydium::Mixins::OtherActions
- Defined in:
- lib/rubydium/mixins/other_actions.rb
Instance Method Summary collapse
- #definitely_message(maybe_message) ⇒ Object
- #safe_delete(maybe_message, only_bot_or_owner: true) ⇒ Object
- #safe_delete_by_id(id, from_bot: false) ⇒ Object
Instance Method Details
#definitely_message(maybe_message) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubydium/mixins/other_actions.rb', line 22 def () return if .is_a? Telegram::Bot::Types::Message if ["message_id"] Telegram::Bot::Types::Message.new() elsif ["result"]["message_id"] Telegram::Bot::Types::Message.new(["result"]) else nil end rescue StandardError nil end |
#safe_delete(maybe_message, only_bot_or_owner: true) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/rubydium/mixins/other_actions.rb', line 4 def safe_delete(, only_bot_or_owner: true) = () from_owner = &.from&.username == config.owner_username from_bot = &.from&.id == config.bot_id return false unless only_bot_or_owner || from_bot || from_owner safe_delete_by_id(., from_bot: true) end |
#safe_delete_by_id(id, from_bot: false) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/rubydium/mixins/other_actions.rb', line 13 def safe_delete_by_id(id, from_bot: false) return false unless || from_bot result = @api.(chat_id: @chat.id, message_id: id) result["ok"] rescue Telegram::Bot::Exceptions::ResponseError false end |