Class: Ruboty::SlackTakeTurns::Actions::Base
- Inherits:
-
Object
- Object
- Ruboty::SlackTakeTurns::Actions::Base
show all
- Defined in:
- lib/ruboty/slack_take_turns/actions/base.rb
Defined Under Namespace
Classes: ActionBaseError, CurrentUserNotFound, UserNotFound
Constant Summary
collapse
- NAMESPACE =
'slack_take_turns'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(message) ⇒ Base
Returns a new instance of Base.
9
10
11
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 9
def initialize(message)
@message = message
end
|
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
7
8
9
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 7
def message
@message
end
|
Instance Method Details
#channel ⇒ Object
13
14
15
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 13
def channel
message.to
end
|
#channel_data ⇒ Object
25
26
27
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 25
def channel_data
data[channel] ||= {}
end
|
#current_user_id ⇒ Object
29
30
31
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 29
def current_user_id
channel_data[:current_user_id]
end
|
#current_user_id=(id) ⇒ Object
33
34
35
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 33
def current_user_id=(id)
channel_data[:current_user_id] = id
end
|
#current_user_name ⇒ Object
49
50
51
52
53
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 49
def current_user_name
find_user_by_user_id(current_user_id)['name']
rescue
raise CurrentUserNotFound.new(chat_message: message)
end
|
#data ⇒ Object
21
22
23
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 21
def data
message.robot.brain.data[NAMESPACE] ||= {}
end
|
#excluded_user_ids ⇒ Object
45
46
47
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 45
def excluded_user_ids
channel_data[:excluded_user_ids] ||= []
end
|
#find_user_by_user_id(user_id) ⇒ Object
55
56
57
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 55
def find_user_by_user_id(user_id)
slack_client.all_users_hash[user_id] || raise(UserNotFound.new(user_id: user_id, chat_message: message))
end
|
#find_user_id_by_user_name(user_name) ⇒ Object
59
60
61
62
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 59
def find_user_id_by_user_name(user_name)
user = slack_client.all_users.find{|u| u['name'] == user_name}
user ? user['id'] : raise(UserNotFound.new(user_name: user_name, chat_message: message))
end
|
#sender_id ⇒ Object
17
18
19
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 17
def sender_id
message.from
end
|
#target_user_ids ⇒ Object
41
42
43
|
# File 'lib/ruboty/slack_take_turns/actions/base.rb', line 41
def target_user_ids
slack_client.channel_user_ids - excluded_user_ids
end
|