Module: Rubord::Intents

Defined in:
lib/rubord/models/flags.rb

Constant Summary collapse

FLAGS =
{
  guilds: 1 << 0,
  guild_members: 1 << 1,
  guild_bans: 1 << 2,
  guild_emojis: 1 << 3,
  guild_integrations: 1 << 4,
  guild_webhooks: 1 << 5,
  guild_invites: 1 << 6,
  guild_voice_states: 1 << 7,
  guild_presences: 1 << 8,
  guild_messages: 1 << 9,
  guild_message_reactions: 1 << 10,
  guild_message_typing: 1 << 11,
  direct_messages: 1 << 12,
  direct_message_reactions: 1 << 13,
  direct_message_typing: 1 << 14,
  message_content: 1 << 15,
  guild_scheduled_events: 1 << 16,
  auto_moderation_configuration: 1 << 20,
  auto_moderation_execution: 1 << 21,
}.freeze

Class Method Summary collapse

Class Method Details

.[](intent_name) ⇒ Object



71
72
73
# File 'lib/rubord/models/flags.rb', line 71

def [](intent_name)
  FLAGS[intent_name.to_sym] if intent_name
end

.allObject



75
# File 'lib/rubord/models/flags.rb', line 75

def all = FLAGS.values.reduce(0, :|)

.auto_moderation_configurationObject



176
177
178
# File 'lib/rubord/models/flags.rb', line 176

def auto_moderation_configuration
  FLAGS[:auto_moderation_configuration]
end

.auto_moderation_executionObject



180
181
182
# File 'lib/rubord/models/flags.rb', line 180

def auto_moderation_execution
  FLAGS[:auto_moderation_execution]
end

.combine(*intents) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rubord/models/flags.rb', line 89

def combine(*intents)
  intents.flatten.reduce(0) do |sum, intent|
    case intent
    when Integer
      sum | intent
    when Symbol, String
      value = FLAGS[intent.to_sym]
      unless value
        Rubord::Logger.warn "[Rubord:Intents] Unknown intent: #{intent.inspect}"
        next sum
      end
      sum | value
    else
      Rubord::Logger.warn "[Rubord:Intents] Invalid intent type: #{intent.class}"
      sum
    end
  end
end

.defaultObject



184
185
186
187
188
189
190
191
192
193
# File 'lib/rubord/models/flags.rb', line 184

def default
  combine(
    :guilds,
    :guild_members,
    :guild_messages,
    :guild_message_reactions,
    :direct_messages,
    :direct_message_reactions
  )
end

.direct_message_reactionsObject



160
161
162
# File 'lib/rubord/models/flags.rb', line 160

def direct_message_reactions
  FLAGS[:direct_message_reactions]
end

.direct_message_typingObject



164
165
166
# File 'lib/rubord/models/flags.rb', line 164

def direct_message_typing
  FLAGS[:direct_message_typing]
end

.direct_messagesObject



156
157
158
# File 'lib/rubord/models/flags.rb', line 156

def direct_messages
  FLAGS[:direct_messages]
end

.exists?(intent_name) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/rubord/models/flags.rb', line 77

def exists?(intent_name)
  FLAGS.key?(intent_name.to_sym)
end

.guild_bansObject



116
117
118
# File 'lib/rubord/models/flags.rb', line 116

def guild_bans
  FLAGS[:guild_bans]
end

.guild_emojisObject



120
121
122
# File 'lib/rubord/models/flags.rb', line 120

def guild_emojis
  FLAGS[:guild_emojis]
end

.guild_integrationsObject



124
125
126
# File 'lib/rubord/models/flags.rb', line 124

def guild_integrations
  FLAGS[:guild_integrations]
end

.guild_invitesObject



132
133
134
# File 'lib/rubord/models/flags.rb', line 132

def guild_invites
  FLAGS[:guild_invites]
end

.guild_membersObject



112
113
114
# File 'lib/rubord/models/flags.rb', line 112

def guild_members
  FLAGS[:guild_members]
end

.guild_message_reactionsObject



148
149
150
# File 'lib/rubord/models/flags.rb', line 148

def guild_message_reactions
  FLAGS[:guild_message_reactions]
end

.guild_message_typingObject



152
153
154
# File 'lib/rubord/models/flags.rb', line 152

def guild_message_typing
  FLAGS[:guild_message_typing]
end

.guild_messagesObject



144
145
146
# File 'lib/rubord/models/flags.rb', line 144

def guild_messages
  FLAGS[:guild_messages]
end

.guild_presencesObject



140
141
142
# File 'lib/rubord/models/flags.rb', line 140

def guild_presences
  FLAGS[:guild_presences]
end

.guild_scheduled_eventsObject



172
173
174
# File 'lib/rubord/models/flags.rb', line 172

def guild_scheduled_events
  FLAGS[:guild_scheduled_events]
end

.guild_voice_statesObject



136
137
138
# File 'lib/rubord/models/flags.rb', line 136

def guild_voice_states
  FLAGS[:guild_voice_states]
end

.guild_webhooksObject



128
129
130
# File 'lib/rubord/models/flags.rb', line 128

def guild_webhooks
  FLAGS[:guild_webhooks]
end

.guildsObject



108
109
110
# File 'lib/rubord/models/flags.rb', line 108

def guilds
  FLAGS[:guilds]
end

.include?(intent_value, intent_name) ⇒ Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/rubord/models/flags.rb', line 203

def include?(intent_value, intent_name)
  intent_value & self[intent_name] != 0
end

.message_contentObject



168
169
170
# File 'lib/rubord/models/flags.rb', line 168

def message_content
  FLAGS[:message_content]
end

.method_missing(name, *args) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/rubord/models/flags.rb', line 207

def method_missing(name, *args)
  if FLAGS.key?(name)
    FLAGS[name]
  elsif name.to_s.end_with?("?") && FLAGS.key?(name.to_s[0...-1].to_sym)
    intent_name = name.to_s[0...-1].to_sym
    if args.first.is_a?(Integer)
      args.first & FLAGS[intent_name] != 0
    else
      super
    end
  else
    super
  end
end

.namesObject



81
82
83
# File 'lib/rubord/models/flags.rb', line 81

def names
  FLAGS.keys
end

.privilegedObject



195
196
197
198
199
200
201
# File 'lib/rubord/models/flags.rb', line 195

def privileged
  combine(
    :guild_members,
    :guild_presences,
    :message_content
  )
end

.respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


222
223
224
225
226
# File 'lib/rubord/models/flags.rb', line 222

def respond_to_missing?(name, include_private = false)
  FLAGS.key?(name) ||
  (name.to_s.end_with?("?") && FLAGS.key?(name.to_s[0...-1].to_sym)) ||
  super
end

.valuesObject



85
86
87
# File 'lib/rubord/models/flags.rb', line 85

def values
  FLAGS.values
end