Class: Waylon::Condition Abstract
- Inherits:
-
Object
- Object
- Waylon::Condition
- Defined in:
- lib/waylon/condition.rb
Overview
Abstract route condition superclass
Direct Known Subclasses
Waylon::Conditions::BlackHole, Waylon::Conditions::Default, Waylon::Conditions::PermissionDenied, Waylon::Conditions::Regex
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#mechanism ⇒ Object
readonly
Returns the value of attribute mechanism.
Instance Method Summary collapse
-
#initialize(mechanism, action, allowed_groups, help = nil, mention_only = true) ⇒ Condition
constructor
rubocop:disable Style/OptionalBooleanParameter.
-
#matches?(_input) ⇒ Boolean
Placeholder for determining if this condition applies to the given input.
-
#mention_only? ⇒ Boolean
Is this condition only valid for Messages that directly mention the bot?.
-
#named_tokens(_input) ⇒ Hash<String,Object>
Placeholder for optionally providing named tokens.
-
#permits?(user) ⇒ Boolean
Checks if a user is allowed based on this condition.
-
#properly_mentions?(message) ⇒ Boolean
Determines of a message complies with the #mention_only? setting for this condition.
-
#tokens(_input) ⇒ Array<String>
Tokens is used to provide details about the message input to the action.
Constructor Details
#initialize(mechanism, action, allowed_groups, help = nil, mention_only = true) ⇒ Condition
rubocop:disable Style/OptionalBooleanParameter
15 16 17 18 19 20 21 |
# File 'lib/waylon/condition.rb', line 15 def initialize(mechanism, action, allowed_groups, help = nil, mention_only = true) @mechanism = mechanism @action = action @allowed_groups = allowed_groups @help = help @mention_only = mention_only end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/waylon/condition.rb', line 7 def action @action end |
#help ⇒ Object (readonly)
Returns the value of attribute help.
7 8 9 |
# File 'lib/waylon/condition.rb', line 7 def help @help end |
#mechanism ⇒ Object (readonly)
Returns the value of attribute mechanism.
7 8 9 |
# File 'lib/waylon/condition.rb', line 7 def mechanism @mechanism end |
Instance Method Details
#matches?(_input) ⇒ Boolean
Placeholder for determining if this condition applies to the given input
27 28 29 |
# File 'lib/waylon/condition.rb', line 27 def matches?(_input) false end |
#mention_only? ⇒ Boolean
Is this condition only valid for Messages that directly mention the bot?
33 34 35 |
# File 'lib/waylon/condition.rb', line 33 def mention_only? @mention_only end |
#named_tokens(_input) ⇒ Hash<String,Object>
Placeholder for optionally providing named tokens
40 41 42 |
# File 'lib/waylon/condition.rb', line 40 def named_tokens(_input) {} end |
#permits?(user) ⇒ Boolean
Checks if a user is allowed based on this condition
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/waylon/condition.rb', line 46 def permits?(user) return true if allows?(:everyone) Logger.log("Checking permissions for #{user.email}", :debug) group_class = user.class.sense.group_class # Check for global admins return true if Config.instance.admins.include?(user.email) # Check for managed admins return true if group_class.new("admins").include?(user) permitted = false [*@allowed_groups].each do |group| permitted = true if group_class.new(group).include?(user) break if permitted end permitted end |
#properly_mentions?(message) ⇒ Boolean
Determines of a message complies with the #mention_only? setting for this condition
68 69 70 71 72 73 |
# File 'lib/waylon/condition.rb', line 68 def properly_mentions?() return true unless mention_only? .to_bot? # (mention_only? && message.to_bot?) || (!mention_only? && !message.to_bot?) end |
#tokens(_input) ⇒ Array<String>
Tokens is used to provide details about the message input to the action
78 79 80 |
# File 'lib/waylon/condition.rb', line 78 def tokens(_input) [] end |