Class: DBLRuby::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/dblruby/bot.rb

Overview

Find information about bots.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, data: nil, api: nil) ⇒ Bot

Initialize the bot

Parameters:

  • id (Integer, String) (defaults to: nil)

    Integer/String ID of bot you're requesting.

Raises:


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dblruby/bot.rb', line 6

def initialize(id: nil, data: nil, api: nil)
  if id.nil?
    @data = data
  else
    url = "https://discordbots.org/api/bots/#{id}"
    @data = JSON.parse(RestClient.get(url, Authorization: api))
  end
rescue RestClient::NotFound
  raise DBLRuby::Errors::InvalidBot,
        'The API returned a 404 error! Is that bot listed?'
end

Instance Attribute Details

#dataObject (readonly) Also known as: to_s

Returns data in raw json form.

Returns:

  • data in raw json form.


19
20
21
# File 'lib/dblruby/bot.rb', line 19

def data
  @data
end

Instance Method Details

#avatarString

The avatar hash of the bot's avatar.

Returns:

  • (String)

    the bot's avatar.


91
92
93
# File 'lib/dblruby/bot.rb', line 91

def avatar
  @data['avatar']
end

#avatar_imgString

Get's the bot's avatar as an img, ready to be used in image linking.

Returns:

  • (String)

    the bot's avatar image url.


97
98
99
# File 'lib/dblruby/bot.rb', line 97

def avatar_img
  "https://cdn.discordapp.com/avatars/#{id}/#{avatar}.webp?size=1024"
end

#certified?true, false Also known as: certifiedbot, certified, certifiedbot?

The certified status of the bot.

Returns:

  • (true, false)

    the bot's certified status.


194
195
196
# File 'lib/dblruby/bot.rb', line 194

def certified?
  @data['certifiedBot']
end

#clientidInteger

Get the bot's Client ID.

Returns:

  • (Integer)

    the bot's client id.


79
80
81
# File 'lib/dblruby/bot.rb', line 79

def clientid
  @data['clientid'].to_i
end

#dateDate

The date when the bot was approved.

Returns:

  • (Date)

    the bot's approval date.


130
131
132
# File 'lib/dblruby/bot.rb', line 130

def date
  Date.parse(@data['date'])
end

#defavatarString

The cdn hash of the bot's avatar if the bot has none.

Returns:

  • (String)

    the bot's defAvatar.


85
86
87
# File 'lib/dblruby/bot.rb', line 85

def defavatar
  @data['defAvatar']
end

#discriminatorString Also known as: discrim, tag

The discriminator of the bot.

Returns:

  • (String)

    the bot's discriminator.


109
110
111
# File 'lib/dblruby/bot.rb', line 109

def discriminator
  @data['discriminator']
end

#distinctString

Returns the bot's distinct, which is the Username and Discriminator.

Returns:

  • (String)

    the bot's distinct.


124
125
126
# File 'lib/dblruby/bot.rb', line 124

def distinct
  "#{username}\##{tag}"
end

#donatebotguildidString Also known as: donatebotserverid

Get the bot's donate bot guild ID.

Returns:

  • (String)

    the bot's donate bot guild ID.


216
217
218
# File 'lib/dblruby/bot.rb', line 216

def donatebotguildid
  @data['donatebotguildid']
end

#errorString?

Return the error if there is one, nil otherwise.

Returns:

  • (String, nil)

    the error.


25
26
27
# File 'lib/dblruby/bot.rb', line 25

def error
  @data['error']
end

#error?true, false

Return true if there is an error, false otherwise.

Returns:

  • (true, false)

    if there is an error.


31
32
33
# File 'lib/dblruby/bot.rb', line 31

def error?
  !@data['error'].nil?
end

#githubString

The link to the github repo of the bot.

Returns:

  • (String)

    the bot's GitHub Repo link.


43
44
45
# File 'lib/dblruby/bot.rb', line 43

def github
  @data['github']
end

#guildsArray<String> Also known as: servers

Get the bot's “This Bot Powers the following Servers”

