|
1 | | -# [Top.gg](https://top.gg) Ruby |
| 1 | +# Top.gg Ruby SDK |
2 | 2 |
|
3 | | -The Top.gg Ruby SDK is a lighweight package, that allows you |
4 | | -to fetch data from the top.gg api and post data such as statistics to the website. |
| 3 | +The community-maintained Ruby library for Top.gg. |
5 | 4 |
|
6 | | -It provides you with numerous methods to interact with the API. |
| 5 | +## Installation |
7 | 6 |
|
8 | | -## Dependencies |
| 7 | +```sh |
| 8 | +$ gem install topgg |
| 9 | +``` |
9 | 10 |
|
10 | | -- Ruby |
| 11 | +## Setting up |
11 | 12 |
|
12 | | -## Installation |
| 13 | +```rb |
| 14 | +require "topgg" |
13 | 15 |
|
14 | | -```bash |
| 16 | +client = Topgg.new(ENV["TOPGG_TOKEN"]) |
| 17 | +``` |
15 | 18 |
|
16 | | -gem install topgg |
| 19 | +## Usage |
17 | 20 |
|
| 21 | +### Getting a bot |
| 22 | + |
| 23 | +```rb |
| 24 | +bot = client.get_bot("264811613708746752") |
18 | 25 | ``` |
19 | 26 |
|
20 | | -## Note |
| 27 | +### Getting several bots |
21 | 28 |
|
22 | | -You require a Token to interact with the Api. |
23 | | -The token can be found at `https://top.gg/bot/[YOUR_BOT_ID]/webhooks` |
| 29 | +```rb |
| 30 | +bots = client.get_bots({ sort: "date", limit: 50, offset: 0 }) |
24 | 31 |
|
25 | | -## Example |
| 32 | +for bot in bots.results do |
| 33 | + puts bot.username |
| 34 | +``` |
26 | 35 |
|
27 | | -Here's a straightforward example of how to request data with the wrapper. |
| 36 | +### Getting your bot's voters |
28 | 37 |
|
29 | | -```ruby |
30 | | -require "topgg" |
| 38 | +#### First page |
31 | 39 |
|
32 | | -client = Topgg.new("AUTH_TOKEN", "BOTID") |
| 40 | +```rb |
| 41 | +voters = client.get_votes |
33 | 42 |
|
34 | | -client.get_bot("1234").avatar |
35 | | -# returns |
36 | | -# "https://cdn.discordapp.com/avatars/661200758510977084/4354318859c319c7ca39753260fdd350.png?size=4096" |
| 43 | +for voter in voters.results do |
| 44 | + puts voter.username |
37 | 45 | ``` |
38 | 46 |
|
39 | | -### Auto Posting |
| 47 | +#### Subsequent pages |
40 | 48 |
|
41 | | -The library provides you with autoposting functionality, and autoposts at an interval of 15 minutes. |
42 | | -Here's how you can use it |
| 49 | +```rb |
| 50 | +voters = client.get_votes(2) |
43 | 51 |
|
44 | | -```ruby |
45 | | -require "topgg" |
| 52 | +for voter in voters.results do |
| 53 | + puts voter.username |
| 54 | +``` |
| 55 | + |
| 56 | +### Check if a user has voted for your bot |
| 57 | + |
| 58 | +```rb |
| 59 | +has_voted = client.voted?("661200758510977084") |
| 60 | +``` |
| 61 | + |
| 62 | +### Getting your bot's server count |
| 63 | + |
| 64 | +```rb |
| 65 | +stats = client.get_stats |
| 66 | +server_count = client.server_count |
| 67 | +``` |
| 68 | + |
| 69 | +### Posting your bot's server count |
| 70 | + |
| 71 | +```rb |
| 72 | +client.post_stats(bot.server_count) |
| 73 | +``` |
| 74 | + |
| 75 | +### Automatically posting your bot's server count every few minutes |
| 76 | + |
| 77 | +For Discordrb: |
| 78 | + |
| 79 | +```rb |
46 | 80 | require "discordrb" |
47 | 81 |
|
48 | | -bot = Discordrb::Bot.new token: "TOKEN" |
| 82 | +bot = Discordrb::Bot.new(token: env["BOT_TOKEN"], intents: [:servers]) |
49 | 83 |
|
50 | | -client = Topgg.new("AUTH_TOKEN", "BOTID") |
51 | 84 | bot.ready do |event| |
52 | | - client.auto_post_stats(bot) # The discordrb bot client. |
| 85 | + client.auto_post_stats(bot) |
| 86 | + |
| 87 | + puts "Bot is now ready!" |
53 | 88 | end |
| 89 | + |
54 | 90 | bot.run |
55 | 91 | ``` |
56 | 92 |
|
57 | | -# Documentation |
| 93 | +### Checking if the weekend vote multiplier is active |
| 94 | + |
| 95 | +```rb |
| 96 | +is_weekend = client.is_weekend? |
| 97 | +``` |
| 98 | + |
| 99 | +### Generating widget URLs |
| 100 | + |
| 101 | +#### Large |
| 102 | + |
| 103 | +```rb |
| 104 | +widget_url = Dbl::Widget.large(:discord_bot, "574652751745777665") |
| 105 | +``` |
| 106 | + |
| 107 | +#### Votes |
| 108 | + |
| 109 | +```rb |
| 110 | +widget_url = Dbl::Widget.votes(:discord_bot, "574652751745777665") |
| 111 | +``` |
| 112 | + |
| 113 | +#### Owner |
| 114 | + |
| 115 | +```rb |
| 116 | +widget_url = Dbl::Widget.owner(:discord_bot, "574652751745777665") |
| 117 | +``` |
| 118 | + |
| 119 | +#### Social |
58 | 120 |
|
59 | | -Check out the api reference [here](https://rubydoc.info/gems/topgg/) |
| 121 | +```rb |
| 122 | +widget_url = Dbl::Widget.social(:discord_bot, "574652751745777665") |
| 123 | +``` |
0 commit comments