class Tgbot::Update
Attributes
bot[R]
data[R]
Public Class Methods
new(bot, data)
click to toggle source
# File lib/tgbot.rb, line 54 def initialize bot, data @bot = bot @data = data end
Public Instance Methods
interrupt!()
click to toggle source
# File lib/tgbot.rb, line 59 def interrupt! @bot.instance_variable_get(:@tasks).clear end
Also aliased as: done!
match(pattern)
click to toggle source
# File lib/tgbot.rb, line 78 def match pattern return nil if pattern.nil? || text.nil? text.match(pattern) end
match?(pattern)
click to toggle source
# File lib/tgbot.rb, line 72 def match? pattern return true if pattern.nil? return false if text.nil? !!match(pattern) end
message()
click to toggle source
# File lib/tgbot.rb, line 83 def message @data.to_h.find { |k, v| k.match? /message|post/ }&.last end
message_id()
click to toggle source
# File lib/tgbot.rb, line 138 def message_id message&.message_id end
method_missing(meth, *args, &blk)
click to toggle source
# File lib/tgbot.rb, line 142 def method_missing meth, *args, &blk return @data[meth] if args.empty? && @data[meth] @bot.send(meth, *args, &blk) end
reply(*things, media: true, style: nil, **options)
click to toggle source
# File lib/tgbot.rb, line 91 def reply *things, media: true, style: nil, **options meth = :send_message payload = { chat_id: message&.chat.id } things.each do |x| if IO === x magic = MimeMagic.by_magic(x) case when magic.audio? meth = :send_audio payload[:audio] = x when magic.image? meth = :send_photo payload[:photo] = x when magic.video? meth = :send_video payload[:video] = x else meth = :send_document payload[:document] = x end else payload[:text] = x.to_s payload[:parse_mode] = 'Markdown' end end payload = payload.merge options case style when :at if payload[:text] && message.from from = message.from if payload[:parse_mode].match? /Markdown/i prefix = "[#{from.first_name}](tg://user?id=#{from.id}) " elsif payload[:parse_mode].match? /HTML/i prefix = "<a href=\"tg://user?id=#{from.id}\">#{from.first_name}</a> " else prefix = '' end payload[:text] = prefix + payload[:text] end when nil if !payload[:reply_to_message_id] payload[:reply_to_message_id] = message_id end end @bot.send meth, payload end
retry!(n=1)
click to toggle source
# File lib/tgbot.rb, line 65 def retry! n=1 @retried ||= n return if @retried <= 0 @bot.instance_variable_get(:@updates) << self @retried -= 1 end
text()
click to toggle source
# File lib/tgbot.rb, line 87 def text message&.text&.gsub(/(\/\w+)(@\w+)/, '\1') end