Module: ESM::Command::Base::Permissions
- Included in:
- ESM::Command::Base
- Defined in:
- lib/esm/command/base/permissions.rb
Instance Method Summary collapse
- #command_allowed? ⇒ Boolean
-
#command_allowed_in_channel? ⇒ Boolean
Is the command allowed in this text channel?.
- #command_allowlist_enabled? ⇒ Boolean
- #command_enabled? ⇒ Boolean
- #community_permissions? ⇒ Boolean
- #cooldown_time ⇒ Object
- #notify_when_command_disabled? ⇒ Boolean
Instance Method Details
#command_allowed? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/esm/command/base/permissions.rb', line 49 def command_allowed? return true if !command_allowlist_enabled? community = target_community || current_community return false if community.nil? server = ESM.bot.server(community.guild_id.to_i) guild_member = current_user.on(server) return false if guild_member.nil? allowlisted_role_ids = if .allowlisted_role_ids else attributes.allowlisted_role_ids.default || [] end return true if guild_member.(:administrator) return false if allowlisted_role_ids.empty? allowlisted_role_ids.any? { |role_id| guild_member.role?(role_id.to_i) } end |
#command_allowed_in_channel? ⇒ Boolean
Is the command allowed in this text channel?
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/esm/command/base/permissions.rb', line 73 def command_allowed_in_channel? return true if current_channel.pm? return true if current_community&.player_mode_enabled? return .allowed_in_text_channels? if allowed_define = attributes.allowed_in_text_channels return allowed_define.default if allowed_define.default? true end |
#command_allowlist_enabled? ⇒ Boolean
40 41 42 43 44 45 46 47 |
# File 'lib/esm/command/base/permissions.rb', line 40 def command_allowlist_enabled? if .allowlist_enabled? else allowlist_enabled = attributes.allowlist_enabled allowlist_enabled.default? ? allowlist_enabled.default : false end end |
#command_enabled? ⇒ Boolean
23 24 25 26 27 28 29 30 |
# File 'lib/esm/command/base/permissions.rb', line 23 def command_enabled? if .enabled? else enabled = attributes.enabled enabled.default? ? enabled.default : true end end |
#community_permissions? ⇒ Boolean
7 8 9 10 |
# File 'lib/esm/command/base/permissions.rb', line 7 def # Caching so if community_permissions returns `nil`, it doesn't hit the database for every call to this method @community_permission_predicate ||= !.nil? end |
#cooldown_time ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/esm/command/base/permissions.rb', line 12 def cooldown_time if # [2, "seconds"] -> 2 seconds # Calls .seconds, .days, .months, etc .cooldown_quantity.send(.cooldown_type) else cooldown_time = attributes.cooldown_time cooldown_time.default? ? cooldown_time.default : 2.seconds end end |
#notify_when_command_disabled? ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/esm/command/base/permissions.rb', line 32 def notify_when_command_disabled? if .notify_when_disabled? else true end end |