Returns:

  • (Array<String>)

    the bot's guilds.


164
165
166
# File 'lib/dblruby/bot.rb', line 164

def guilds
  @data['guilds']
end

#idInteger

The id of the bot.

Returns:

  • (Integer)

    the bot's id.


103
104
105
# File 'lib/dblruby/bot.rb', line 103

def id
  @data['id'].to_i
end

#inviteString

The custom bot invite url of the bot.

Returns:

  • (String)

    the bot's invite link.


37
38
39
# File 'lib/dblruby/bot.rb', line 37

def invite
  @data['invite']
end

#libString

The library of the bot.

Returns:

  • (String)

    the bot's library.


73
74
75
# File 'lib/dblruby/bot.rb', line 73

def lib
  @data['lib']
end

#longdescString

The long description of the bot. Can contain HTML and/or Markdown.

Returns:

  • (String)

    the bot's Long Description.


55
56
57
# File 'lib/dblruby/bot.rb', line 55

def longdesc
  @data['longdesc']
end

#monthlypointsInteger Also known as: monthlyvotes

The amount of upvotes the bot has this month.

Returns:

  • (Integer)

    the bot's monthly points/votes.


178
179
180
# File 'lib/dblruby/bot.rb', line 178

def monthlypoints
  @data['monthlyPoints'].to_i
end

#ownersArray<String>

The owners of the bot. First one in the array is the main owner.

Returns:

  • (Array<String>)

    the bot's owners in an array.


204
205
206
# File 'lib/dblruby/bot.rb', line 204

def owners
  @data['owners']
end

#pointsInteger Also known as: votes

The amount of upvotes the bot has.

Returns:

  • (Integer)

    the bot's total points/votes.


186
187
188
# File 'lib/dblruby/bot.rb', line 186

def points
  @data['points'].to_i
end

#prefixString

The prefix of the bot.

Returns:

  • (String)

    the bot's prefix.


67
68
69
# File 'lib/dblruby/bot.rb', line 67

def prefix
  @data['prefix']
end

#server_countInteger Also known as: guild_count, server

Get the bot's server count

Returns:

  • (Integer)

    the bot's server count.


155
156
157
# File 'lib/dblruby/bot.rb', line 155

def server_count
  @data['server_count'].to_i
end

#shardsArray<String>

Get the bot's shards.

Returns:

  • (Array<String>)

    the bot's shards.


172
173
174
# File 'lib/dblruby/bot.rb', line 172

def shards
  @data['shards']
end

#shortdescString

The short description of the bot.

Returns:

  • (String)

    the bot's Short Description.


61
62
63
# File 'lib/dblruby/bot.rb', line 61

def shortdesc
  @data['shortdesc']
end

#supportString

The support server invite code of the bot.

Returns:

  • (String)

    the bot's support server code.


143
144
145
# File 'lib/dblruby/bot.rb', line 143

def support
  @data['support']
end

The bot's support server link, ready for clicking.

Returns:

  • (String)

    the bot's support server link.


149
150
151
# File 'lib/dblruby/bot.rb', line 149

def support_link
  "https://discord.gg/#{support}"
end

#tagsArray<String>

The tags of the bot.

Returns:

  • (Array<String>)

    the bot's tags in an array.


210
211
212
# File 'lib/dblruby/bot.rb', line 210

def tags
  @data['tags']
end

#timeTime

The time when the bot was approved. This is compatiable with embed.timestamp, unlike #date

Returns:

  • (Time)

    the bot's approval time.


137
138
139
# File 'lib/dblruby/bot.rb', line 137

def time
  Time.parse(@data['date'])
end

#usernameString

The username of the bot.

Returns:

  • (String)

    the bot's username.


118
119
120
# File 'lib/dblruby/bot.rb', line 118

def username
  @data['username']
end

#websiteString

The website url of the bot.

Returns:

  • (String)

    the bot's website link.


49
50
51
# File 'lib/dblruby/bot.rb', line 49

def website
  @data['website']
end