Class: Discordrb::Server
- Inherits:
-
Object
- Object
- Discordrb::Server
- Includes:
- IDObject, ServerAttributes
- Defined in:
- lib/discordrb/data.rb
Overview
A server on Discord
Instance Attribute Summary collapse
-
#afk_channel ⇒ Channel?
The AFK voice channel of this server, or nil if none is set.
-
#afk_timeout ⇒ Integer
The amount of time after which a voice user gets moved into the AFK channel, in seconds.
-
#channels ⇒ Array<Channel>
readonly
An array of all the channels (text and voice) on this server.
-
#emoji ⇒ Hash<Integer, Emoji>
(also: #emojis)
readonly
A hash of all the emoji available on this server.
-
#features ⇒ Array<Symbol>
readonly
The features of the server (eg. "INVITE_SPLASH").
-
#large ⇒ true, false
(also: #large?)
readonly
it means the members list may be inaccurate for a couple seconds after starting up the bot.
-
#member_count ⇒ Integer
readonly
The absolute number of members on this server, offline or not.
-
#owner ⇒ Member
The server owner.
-
#region ⇒ String
The region the server is on (e. g.
amsterdam). -
#roles ⇒ Array<Role>
readonly
An array of all the roles created on this server.
-
#verification_level ⇒ Symbol
readonly
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').
-
#voice_states ⇒ Hash<Integer => VoiceState>
readonly
The hash (user ID => voice state) of voice states of members on this server.
Attributes included from ServerAttributes
Attributes included from IDObject
Instance Method Summary collapse
-
#any_emoji? ⇒ true, false
(also: #has_emoji?, #emoji?)
Whether this server has any emoji or not.
-
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
-
#bans ⇒ Array<User>
A list of banned users on this server.
-
#create_channel(name, type = 0) ⇒ Channel
Creates a channel on this server with the given name.
-
#create_role ⇒ Role
Creates a role on this server which can then be modified.
-
#default_channel ⇒ Channel
(also: #general_channel)
The default channel on this server (usually called #general).
-
#delete ⇒ Object
Deletes this server.
-
#embed? ⇒ true, false
Whether or not the server has widget enabled.
-
#icon=(icon) ⇒ Object
Sets the server's icon.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#integrations ⇒ Array<Integration>
An array of all the integrations connected to this server.
-
#kick(user) ⇒ Object
Kicks a user from this server.
-
#leave ⇒ Object
Leave the server.
-
#member(id, request = true) ⇒ Object
Gets a member on this server based on user ID.
-
#members ⇒ Array<Member>
(also: #users)
An array of all the members on this server.
-
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel.
-
#name=(name) ⇒ Object
Sets the server's name.
-
#online_members(include_idle: false, include_bots: true) ⇒ Array<Member>
(also: #online_users)
An array of online members on this server.
-
#role(id) ⇒ Object
Gets a role on this server based on its ID.
-
#splash_id ⇒ String
The hexadecimal ID used to identify this server's splash image for their VIP invite page.
-
#splash_url ⇒ String?
The splash image URL for the server's VIP invite page.
-
#text_channels ⇒ Array<Channel>
An array of text channels on this server.
-
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
-
#voice_channels ⇒ Array<Channel>
An array of voice channels on this server.
-
#widget_banner_url(style) ⇒ String?
The widget banner URL to the server that displays the amount of online members, server icon and server name in a stylish way.
-
#widget_url ⇒ String?
The widget URL to the server that displays the amount of online members in a stylish way.
Methods included from ServerAttributes
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#afk_channel ⇒ Channel?
Returns the AFK voice channel of this server, or nil if none is set.
2237 2238 2239 |
# File 'lib/discordrb/data.rb', line 2237 def afk_channel @afk_channel end |
#afk_timeout ⇒ Integer
Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.
2234 2235 2236 |
# File 'lib/discordrb/data.rb', line 2234 def afk_timeout @afk_timeout end |
#channels ⇒ Array<Channel> (readonly)
Returns an array of all the channels (text and voice) on this server.
2210 2211 2212 |
# File 'lib/discordrb/data.rb', line 2210 def channels @channels end |
#emoji ⇒ Hash<Integer, Emoji> (readonly) Also known as: emojis
Returns a hash of all the emoji available on this server.
2216 2217 2218 |
# File 'lib/discordrb/data.rb', line 2216 def emoji @emoji end |
#features ⇒ Array<Symbol> (readonly)
Returns the features of the server (eg. "INVITE_SPLASH").
2225 2226 2227 |
# File 'lib/discordrb/data.rb', line 2225 def features @features end |
#large ⇒ true, false (readonly) Also known as: large?
it means the members list may be inaccurate for a couple seconds after starting up the bot.
2221 2222 2223 |
# File 'lib/discordrb/data.rb', line 2221 def large @large end |
#member_count ⇒ Integer (readonly)
Returns the absolute number of members on this server, offline or not.
2228 2229 2230 |
# File 'lib/discordrb/data.rb', line 2228 def member_count @member_count end |
#owner ⇒ Member
Returns The server owner.
2207 2208 2209 |
# File 'lib/discordrb/data.rb', line 2207 def owner @owner end |
#region ⇒ String
Returns the region the server is on (e. g. amsterdam).
2204 2205 2206 |
# File 'lib/discordrb/data.rb', line 2204 def region @region end |
#roles ⇒ Array<Role> (readonly)
Returns an array of all the roles created on this server.
2213 2214 2215 |
# File 'lib/discordrb/data.rb', line 2213 def roles @roles end |
#verification_level ⇒ Symbol (readonly)
Returns 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').
2231 2232 2233 |
# File 'lib/discordrb/data.rb', line 2231 def verification_level @verification_level end |
#voice_states ⇒ Hash<Integer => VoiceState> (readonly)
Returns the hash (user ID => voice state) of voice states of members on this server.
2240 2241 2242 |
# File 'lib/discordrb/data.rb', line 2240 def voice_states @voice_states end |
Instance Method Details
#any_emoji? ⇒ true, false Also known as: has_emoji?, emoji?
Returns whether this server has any emoji or not.
2575 2576 2577 |
# File 'lib/discordrb/data.rb', line 2575 def any_emoji? @emoji.any? end |
#ban(user, message_days = 0) ⇒ Object
Bans a user from this server.
2499 2500 2501 |
# File 'lib/discordrb/data.rb', line 2499 def ban(user, = 0) API::Server.ban_user(@bot.token, @id, user.resolve_id, ) end |
#bans ⇒ Array<User>
Returns a list of banned users on this server.
2491 2492 2493 2494 |
# File 'lib/discordrb/data.rb', line 2491 def bans users = JSON.parse(API::Server.bans(@bot.token, @id)) users.map { |e| User.new(e['user'], @bot) } end |
#create_channel(name, type = 0) ⇒ Channel
Creates a channel on this server with the given name.
2473 2474 2475 2476 2477 |
# File 'lib/discordrb/data.rb', line 2473 def create_channel(name, type = 0) raise ArgumentError, 'Channel type must be either 0 (text) or 2 (voice)!' unless [0, 2].include?(type) response = API::Server.create_channel(@bot.token, @id, name, type) Channel.new(JSON.parse(response), @bot) end |
#create_role ⇒ Role
Creates a role on this server which can then be modified. It will be initialized (on Discord's side) with the regular role defaults the client uses, i. e. name is "new role", permissions are the default, colour is the default etc.
2483 2484 2485 2486 2487 2488 |
# File 'lib/discordrb/data.rb', line 2483 def create_role response = API::Server.create_role(@bot.token, @id) role = Role.new(JSON.parse(response), @bot, self) @roles << role role end |
#default_channel ⇒ Channel Also known as: general_channel
Returns The default channel on this server (usually called #general).
2275 2276 2277 |
# File 'lib/discordrb/data.rb', line 2275 def default_channel @bot.channel(@id) end |
#delete ⇒ Object
Deletes this server. Be aware that this is permanent and impossible to undo, so be careful!
2523 2524 2525 |
# File 'lib/discordrb/data.rb', line 2523 def delete API::Server.delete(@bot.token, @id) end |
#embed? ⇒ true, false
Returns whether or not the server has widget enabled.
2328 2329 2330 2331 |
# File 'lib/discordrb/data.rb', line 2328 def if .nil? end |
#icon=(icon) ⇒ Object
Sets the server's icon.
2552 2553 2554 2555 2556 2557 2558 2559 2560 |
# File 'lib/discordrb/data.rb', line 2552 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: icon_string) else update_server_data(icon: icon) end end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
2644 2645 2646 |
# File 'lib/discordrb/data.rb', line 2644 def inspect "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} afk_timeout=#{@afk_timeout}>" end |
#integrations ⇒ Array<Integration>
Returns an array of all the integrations connected to this server.
2315 2316 2317 2318 |
# File 'lib/discordrb/data.rb', line 2315 def integrations integration = JSON.parse(API::Server.integrations(@bot.token, @id)) integration.map { |element| Integration.new(element, @bot, self) } end |
#kick(user) ⇒ Object
Kicks a user from this server.
2511 2512 2513 |
# File 'lib/discordrb/data.rb', line 2511 def kick(user) API::Server.remove_member(@bot.token, @id, user.resolve_id) end |
#leave ⇒ Object
Leave the server
2528 2529 2530 |
# File 'lib/discordrb/data.rb', line 2528 def leave API::User.leave_server(@bot.token, @id) end |
#member(id, request = true) ⇒ Object
Gets a member on this server based on user ID
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 |
# File 'lib/discordrb/data.rb', line 2291 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 rescue nil end |
#members ⇒ Array<Member> Also known as: users
Returns an array of all the members on this server.
2303 2304 2305 2306 2307 2308 2309 2310 |
# File 'lib/discordrb/data.rb', line 2303 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 |
#move(user, channel) ⇒ Object
Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed.
2518 2519 2520 |
# File 'lib/discordrb/data.rb', line 2518 def move(user, channel) API::Server.update_member(@bot.token, @id, user.id, channel_id: channel.id) end |
#name=(name) ⇒ Object
Sets the server's name.
2540 2541 2542 |
# File 'lib/discordrb/data.rb', line 2540 def name=(name) update_server_data(name: name) end |
#online_members(include_idle: false, include_bots: true) ⇒ Array<Member> Also known as: online_users
Returns an array of online members on this server.
2336 2337 2338 2339 2340 |
# File 'lib/discordrb/data.rb', line 2336 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 |
#role(id) ⇒ Object
Gets a role on this server based on its ID.
2283 2284 2285 2286 |
# File 'lib/discordrb/data.rb', line 2283 def role(id) id = id.resolve_id @roles.find { |e| e.id == id } end |
#splash_id ⇒ String
Returns the hexadecimal ID used to identify this server's splash image for their VIP invite page.
2377 2378 2379 |
# File 'lib/discordrb/data.rb', line 2377 def splash_id @splash_id ||= JSON.parse(API::Server.resolve(@bot.token, @id))['splash'] end |
#splash_url ⇒ String?
Returns the splash image URL for the server's VIP invite page.
nil if there is no splash image.
2383 2384 2385 2386 2387 |
# File 'lib/discordrb/data.rb', line 2383 def splash_url splash_id if @splash_id.nil? return nil unless @splash_id API.splash_url(@id, @splash_id) end |
#text_channels ⇒ Array<Channel>
Returns an array of text channels on this server.
2345 2346 2347 |
# File 'lib/discordrb/data.rb', line 2345 def text_channels @channels.select(&:text?) end |
#unban(user) ⇒ Object
Unbans a previously banned user from this server.
2505 2506 2507 |
# File 'lib/discordrb/data.rb', line 2505 def unban(user) API::Server.unban_user(@bot.token, @id, user.resolve_id) end |
#voice_channels ⇒ Array<Channel>
Returns an array of voice channels on this server.
2350 2351 2352 |
# File 'lib/discordrb/data.rb', line 2350 def voice_channels @channels.select(&:voice?) end |
#widget_banner_url(style) ⇒ String?
Returns the widget banner URL to the server that displays the amount of online members,
server icon and server name in a stylish way. nil if the widget is not enabled.
2370 2371 2372 2373 2374 |
# File 'lib/discordrb/data.rb', line 2370 def (style) return nil unless if .nil? API.(@id, style) end |
#widget_url ⇒ String?
Returns the widget URL to the server that displays the amount of online members in a
stylish way. nil if the widget is not enabled.
2356 2357 2358 2359 2360 |
# File 'lib/discordrb/data.rb', line 2356 def if .nil? return nil unless API.(@id) end |