Class: DBLRuby::Stats

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

Overview

Stats and stuff, ya know.

Instance Method Summary collapse

Constructor Details

#initialize(apikey, id) ⇒ Stats

Initialize the stats Program does this automatically when running DBLRuby.new.


5
6
7
8
# File 'lib/dblruby/stats.rb', line 5

def initialize(apikey, id)
  @api = apikey
  @id = id
end

Instance Method Details

#servercountInteger Also known as: servers

Get the bot's server count, returns an int.

Returns:

  • (Integer)

    amount of servers the bot is on.

Raises:


13
14
15
16
17
18
19
# File 'lib/dblruby/stats.rb', line 13

def servercount
  url = "https://discordbots.org/api/bots/#{@id}"
  JSON.parse(RestClient.get(url, Authorization: @api))['server_count'].to_i
rescue RestClient::NotFound
  raise DBLRuby::Errors::InvalidID,
        'DBL Returned a 404 unknown error! Did you enter the correct ID?'
end

#updateservercount(count, shard_id = nil, shard_count = nil) ⇒ Object Also known as: servers=

Update the bot's server count.

Parameters:

  • count (Integer)

    Integer/String of bot server count.

  • shard_id (Integer) (defaults to: nil)

    ID of the shard

  • shard_count (Integer) (defaults to: nil)

    amount of shards the bot has.

Returns:

  • The count of the servers.

Raises:


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dblruby/stats.rb', line 29

def updateservercount(count, shard_id = nil, shard_count = nil)
  url = "https://discordbots.org/api/bots/#{@id}/stats"
  json = {
    'server_count': count,
    'shard_id': shard_id,
    'shard_count': shard_count
  }
  RestClient.post(url, json, Authorization: @api, 'Content-Type': :json)
  count
rescue RestClient::Unauthorized
  raise DBLRuby::Errors::InvalidAPIKey,
        'There was an error posting stats to the DBL. Is your API key ok?'
end

#verifyvote(id) ⇒ true, false

Check to see if a user really voted, via an ID.

Parameters:

  • id (Integer, String)

    Integer/String ID of user you're requesting.

Returns:

  • (true, false)

    if the user voted or not.

Raises:


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dblruby/stats.rb', line 49

def verifyvote(id)
  r = RestClient.get('https://discordbots.org/api/bots/check',
                     params: { userId: id },
                     Authorization: @api,
                     'Content-Type': :json)
  o = JSON.parse(r)['voted'].to_i
  !o.zero?
rescue RestClient::Unauthorized
  raise DBLRuby::Errors::InvalidAPIKey,
        'There was an error posting stats to the DBL. Is your API key ok?'
end