Class: WatchmonkeyCli::TelegramBot::Event
- Inherits:
-
Object
- Object
- WatchmonkeyCli::TelegramBot::Event
show all
- Defined in:
- lib/watchmonkey_cli/hooks/telegram_bot.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, bot, event) ⇒ Event
Returns a new instance of Event.
9
10
11
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 9
def initialize app, bot, event
@app, @bot, @event = app, bot, event
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17
18
19
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 17
def method_missing method, *args, &block
@event.__send__(method, *args, &block)
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
7
8
9
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 7
def app
@app
end
|
#bot ⇒ Object
Returns the value of attribute bot.
7
8
9
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 7
def bot
@bot
end
|
Instance Method Details
#args ⇒ Object
60
61
62
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 60
def args
chunks[1..-1]
end
|
#chunks ⇒ Object
48
49
50
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 48
def chunks
@_chunks ||= message.split(" ")
end
|
#command ⇒ Object
56
57
58
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 56
def command
chunks.first if command?
end
|
#command? ⇒ Boolean
52
53
54
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 52
def command?
raw.is_a?(Telegram::Bot::Types::Message) && message.start_with?("/")
end
|
#from_descriptive ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 29
def from_descriptive
"".tap do |name|
name << "[BOT] " if from.is_bot
name << "#{from.first_name} " if from.first_name.present?
name << "#{from.last_name} " if from.last_name.present?
name << "(#{from.username}) " if from.username.present?
name << "[##{from.id}]"
end.strip
end
|
#message ⇒ Object
43
44
45
46
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 43
def message
return false unless message?
raw.text.to_s
end
|
#message? ⇒ Boolean
39
40
41
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 39
def message?
raw.is_a?(Telegram::Bot::Types::Message)
end
|
#raw ⇒ Object
13
14
15
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 13
def raw
@event
end
|
#reply(msg, msgopts = {}) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 64
def reply msg, msgopts = {}
return unless msg.present?
msgopts = msgopts.merge(text: msg, chat_id: raw.chat.id)
msgopts = msgopts.merge(reply_to_message_id: raw.message_id) unless msgopts[:quote] == false
app.telegram_bot_send(msgopts.except(:quote))
end
|
#user_admin? ⇒ Boolean
25
26
27
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 25
def user_admin?
user_data && user_data[1].include?(:admin_flag)
end
|
#user_data ⇒ Object
21
22
23
|
# File 'lib/watchmonkey_cli/hooks/telegram_bot.rb', line 21
def user_data
app.telegram_bot_get_udata(raw.from.id)
end
|