Class: Discorb::Intents
- Inherits:
-
Object
- Object
- Discorb::Intents
- Defined in:
- lib/discorb/intents.rb
Overview
Represents intents.
Class Attribute Summary collapse
-
.intent_bits -> Object
readonly
Returns the value of attribute intent_bits.
Class Method Summary collapse
-
.all -> Object
Create new intent object with all intents.
-
.default -> Object
Create new intent object with default values.
-
.from_value(value) -> Object
Create new intent object from raw value.
-
.none -> Object
Create new intent object with no intents.
Instance Method Summary collapse
-
#initialize(guilds: true, members: false, bans: true, emojis: true, integrations: true, webhooks: true, invites: true, voice_states: true, presences: false, messages: true, reactions: true, typing: true, dm_messages: true, dm_reactions: true, dm_typing: true) -> Intents
constructor
Create new intents object with default (no members and presence) intents.
- #inspect -> Object
- #method_missing(name, args = nil) -> Object
- #respond_to_missing?(sym, include_private) -> Boolean
-
#value -> Integer
Returns value of the intent.
Constructor Details
#initialize(guilds: true, members: false, bans: true, emojis: true, integrations: true, webhooks: true, invites: true, voice_states: true, presences: false, messages: true, reactions: true, typing: true, dm_messages: true, dm_reactions: true, dm_typing: true) -> Intents
Create new intents object with default (no members and presence) intents.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/discorb/intents.rb', line 44 def initialize(guilds: true, members: false, bans: true, emojis: true, integrations: true, webhooks: true, invites: true, voice_states: true, presences: false, messages: true, reactions: true, typing: true, dm_messages: true, dm_reactions: true, dm_typing: true) @raw_value = { guilds: guilds, members: members, bans: bans, emojis: emojis, integrations: integrations, webhooks: webhooks, invites: invites, voice_states: voice_states, presences: presences, messages: , reactions: reactions, typing: typing, dm_messages: , dm_reactions: dm_reactions, dm_typing: dm_typing, } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, args = nil) -> Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/discorb/intents.rb', line 78 def method_missing(name, args = nil) if @raw_value.key?(name) @raw_value[name] elsif name.end_with?("=") && @raw_value.key?(name[0..-2].to_sym) raise ArgumentError, "true/false expected" if (!args.is_a? TrueClass) || args.is_a?(FalseClass) @raw_value[name[0..-2].to_sym] = args else super end end |
Class Attribute Details
.intent_bits -> Object (readonly)
Returns the value of attribute intent_bits.
134 135 136 |
# File 'lib/discorb/intents.rb', line 134 def intent_bits @intent_bits end |
Class Method Details
.all -> Object
Create new intent object with all intents.
125 126 127 |
# File 'lib/discorb/intents.rb', line 125 def all from_value(32_767) end |
.default -> Object
Create new intent object with default values.
120 121 122 |
# File 'lib/discorb/intents.rb', line 120 def default from_value(32_509) end |
.from_value(value) -> Object
Create new intent object from raw value.
111 112 113 114 115 116 117 |
# File 'lib/discorb/intents.rb', line 111 def from_value(value) raw_value = {} @intent_bits.each do |intent, bit| raw_value[intent] = value & bit != 0 end new(**raw_value) end |
.none -> Object
Create new intent object with no intents.
130 131 132 |
# File 'lib/discorb/intents.rb', line 130 def none from_value(0) end |
Instance Method Details
#inspect -> Object
104 105 106 |
# File 'lib/discorb/intents.rb', line 104 def inspect "#<#{self.class} value=#{value}>" end |
#respond_to_missing?(sym, include_private) -> Boolean
90 91 92 |
# File 'lib/discorb/intents.rb', line 90 def respond_to_missing?(sym, include_private) @raw_value.key?(name) ? true : super end |
#value -> Integer
Returns value of the intent.
96 97 98 99 100 101 102 |
# File 'lib/discorb/intents.rb', line 96 def value res = 0 self.class.intent_bits.each do |intent, bit| res += bit if @raw_value[intent] end res end |