Class: DBLRuby::Stats
- Inherits:
-
Object
- Object
- DBLRuby::Stats
- Defined in:
- lib/dblruby/stats.rb
Overview
Stats and stuff, ya know.
Instance Method Summary collapse
-
#initialize(apikey, id) ⇒ Stats
constructor
Initialize the stats Program does this automatically when running DBLRuby.new.
-
#servercount ⇒ Integer
(also: #servers)
Get the bot's server count, returns an int.
-
#updateservercount(count, shard_id = nil, shard_count = nil) ⇒ Object
(also: #servers=)
Update the bot's server count.
-
#verifyvote(id) ⇒ true, false
Check to see if a user really voted, via an ID.
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
#servercount ⇒ Integer Also known as: servers
Get the bot's server count, returns an int.
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.
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.
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 |