Skip to content

Commit

Permalink
Update gemfile and add topgg stat uploader
Browse files Browse the repository at this point in the history
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
Humblemonk committed May 19, 2024
1 parent 951659f commit 7993bf7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ source 'https://rubygems.org'
gem 'dicebag', git: 'https://github.com/Humblemonk/Dice-Bag.git', branch: 'pre-3.3'
gem 'discordrb', github: 'shardlab/discordrb', branch: 'main'
gem 'dotenv', '~> 2.5'
gem 'rest-client', '~>2.1'
gem 'rubocop', require: false
gem 'sqlite3', '~> 2.0', '>= 2.0.1'
31 changes: 31 additions & 0 deletions tools/topgg.rb
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

0 comments on commit 7993bf7

Please sign in to comment.