Class: Topgg
- Inherits:
-
Object
- Object
- Topgg
- Defined in:
- lib/lib.rb
Overview
The class instantiates all the methods for api requests and posts.
Instance Method Summary collapse
-
#auto_post_stats(client) ⇒ Object
Auto-posts stats on to the top.gg website.
-
#get_bot(id) ⇒ Dbl::Bot
The method fetches bot statistics from top.gg.
-
#get_stats(id) ⇒ Dbl::Stats
Get Bot statistics.
-
#initialize(token, id) ⇒ Topgg
constructor
initializes the class attributes.
- #interval(seconds) ⇒ Object
-
#post_stats(server_count, shards: nil, shard_count: nil) ⇒ Object
Post Bot Statistics to the website.
-
#search_bot(params) ⇒ Dbl::BotSearch
The method searches bots from top.gg using a keyword query.
-
#self ⇒ get_bot
Mini-method to get statistics on self.
-
#user(id) ⇒ Dbl::User
Search for a user on top.gg with id.
-
#voted?(userid) ⇒ Boolean
Mini-method to query if the bot(self) was voted by the user.
-
#votes ⇒ Dbl::Votes
Get the Last 1000 votes of the bot(self).
Constructor Details
Instance Method Details
#auto_post_stats(client) ⇒ Object
Auto-posts stats on to the top.gg website
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/lib.rb', line 91 def auto_post_stats(client) semaphore = Mutex.new Thread.new do semaphore.synchronize do interval 1800 do server_len = client.servers.length post_stats(server_len) print("[TOPGG] : \033[31;1;4m Bot statistics has been successfully posted!\033[0m") end end end end |
#get_bot(id) ⇒ Dbl::Bot
The method fetches bot statistics from top.gg
25 26 27 28 29 |
# File 'lib/lib.rb', line 25 def get_bot(id) resp = @request.get("bots/#{id}") Dbl::Bot.new(resp) end |
#get_stats(id) ⇒ Dbl::Stats
Get Bot statistics.
52 53 54 55 56 |
# File 'lib/lib.rb', line 52 def get_stats(id) resp = @request.get("bots/#{id}/stats") Dbl::Stats.new(resp) end |
#interval(seconds) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/lib.rb', line 110 def interval(seconds) loop do yield sleep seconds end end |
#post_stats(server_count, shards: nil, shard_count: nil) ⇒ Object
Post Bot Statistics to the website
80 81 82 83 84 85 86 87 |
# File 'lib/lib.rb', line 80 def post_stats(server_count, shards: nil, shard_count: nil) json_post = { server_count: server_count, shards: shards, shard_count: shard_count }.to_json @request.post("bots/#{@id}/stats", json_post, { 'Content-Type' => 'application/json' }) end |
#search_bot(params) ⇒ Dbl::BotSearch
The method searches bots from top.gg using a keyword query. To know what the parameters are check it out here
35 36 37 38 |
# File 'lib/lib.rb', line 35 def search_bot(params) resp = @request.get('bots/search', params) Dbl::BotSearch.new(resp) end |
#self ⇒ get_bot
Mini-method to get statistics on self
106 107 108 |
# File 'lib/lib.rb', line 106 def self get_bot(@id) end |
#user(id) ⇒ Dbl::User
Search for a user on top.gg with id
43 44 45 46 47 |
# File 'lib/lib.rb', line 43 def user(id) resp = @request.get("users/#{id}") Dbl::User.new(resp) end |
#voted?(userid) ⇒ Boolean
Mini-method to query if the bot(self) was voted by the user.
61 62 63 64 65 66 |
# File 'lib/lib.rb', line 61 def voted?(userid) resp = @request.get("bots/#{@id}/check", { userId: userid }) ret = resp ret['voted'] == 1 end |
#votes ⇒ Dbl::Votes
Get the Last 1000 votes of the bot(self)
70 71 72 73 74 |
# File 'lib/lib.rb', line 70 def votes resp = @request.get("bots/#{@id}/votes") Dbl::Votes.new(resp) end |