Class: XNM::Telegram::SingleUser
- Inherits:
-
Object
- Object
- XNM::Telegram::SingleUser
- Defined in:
- lib/xnm/telegram/SingleUser.rb
Instance Attribute Summary collapse
-
#httpCore ⇒ Object
readonly
Returns the value of attribute httpCore.
Instance Method Summary collapse
- #delete_message(mID) ⇒ Object
- #edit_message(mID, text = nil, **args) ⇒ Object
- #handle_packet(packet) ⇒ Object
-
#initialize(userChat, httpCore) ⇒ SingleUser
constructor
A new instance of SingleUser.
- #on_inlinebutton_press(&block) ⇒ Object
- #on_message(&block) ⇒ Object
- #send_message(text, **args) ⇒ Object
Constructor Details
#initialize(userChat, httpCore) ⇒ SingleUser
Returns a new instance of SingleUser.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xnm/telegram/SingleUser.rb', line 9 def initialize(userChat, httpCore) # Check if we already have a HTTPCore, else create one @httpCore = if(httpCore.is_a? Telegram::HTTPCore) httpCore; else Telegram::HTTPCore.new(httpCore); end @httpCore.attach_receptor(self); @httpCore.attach_receptor(self); @userID = userChat; @message_procs = Array.new(); @inlinebutton_procs = Array.new(); end |
Instance Attribute Details
#httpCore ⇒ Object (readonly)
Returns the value of attribute httpCore.
7 8 9 |
# File 'lib/xnm/telegram/SingleUser.rb', line 7 def httpCore @httpCore end |
Instance Method Details
#delete_message(mID) ⇒ Object
66 67 68 |
# File 'lib/xnm/telegram/SingleUser.rb', line 66 def (mID) @httpCore.perform_post("deleteMessage", {chat_id: @userID, message_id: mID}); end |
#edit_message(mID, text = nil, **args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xnm/telegram/SingleUser.rb', line 52 def (mID, text=nil, **args) args[:chat_id] = @userID; args[:message_id] = mID; args[:parse_mode] ||= "Markdown"; if(text) then args[:text] = text; @httpCore.perform_post("editMessageText", args); else @httpCore.perform_post("editMessageReplyMarkup", args); end end |
#handle_packet(packet) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/xnm/telegram/SingleUser.rb', line 25 def handle_packet(packet) if(packet[:message]) return unless packet[:message][:chat][:id] == @userID; @message_procs.each do |cb| cb.call(packet[:message]); end packet[:has_been_handled] = true; end return unless packet[:callback_query] return unless packet[:callback_query][:message][:chat][:id] == @userID; @inlinebutton_procs.each { |cb| cb.call(packet[:callback_query]); } packet[:has_been_handled] = true; end |
#on_inlinebutton_press(&block) ⇒ Object
73 74 75 |
# File 'lib/xnm/telegram/SingleUser.rb', line 73 def (&block) @inlinebutton_procs << block; end |
#on_message(&block) ⇒ Object
70 71 72 |
# File 'lib/xnm/telegram/SingleUser.rb', line 70 def (&block) @message_procs << block; end |
#send_message(text, **args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xnm/telegram/SingleUser.rb', line 40 def (text, **args) args ||= Hash.new(); args[:text] = text; args[:chat_id] = @userID; args[:parse_mode] ||= "Markdown"; = @httpCore.perform_post("sendMessage", args); return [:result][:message_id]; end |