Class: Xasin::Telegram::SingleUser

Inherits:
Object
  • Object
show all
Defined in:
lib/xasin/telegram/SingleUser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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/xasin/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

#httpCoreObject (readonly)

Returns the value of attribute httpCore.



7
8
9
# File 'lib/xasin/telegram/SingleUser.rb', line 7

def httpCore
  @httpCore
end

Instance Method Details

#delete_message(mID) ⇒ Object



66
67
68
# File 'lib/xasin/telegram/SingleUser.rb', line 66

def delete_message(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/xasin/telegram/SingleUser.rb', line 52

def edit_message(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/xasin/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/xasin/telegram/SingleUser.rb', line 73

def on_inlinebutton_press(&block)
	@inlinebutton_procs << block;
end

#on_message(&block) ⇒ Object



70
71
72
# File 'lib/xasin/telegram/SingleUser.rb', line 70

def on_message(&block)
	@message_procs << block;
end

#send_message(text, **args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/xasin/telegram/SingleUser.rb', line 40

def send_message(text, **args)
	args ||= Hash.new();
	args[:text] = text;

	args[:chat_id] 	=   @userID;
	args[:parse_mode]	||= "Markdown";

	sent_message = @httpCore.perform_post("sendMessage", args);

	return sent_message[:result][:message_id];
end