-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update gemfile and add topgg stat uploader
This commit updates the gemfile to add support for rest-client as well as a simple script for uploading bot stats to top.gg
- Loading branch information
1 parent
951659f
commit 7993bf7
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/ruby | ||
# frozen_string_literal: true | ||
|
||
# script for top.gg stat uploads for Dice Maiden | ||
|
||
require 'dotenv' | ||
require 'json' | ||
require 'rest-client' | ||
require 'sqlite3' | ||
|
||
cwd = File.expand_path(File.join(File.dirname(__FILE__), %w[../])) | ||
|
||
Dotenv.load("#{cwd}/.env") | ||
|
||
total_shards = ENV['SHARD'].to_i | ||
|
||
db = SQLite3::Database.new "#{cwd}/main.db" | ||
db.busy_timeout = (10_000) | ||
|
||
servers = db.execute 'select sum(server_count) from shard_stats;' | ||
|
||
RestClient.post('https://top.gg/api/bots/377701707943116800/stats', { "shard_count": total_shards, "server_count": servers.join.to_i }.to_json, { Authorization: ENV['API'], content_type: :json }) do |response, _request, _result, &block| | ||
case response.code | ||
when 200 | ||
puts 'Bot stats update successful!' | ||
response | ||
else | ||
puts 'Bot stat update failed!' | ||
response.return!(&block) | ||
end | ||
end |