Class: Discordrb::Light::LightBot
- Inherits:
-
Object
- Object
- Discordrb::Light::LightBot
- Defined in:
- lib/discordrb/light/light_bot.rb
Overview
A bot that only uses the REST part of the API. Hierarchically unrelated to the regular Bot. Useful to make applications integrated to Discord over OAuth, for example.
Instance Method Summary collapse
-
#connections ⇒ Array<Connection>
Gets the connections associated with this account.
-
#initialize(token) ⇒ LightBot
constructor
Create a new LightBot.
-
#join(code) ⇒ Object
Joins a server using an instant invite.
-
#profile ⇒ LightProfile
The details of the user this bot is connected to.
-
#servers ⇒ Array<LightServer>
The servers this bot is connected to.
Constructor Details
#initialize(token) ⇒ LightBot
Create a new LightBot. This does no networking yet, all networking is done by the methods on this class.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/discordrb/light/light_bot.rb', line 18 def initialize(token) if token.respond_to? :token # Parse AccessTokens from the OAuth2 gem token = token.token end unless token.include? '.' # Discord user/bot tokens always contain two dots, so if there's none we can assume it's an OAuth token. token = "Bearer #{token}" # OAuth tokens have to be prefixed with 'Bearer' for Discord to be able to use them end @token = token end |
Instance Method Details
#connections ⇒ Array<Connection>
Gets the connections associated with this account.
53 54 55 56 |
# File 'lib/discordrb/light/light_bot.rb', line 53 def connections response = Discordrb::API::User.connections(@token) JSON.parse(response).map { |e| Connection.new(e, self) } end |
#join(code) ⇒ Object
Joins a server using an instant invite.
47 48 49 |
# File 'lib/discordrb/light/light_bot.rb', line 47 def join(code) Discordrb::API::Invite.accept(@token, code) end |
#profile ⇒ LightProfile
Returns the details of the user this bot is connected to.
33 34 35 36 |
# File 'lib/discordrb/light/light_bot.rb', line 33 def profile response = Discordrb::API::User.profile(@token) LightProfile.new(JSON.parse(response), self) end |
#servers ⇒ Array<LightServer>
Returns the servers this bot is connected to.
39 40 41 42 |
# File 'lib/discordrb/light/light_bot.rb', line 39 def servers response = Discordrb::API::User.servers(@token) JSON.parse(response).map { |e| LightServer.new(e, self) } end |