class Discordrb::Server
A server on Discord
Constants
- FILTER_LEVELS
A map of possible content filter levels to symbol names
- NOTIFICATION_LEVELS
A map of possible message notification levels to symbol names
- VERIFICATION_LEVELS
A map of possible server verification levels to symbol names
Attributes
@return [Integer] the amount of time after which a voice user gets moved into the AFK channel, in seconds.
@return [Array<Channel>] an array of all the channels (text and voice) on this server.
@return [Hash<Integer => Emoji>] a hash of all the emoji available on this server.
@return [Hash<Integer => Emoji>] a hash of all the emoji available on this server.
@return [Array<Symbol>] the features of the server (eg. “INVITE_SPLASH”)
@return [true, false] whether or not this server is large (members > 100). If it is, it means the members list may be inaccurate for a couple seconds after starting up the bot.
@return [true, false] whether or not this server is large (members > 100). If it is, it means the members list may be inaccurate for a couple seconds after starting up the bot.
@return [Integer] the absolute number of members on this server, offline or not.
@return [Member] The server owner.
@return [String] the ID of the region the server is on (e.g. `amsterdam`).
@return [Array<Role>] an array of all the roles created on this server.
@return [Hash<Integer => VoiceState>] the hash (user ID => voice state) of voice states of members on this server
Public Class Methods
@!visibility private
# File lib/discordrb/data.rb, line 2903 def initialize(data, bot, exists = true) @bot = bot @owner_id = data['owner_id'].to_i @id = data['id'].to_i process_channels(data['channels']) update_data(data) @large = data['large'] @member_count = data['member_count'] @splash_id = nil @features = data['features'].map { |element| element.downcase.to_sym } @members = {} @voice_states = {} @emoji = {} process_roles(data['roles']) process_emoji(data['emojis']) process_members(data['members']) process_presences(data['presences']) process_voice_states(data['voice_states']) # Whether this server's members have been chunked (resolved using op 8 and GUILD_MEMBERS_CHUNK) yet @chunked = false @processed_chunk_members = 0 # Only get the owner of the server actually exists (i.e. not for ServerDeleteEvent) @owner = member(@owner_id) if exists end
Public Instance Methods
Adds a channel to this server's cache @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3600 def add_channel(channel) @channels << channel @channels_by_id[channel.id] = channel end
Adds a member to the member cache. @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3229 def add_member(member) @member_count += 1 @members[member.id] = member end
Adds a member to this guild that has granted this bot's application an OAuth2 access token with the `guilds.join` scope. For more information about Discord's OAuth2 implementation, see: discordapp.com/developers/docs/topics/oauth2 @note Your bot must be present in this server, and have permission to create instant invites for this to work. @param user [Integer, User
, resolve_id
] the user, or ID of the user to add to this server @param access_token [String] the OAuth2 Bearer token that has been granted the `guilds.join` scope @param nick [String] the nickname to give this member upon joining @param roles [Role, Array<Integer, Role
, resolve_id
>] the role (or roles) to give this member upon joining @param deaf [true, false] whether this member will be server deafened upon joining @param mute [true, false] whether this member will be server muted upon joining @return [Member] the created member
# File lib/discordrb/data.rb, line 3103 def add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false) user_id = user.resolve_id roles = roles.is_a?(Array) ? roles.map(&:resolve_id) : [roles.resolve_id] response = JSON.parse(API::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute)) add_member Member.new(response, self, @bot) end
Adds a role to the role cache @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3196 def add_role(role) @roles << role end
@return [Channel, nil] the AFK voice channel of this server, or `nil` if none is set.
# File lib/discordrb/data.rb, line 3563 def afk_channel @bot.channel(@afk_channel_id) if @afk_channel_id end
Sets the server's AFK channel. @param afk_channel
[Channel, nil] The new AFK channel, or `nil` if there should be none set.
# File lib/discordrb/data.rb, line 3435 def afk_channel=(afk_channel) update_server_data(afk_channel_id: afk_channel.resolve_id) end
Sets the amount of time after which a user gets moved into the AFK channel. @param afk_timeout
[Integer] The AFK timeout, in seconds.
# File lib/discordrb/data.rb, line 3447 def afk_timeout=(afk_timeout) update_server_data(afk_timeout: afk_timeout) end
@return [true, false] whether this server has any emoji or not.
# File lib/discordrb/data.rb, line 3523 def any_emoji? @emoji.any? end
@param action [Symbol] The action to only include. @param user [User, resolve_id
] The user to filter entries to. @param limit [Integer] The amount of entries to limit it to. @param before [Entry, resolve_id
] The entry to use to not include all entries after it. @return [AuditLogs] The server's audit logs.
# File lib/discordrb/data.rb, line 2999 def audit_logs(action: nil, user: nil, limit: 50, before: nil) raise 'Invalid audit log action!' if action && AuditLogs::ACTIONS.key(action).nil? action = AuditLogs::ACTIONS.key(action) user = user.resolve_id if user before = before.resolve_id if before AuditLogs.new(self, @bot, JSON.parse(API::Server.audit_logs(@bot.token, @id, limit, user, action, before))) end
@return [Array<VoiceRegion>] collection of available voice regions to this guild
# File lib/discordrb/data.rb, line 3400 def available_voice_regions return @available_voice_regions if @available_voice_regions @available_voice_regions = {} data = JSON.parse API::Server.regions(@bot.token, @id) @available_voice_regions = data.map { |e| VoiceRegion.new e } end
Bans a user from this server. @param user [User, resolve_id
] The user to ban. @param message_days [Integer] How many days worth of messages sent by the user should be deleted. @param reason [String] The reason the user is being banned.
# File lib/discordrb/data.rb, line 3352 def ban(user, message_days = 0, reason: nil) API::Server.ban_user(@bot.token, @id, user.resolve_id, message_days, reason) end
@return [Array<ServerBan>] a list of banned users on this server and the reason they were banned.
# File lib/discordrb/data.rb, line 3341 def bans response = JSON.parse(API::Server.bans(@bot.token, @id)) response.map do |e| ServerBan.new(self, User.new(e['user'], @bot), e['reason']) end end
Prunes (kicks) an amount of members for inactivity @param days [Integer] the number of days to consider for inactivity (between 1 and 30) @param reason [String] The reason the for the prune. @return [Integer] the number of members removed at the end of the operation @raise [ArgumentError] if days is not between 1 and 30 (inclusive)
# File lib/discordrb/data.rb, line 3126 def begin_prune(days, reason = nil) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = JSON.parse API::Server.begin_prune(@bot.token, @id, days, reason) response['pruned'] end
Cache
@embed @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3011 def cache_embed_data data = JSON.parse(API::Server.embed(@bot.token, @id)) @embed_enabled = data['enabled'] @embed_channel_id = data['channel_id'] end
Adds a member to the cache @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3252 def cache_member(member) @members[member.id] = member end
@return [Array<Channel>] an array of category channels on this server
# File lib/discordrb/data.rb, line 3146 def categories @channels.select(&:category?) end
Creates a channel on this server with the given name. @note If parent is provided, permission overwrites have the follow behavior:
1. If overwrites is null, the new channel inherits the parent's permissions. 2. If overwrites is [], the new channel inherits the parent's permissions. 3. If you supply one or more overwrites, the channel will be created with those permissions and ignore the parents.
@param name [String] Name of the channel to create @param type [Integer, Symbol] Type of channel to create (0: text, 2: voice, 4: category) @param topic [String] the topic of this channel, if it will be a text channel @param bitrate [Integer] the bitrate of this channel, if it will be a voice channel @param user_limit [Integer] the user limit of this channel, if it will be a voice channel @param permission_overwrites [Array<Hash>, Array<Overwrite>] permission overwrites for this channel @param parent [Channel, resolve_id
] parent category for this channel to be created in. @param nsfw [true, false] whether this channel should be created as nsfw @param rate_limit_per_user [Integer] how many seconds users need to wait in between messages. @param reason [String] The reason the for the creation of this channel. @return [Channel] the created channel. @raise [ArgumentError] if type is not 0 (text), 2 (voice), or 4 (category)
# File lib/discordrb/data.rb, line 3302 def create_channel(name, type = 0, topic: nil, bitrate: nil, user_limit: nil, permission_overwrites: nil, parent: nil, nsfw: false, rate_limit_per_user: nil, reason: nil) type = Channel::TYPES[type] if type.is_a?(Symbol) raise ArgumentError, 'Channel type must be either 0 (text), 2 (voice), or 4 (category)!' unless [0, 2, 4].include?(type) permission_overwrites.map! { |e| e.is_a?(Overwrite) ? e.to_hash : e } if permission_overwrites.is_a?(Array) parent_id = parent.respond_to?(:resolve_id) ? parent.resolve_id : nil response = API::Server.create_channel(@bot.token, @id, name, type, topic, bitrate, user_limit, permission_overwrites, parent_id, nsfw, rate_limit_per_user, reason) Channel.new(JSON.parse(response), @bot) end
Creates a role on this server which can then be modified. It will be initialized with the regular role defaults the client uses unless specified, i.e. name is “new role”, permissions are the default, colour is the default etc. @param name [String] Name of the role to create @param colour [Integer, ColourRGB
, combined] The roles colour @param hoist [true, false] @param mentionable [true, false] @param permissions [Integer, Array<Symbol>, Permissions
, bits] The permissions to write to the new role. @param reason [String] The reason the for the creation of this role. @return [Role] the created role.
# File lib/discordrb/data.rb, line 3322 def create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, reason: nil) colour = colour.respond_to?(:combined) ? colour.combined : colour permissions = if permissions.is_a?(Array) Permissions.bits(permissions) elsif permissions.respond_to?(:bits) permissions.bits else permissions end response = API::Server.create_role(@bot.token, @id, name, colour, hoist, mentionable, permissions, reason) role = Role.new(JSON.parse(response), @bot, self) @roles << role role end
The default channel is the text channel on this server with the highest position that the bot has Read Messages permission on. @param send_messages [true, false] whether to additionally consider if the bot has Send Messages permission @return [Channel, nil] The default channel on this server, or `nil` if there are no channels that the bot can read.
# File lib/discordrb/data.rb, line 2937 def default_channel(send_messages = false) bot_member = member(@bot.profile) text_channels.sort_by { |e| [e.position, e.id] }.find do |e| if send_messages bot_member.can_read_messages?(e) && bot_member.can_send_messages?(e) else bot_member.can_read_messages?(e) end end end
@return [Symbol] the default message notifications settings of the server (:all = 'All messages', :mentions = 'Only @mentions').
# File lib/discordrb/data.rb, line 3480 def default_message_notifications NOTIFICATION_LEVELS.key @default_message_notifications end
Sets the default message notification level @param notification_level [Integer, Symbol] The default message notificiation 0-1 or Symbol (see {NOTIFICATION_LEVELS})
# File lib/discordrb/data.rb, line 3486 def default_message_notifications=(notification_level) notification_level = NOTIFICATION_LEVELS[notification_level] if notification_level.is_a?(Symbol) update_server_data(default_message_notifications: notification_level) end
Deletes this server. Be aware that this is permanent and impossible to undo, so be careful!
# File lib/discordrb/data.rb, line 3378 def delete API::Server.delete(@bot.token, @id) end
Deletes a channel from this server's cache @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3608 def delete_channel(id) @channels.reject! { |e| e.id == id } @channels_by_id.delete(id) end
Removes a member from the member cache. @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3237 def delete_member(user_id) @members.delete(user_id) @member_count -= 1 end
Removes a role from the role cache @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3203 def delete_role(role_id) @roles.reject! { |r| r.id == role_id } @members.each do |_, member| new_roles = member.roles.reject { |r| r.id == role_id } member.update_roles(new_roles) end @channels.each do |channel| overwrites = channel.permission_overwrites.reject { |id, _| id == role_id } channel.update_overwrites(overwrites) end end
@return [Channel, nil] the channel the server embed will make an invite for.
# File lib/discordrb/data.rb, line 3027 def embed_channel cache_embed_data if @embed_enabled.nil? @bot.channel(@embed_channel_id) if @embed_channel_id end
Changes the channel on the server's embed (widget) @param channel [Channel, String
, Integer
, resolve_id
] the channel to be referenced by the embed
# File lib/discordrb/data.rb, line 3052 def embed_channel=(channel) modify_embed(embed?, channel) end
Sets whether this server's embed (widget) is enabled @param value [true, false]
# File lib/discordrb/data.rb, line 3035 def embed_enabled=(value) modify_embed(value, embed_channel) end
@return [true, false] whether or not the server has widget enabled
# File lib/discordrb/data.rb, line 3018 def embed_enabled? cache_embed_data if @embed_enabled.nil? @embed_enabled end
@return [Role] The @everyone role on this server
# File lib/discordrb/data.rb, line 2951 def everyone_role role(@id) end
@return [Symbol] the explicit content filter level of the server (:none = 'Don't scan any messages.', :exclude_roles = 'Scan messages for members without a role.', :all = 'Scan messages sent by all members.').
# File lib/discordrb/data.rb, line 3508 def explicit_content_filter FILTER_LEVELS.key @explicit_content_filter end
Sets the server content filter. @param filter_level [Integer, Symbol] The content filter from 0-2 or Symbol (see {FILTER_LEVELS})
# File lib/discordrb/data.rb, line 3516 def explicit_content_filter=(filter_level) filter_level = FILTER_LEVELS[filter_level] if filter_level.is_a?(Symbol) update_server_data(explicit_content_filter: filter_level) end
Sets the server's icon. @param icon [String, read] The new icon, in base64-encoded JPG format.
# File lib/discordrb/data.rb, line 3423 def icon=(icon) if icon.respond_to? :read icon_string = 'data:image/jpg;base64,' icon_string += Base64.strict_encode64(icon.read) update_server_data(icon_id: icon_string) else update_server_data(icon_id: icon) end end
The inspect method is overwritten to give more useful output
# File lib/discordrb/data.rb, line 3622 def inspect "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} system_channel_id=#{@system_channel_id} afk_timeout=#{@afk_timeout}>" end
@return [Array<Integration>] an array of all the integrations connected to this server.
# File lib/discordrb/data.rb, line 2989 def integrations integration = JSON.parse(API::Server.integrations(@bot.token, @id)) integration.map { |element| Integration.new(element, @bot, self) } end
Requests a list of Invites to the server. @return [Array<Invite>] invites to the server.
# File lib/discordrb/data.rb, line 3539 def invites invites = JSON.parse(API::Server.invites(@bot.token, @id)) invites.map { |invite| Invite.new(invite, @bot) } end
Kicks a user from this server. @param user [User, resolve_id
] The user to kick. @param reason [String] The reason the user is being kicked.
# File lib/discordrb/data.rb, line 3366 def kick(user, reason = nil) API::Server.remove_member(@bot.token, @id, user.resolve_id, reason) end
Leave the server.
# File lib/discordrb/data.rb, line 3383 def leave API::User.leave_server(@bot.token, @id) end
Gets a member on this server based on user ID @param id [Integer] The user ID to look for @param request [true, false] Whether the member should be requested from Discord if it's not cached
# File lib/discordrb/data.rb, line 2965 def member(id, request = true) id = id.resolve_id return @members[id] if member_cached?(id) return nil unless request member = @bot.member(self, id) @members[id] = member unless member.nil? rescue StandardError nil end
Checks whether a member is cached @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3245 def member_cached?(user_id) @members.include?(user_id) end
@return [Array<Member>] an array of all the members on this server.
# File lib/discordrb/data.rb, line 2977 def members return @members.values if @chunked @bot.debug("Members for server #{@id} not chunked yet - initiating") @bot.request_chunks(@id) sleep 0.05 until @chunked @members.values end
Changes the channel on the server's embed (widget), and sets whether it is enabled. @param enabled [true, false] whether the embed (widget) is enabled @param channel [Channel, String
, Integer
, resolve_id
] the channel to be referenced by the embed @param reason [String, nil] the reason to be shown in the audit log for this action
# File lib/discordrb/data.rb, line 3071 def modify_embed(enabled, channel, reason = nil) cache_embed_data if @embed_enabled.nil? channel_id = channel ? channel.resolve_id : @embed_channel_id response = JSON.parse(API::Server.modify_embed(@bot.token, @id, enabled, channel_id, reason)) @embed_enabled = response['enabled'] @embed_channel_id = response['channel_id'] end
Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed. @param user [User, resolve_id
] The user to move. @param channel [Channel, resolve_id
] The voice channel to move into.
# File lib/discordrb/data.rb, line 3373 def move(user, channel) API::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel.resolve_id) end
Sets the server's name. @param name [String] The new server name.
# File lib/discordrb/data.rb, line 3395 def name=(name) update_server_data(name: name) end
@param include_idle [true, false] Whether to count idle members as online. @param include_bots [true, false] Whether to include bot accounts in the count. @return [Array<Member>] an array of online members on this server.
# File lib/discordrb/data.rb, line 3084 def online_members(include_idle: false, include_bots: true) @members.values.select do |e| ((include_idle ? e.idle? : false) || e.online?) && (include_bots ? true : !e.bot_account?) end end
@return [Array<Channel>] an array of channels on this server that are not in a category
# File lib/discordrb/data.rb, line 3151 def orphan_channels @channels.reject { |c| c.parent || c.category? } end
Transfers server ownership to another user. @param user [User, resolve_id
] The user who should become the new owner.
# File lib/discordrb/data.rb, line 3389 def owner=(user) API::Server.transfer_ownership(@bot.token, @id, user.resolve_id) end
Processes a GUILD_MEMBERS_CHUNK packet, specifically the members field @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3547 def process_chunk(members) process_members(members) @processed_chunk_members += members.length LOGGER.debug("Processed one chunk on server #{@id} - length #{members.length}") # Don't bother with the rest of the method if it's not truly the last packet return unless @processed_chunk_members == @member_count LOGGER.debug("Finished chunking server #{@id}") # Reset everything to normal @chunked = true @processed_chunk_members = 0 end
Returns the amount of members that are candidates for pruning @param days [Integer] the number of days to consider for inactivity @return [Integer] number of members to be removed @raise [ArgumentError] if days is not between 1 and 30 (inclusive)
# File lib/discordrb/data.rb, line 3114 def prune_count(days) raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30) response = JSON.parse API::Server.prune_count(@bot.token, @id, days) response['pruned'] end
@return [VoiceRegion, nil] voice region data for this server's region @note This may return `nil` if this server's voice region is deprecated.
# File lib/discordrb/data.rb, line 3411 def region available_voice_regions.find { |e| e.id == @region_id } end
Moves the server to another region. This will cause a voice interruption of at most a second. @param region [String] The new region the server should be in.
# File lib/discordrb/data.rb, line 3417 def region=(region) update_server_data(region: region.to_s) end
Gets a role on this server based on its ID. @param id [Integer, String
, resolve_id
] The role ID to look for.
# File lib/discordrb/data.rb, line 2957 def role(id) id = id.resolve_id @roles.find { |e| e.id == id } end
Changes the channel on the server's embed (widget) @param channel [Channel, String
, Integer
, resolve_id
] the channel to be referenced by the embed @param reason [String, nil] the reason to be shown in the audit log for this action
# File lib/discordrb/data.rb, line 3061 def set_embed_channel(channel, reason = nil) modify_embed(embed?, channel, reason) end
Sets whether this server's embed (widget) is enabled @param value [true, false] @param reason [String, nil] the reason to be shown in the audit log for this action
# File lib/discordrb/data.rb, line 3044 def set_embed_enabled(value, reason = nil) modify_embed(value, embed_channel, reason) end
Sets the server splash @param splash_hash [String] The splash hash
# File lib/discordrb/data.rb, line 3496 def splash=(splash_hash) update_server_data(splash: splash_hash) end
@return [String] the hexadecimal ID used to identify this server's splash image for their VIP invite page.
# File lib/discordrb/data.rb, line 3180 def splash_id @splash_id ||= JSON.parse(API::Server.resolve(@bot.token, @id))['splash'] end
@return [String, nil] the splash image URL for the server's VIP invite page.
`nil` if there is no splash image.
# File lib/discordrb/data.rb, line 3186 def splash_url splash_id if @splash_id.nil? return nil unless @splash_id API.splash_url(@id, @splash_id) end
@return [Channel, nil] the system channel (used for automatic welcome messages) of a server, or `nil` if none is set.
# File lib/discordrb/data.rb, line 3568 def system_channel @bot.channel(@system_channel_id) if @system_channel_id end
Sets the server's system channel. @param system_channel
[Channel, String
, Integer
, resolve_id
, nil] The new system channel, or `nil` should it be disabled.
# File lib/discordrb/data.rb, line 3441 def system_channel=(system_channel) update_server_data(system_channel_id: system_channel.resolve_id) end
@return [Array<Channel>] an array of text channels on this server
# File lib/discordrb/data.rb, line 3136 def text_channels @channels.select(&:text?) end
Unbans a previously banned user from this server. @param user [User, resolve_id
] The user to unban. @param reason [String] The reason the user is being unbanned.
# File lib/discordrb/data.rb, line 3359 def unban(user, reason = nil) API::Server.unban_user(@bot.token, @id, user.resolve_id, reason) end
Updates the cached data with new data @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3575 def update_data(new_data = nil) new_data ||= JSON.parse(API::Server.resolve(@bot.token, @id)) @name = new_data[:name] || new_data['name'] || @name @region_id = new_data[:region] || new_data['region'] || @region_id @icon_id = new_data[:icon] || new_data['icon'] || @icon_id @afk_timeout = new_data[:afk_timeout] || new_data['afk_timeout'] || @afk_timeout afk_channel_id = new_data[:afk_channel_id] || new_data['afk_channel_id'] || @afk_channel @afk_channel_id = afk_channel_id.nil? ? nil : afk_channel_id.resolve_id embed_channel_id = new_data[:embed_channel_id] || new_data['embed_channel_id'] || @embed_channel @embed_channel_id = embed_channel_id.nil? ? nil : embed_channel_id.resolve_id system_channel_id = new_data[:system_channel_id] || new_data['system_channel_id'] || @system_channel @system_channel_id = system_channel_id.nil? ? nil : system_channel_id.resolve_id @embed_enabled = new_data[:embed_enabled] || new_data['embed_enabled'] @splash = new_data[:splash_id] || new_data['splash_id'] || @splash_id @verification_level = new_data[:verification_level] || new_data['verification_level'] || @verification_level @explicit_content_filter = new_data[:explicit_content_filter] || new_data['explicit_content_filter'] || @explicit_content_filter @default_message_notifications = new_data[:default_message_notifications] || new_data['default_message_notifications'] || @default_message_notifications end
Updates the cached emoji data with new data @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3616 def update_emoji_data(new_data) @emoji = {} process_emoji(new_data['emojis']) end
Updates the positions of all roles on the server @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3218 def update_role_positions(role_positions) response = JSON.parse(API::Server.update_role_positions(@bot.token, @id, role_positions)) response.each do |data| updated_role = Role.new(data, @bot, self) role(updated_role.id).update_from(updated_role) end end
Updates a member's voice state @note For internal use only @!visibility private
# File lib/discordrb/data.rb, line 3259 def update_voice_state(data) user_id = data['user_id'].to_i if data['channel_id'] unless @voice_states[user_id] # Create a new voice state for the user @voice_states[user_id] = VoiceState.new(user_id) end # Update the existing voice state (or the one we just created) channel = @channels_by_id[data['channel_id'].to_i] @voice_states[user_id].update( channel, data['mute'], data['deaf'], data['self_mute'], data['self_deaf'] ) else # The user is not in a voice channel anymore, so delete its voice state @voice_states.delete(user_id) end end
@return [Symbol] the verification level of the server (:none = none, :low = 'Must have a verified email on their Discord account', :medium = 'Has to be registered with Discord for at least 5 minutes', :high = 'Has to be a member of this server for at least 10 minutes', :very_high = 'Must have a verified phone on their Discord account').
# File lib/discordrb/data.rb, line 3461 def verification_level VERIFICATION_LEVELS.key @verification_level end
Sets the verification level of the server @param level [Integer, Symbol] The verification level from 0-4 or Symbol (see {VERIFICATION_LEVELS})
# File lib/discordrb/data.rb, line 3467 def verification_level=(level) level = VERIFICATION_LEVELS[level] if level.is_a?(Symbol) update_server_data(verification_level: level) end
@return [Array<Channel>] an array of voice channels on this server
# File lib/discordrb/data.rb, line 3141 def voice_channels @channels.select(&:voice?) end
Requests a list of Webhooks
on the server. @return [Array<Webhook>] webhooks on the server.
# File lib/discordrb/data.rb, line 3532 def webhooks webhooks = JSON.parse(API::Server.webhooks(@bot.token, @id)) webhooks.map { |webhook| Webhook.new(webhook, @bot) } end
@return [String, nil] the widget URL to the server that displays the amount of online members in a
stylish way. `nil` if the widget is not enabled.
# File lib/discordrb/data.rb, line 3157 def widget_url update_data if @embed_enabled.nil? return unless @embed_enabled API.widget_url(@id) end
Private Instance Methods
# File lib/discordrb/data.rb, line 3692 def process_channels(channels) @channels = [] @channels_by_id = {} return unless channels channels.each do |element| channel = @bot.ensure_channel(element, self) @channels << channel @channels_by_id[channel.id] = channel end end
# File lib/discordrb/data.rb, line 3657 def process_emoji(emoji) return if emoji.empty? emoji.each do |element| new_emoji = Emoji.new(element, @bot, self) @emoji[new_emoji.id] = new_emoji end end
# File lib/discordrb/data.rb, line 3666 def process_members(members) return unless members members.each do |element| member = Member.new(element, self, @bot) @members[member.id] = member end end
# File lib/discordrb/data.rb, line 3675 def process_presences(presences) # Update user statuses with presence info return unless presences presences.each do |element| next unless element['user'] user_id = element['user']['id'].to_i user = @members[user_id] if user user.update_presence(element) else LOGGER.warn "Rogue presence update! #{element['user']['id']} on #{@id}" end end end
# File lib/discordrb/data.rb, line 3643 def process_roles(roles) # Create roles @roles = [] @roles_by_id = {} return unless roles roles.each do |element| role = Role.new(element, @bot, self) @roles << role @roles_by_id[role.id] = role end end
# File lib/discordrb/data.rb, line 3705 def process_voice_states(voice_states) return unless voice_states voice_states.each do |element| update_voice_state(element) end end
# File lib/discordrb/data.rb, line 3628 def update_server_data(new_data) response = JSON.parse(API::Server.update(@bot.token, @id, new_data[:name] || @name, new_data[:region] || @region_id, new_data[:icon_id] || @icon_id, new_data[:afk_channel_id] || @afk_channel_id, new_data[:afk_timeout] || @afk_timeout, new_data[:splash] || @splash, new_data[:default_message_notifications] || @default_message_notifications, new_data[:verification_level] || @verification_level, new_data[:explicit_content_filter] || @explicit_content_filter, new_data[:system_channel_id] || @system_channel_id)) update_data(response) end