Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Defined in:
- lib/discordrb/data.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Array of channels on the server.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner_id ⇒ Object
readonly
Returns the value of attribute owner_id.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#roles ⇒ Object
readonly
Array of roles on the server.
Instance Method Summary collapse
- #add_role(role) ⇒ Object
- #delete_role(role_id) ⇒ Object
-
#initialize(data, bot) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(data, bot) ⇒ Server
Returns a new instance of Server.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/discordrb/data.rb', line 289 def initialize(data, bot) @bot = bot @region = data['region'] @name = data['name'] @owner_id = data['owner_id'].to_i @id = data['id'].to_i # Create roles @roles = [] roles_by_id = {} data['roles'].each do |element| role = Role.new(element, bot) @roles << role roles_by_id[role.id] = role end @members = [] members_by_id = {} data['members'].each do |element| user = User.new(element['user'], bot, self) @members << user members_by_id[user.id] = user user_roles = [] element['roles'].each do |element| role_id = element.to_i user_roles << roles_by_id[role_id] end user.update_roles(user_roles) end # Update user statuses with presence info if data['presences'] data['presences'].each do |element| if element['user'] user_id = element['user']['id'].to_i user = members_by_id[user_id] if user user.status = element['status'].to_sym user.game_id = element['game_id'] end end end end @channels = [] channels_by_id = {} if data['channels'] data['channels'].each do |element| channel = Channel.new(element, bot, self) @channels << channel channels_by_id[channel.id] = channel end end if data['voice_states'] data['voice_states'].each do |element| user_id = element['user_id'].to_i user = members_by_id[user_id] if user user.server_mute = element['mute'] user.server_deaf = element['deaf'] user.self_mute = element['self_mute'] user.self_mute = element['self_mute'] channel_id = element['channel_id'] channel = nil if channel_id channel = channels_by_id[channel_id] end user.move(channel) end end end end |
Instance Attribute Details
#channels ⇒ Object (readonly)
Array of channels on the server
284 285 286 |
# File 'lib/discordrb/data.rb', line 284 def channels @channels end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
281 282 283 |
# File 'lib/discordrb/data.rb', line 281 def id @id end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
281 282 283 |
# File 'lib/discordrb/data.rb', line 281 def members @members end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
281 282 283 |
# File 'lib/discordrb/data.rb', line 281 def name @name end |
#owner_id ⇒ Object (readonly)
Returns the value of attribute owner_id.
281 282 283 |
# File 'lib/discordrb/data.rb', line 281 def owner_id @owner_id end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
281 282 283 |
# File 'lib/discordrb/data.rb', line 281 def region @region end |
#roles ⇒ Object (readonly)
Array of roles on the server
287 288 289 |
# File 'lib/discordrb/data.rb', line 287 def roles @roles end |
Instance Method Details
#add_role(role) ⇒ Object
365 366 367 |
# File 'lib/discordrb/data.rb', line 365 def add_role(role) @roles << role end |
#delete_role(role_id) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/discordrb/data.rb', line 369 def delete_role(role_id) @roles.reject! {|r| r.id == role_id} @members.each do |user| new_roles = user.roles.reject {|r| r.id == role_id} user.update_roles(new_roles) end @channels.each do |channel| overwrites = channel..reject {|id, perm| id == role_id} channel.update_overwrites(overwrites) end end |