Skip to content

Commit 6251a1b

Browse files
committed
[feat,docs]: adapt methods and documentation to v1
1 parent 642164e commit 6251a1b

11 files changed

Lines changed: 414 additions & 147 deletions

File tree

README.md

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ The community-maintained Python library for Top.gg.
99
- [Usage](#usage)
1010
- [Getting a bot](#getting-a-bot)
1111
- [Getting several bots](#getting-several-bots)
12-
- [Getting your bot's voters](#getting-your-bots-voters)
13-
- [Check if a user has voted for your bot](#check-if-a-user-has-voted-for-your-bot)
12+
- [Getting your project's voters](#getting-your-projects-voters)
13+
- [Getting your project's vote information of a user](#getting-your-projects-vote-information-of-a-user)
1414
- [Getting your bot's server count](#getting-your-bots-server-count)
1515
- [Posting your bot's server count](#posting-your-bots-server-count)
16+
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
1617
- [Automatically posting your bot's server count every few minutes](#automatically-posting-your-bots-server-count-every-few-minutes)
1718
- [Checking if the weekend vote multiplier is active](#checking-if-the-weekend-vote-multiplier-is-active)
1819
- [Generating widget URLs](#generating-widget-urls)
1920
- [Webhooks](#webhooks)
20-
- [Being notified whenever someone voted for your bot](#being-notified-whenever-someone-voted-for-your-bot)
21+
- [Being notified whenever someone voted for your project](#being-notified-whenever-someone-voted-for-your-project)
2122

2223
## Installation
2324

@@ -34,7 +35,6 @@ import topgg
3435

3536
import os
3637

37-
3838
async with topgg.Client(os.getenv('TOPGG_TOKEN')) as client:
3939
# ...
4040
```
@@ -46,7 +46,6 @@ import topgg
4646

4747
import os
4848

49-
5049
client = topgg.Client(os.getenv('TOPGG_TOKEN'))
5150

5251
# ...
@@ -82,7 +81,7 @@ for bot in bots:
8281
print(bot)
8382
```
8483

85-
### Getting your bot's voters
84+
### Getting your project's voters
8685

8786
#### First page
8887

@@ -102,44 +101,88 @@ for voter in voters:
102101
print(voter)
103102
```
104103

105-
### Check if a user has voted for your bot
104+
### Getting your project's vote information of a user
105+
106+
#### Discord ID
106107

107108
```py
108-
has_voted = await client.has_voted(661200758510977084)
109+
vote = await client.get_vote(661200758510977084)
110+
111+
if vote:
112+
print(f'User has voted: {vote!r}')
113+
```
114+
115+
#### Top.gg ID
116+
117+
```py
118+
vote = await client.get_vote(8226924471638491136, source=topgg.UserSource.TOPGG)
119+
120+
if vote:
121+
print(f'User has voted: {vote!r}')
109122
```
110123

111124
### Getting your bot's server count
112125

113126
```py
114-
posted_server_count = await client.get_server_count()
127+
posted_server_count = await client.get_bot_server_count()
115128
```
116129

117130
### Posting your bot's server count
118131

119132
```py
120-
await client.post_server_count(bot.server_count)
133+
await client.post_bot_server_count(bot.server_count)
134+
```
135+
136+
### Posting your bot's application commands list
137+
138+
#### Discord.py/Pycord/Nextcord/Disnake
139+
140+
```py
141+
app_id = bot.user.id
142+
commands = await bot.http.get_global_commands(app_id)
143+
144+
await client.post_bot_commands(commands)
145+
```
146+
147+
#### Hikari
148+
149+
```py
150+
app_id = ...
151+
commands = await bot.rest.request('GET', f'/applications/{app_id}/commands')
152+
153+
await client.post_bot_commands(commands)
154+
```
155+
156+
#### Discord.http
157+
158+
```py
159+
http = discordhttp.HTTP(f'BOT {os.getenv("BOT_TOKEN")}')
160+
app_id = ...
161+
commands = await http.get(f'/applications/{app_id}/commands')
162+
163+
await client.post_bot_commands(commands)
121164
```
122165

123166
### Automatically posting your bot's server count every few minutes
124167

125168
```py
126-
@client.autopost_retrieval
169+
@client.bot_autopost_retrieval
127170
def get_server_count() -> int:
128171
return bot.server_count
129172

130-
@client.autopost_success
173+
@client.bot_autopost_success
131174
def success(server_count: int) -> None:
132175
print(f'Successfully posted {server_count} servers to Top.gg!')
133176

134-
@client.autopost_error
177+
@client.bot_autopost_error
135178
def error(error: topgg.Error) -> None:
136179
print(f'Error: {error!r}')
137180

138-
client.start_autoposter()
181+
client.start_bot_autoposter()
139182

140183
# ...
141184

142-
client.stop_autoposter() # Optional
185+
client.stop_bot_autoposter() # Optional
143186
```
144187

145188
### Checking if the weekend vote multiplier is active
@@ -176,19 +219,18 @@ widget_url = topgg.widget.social(topgg.WidgetType.DISCORD_BOT, 57465275174577766
176219

177220
### Webhooks
178221

179-
#### Being notified whenever someone voted for your bot
222+
#### Being notified whenever someone voted for your project
180223

181224
```py
182225
import topgg
183226

184227
import asyncio
185228
import os
186229

187-
188230
webhooks = topgg.Webhooks(os.getenv('MY_TOPGG_WEBHOOK_SECRET'), 8080)
189231

190232
@webhooks.on_vote('/votes')
191-
def voted(vote: topgg.Vote) -> None:
233+
def voted(vote: topgg.VoteEvent) -> None:
192234
print(f'A user with the ID of {vote.voter_id} has voted us on Top.gg!')
193235

194236
async def main() -> None:

docs/client.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Client reference
44
.. autoclass:: topgg.client.Client
55
:members:
66

7+
.. autoclass:: topgg.models.UserSource()
8+
:members:
9+
:undoc-members:
10+
711
.. autoclass:: topgg.widget.WidgetType()
812
:members:
913
:undoc-members:
@@ -21,11 +25,11 @@ Client reference
2125
.. autoclass:: topgg.errors.Ratelimited()
2226
:members:
2327

24-
.. autodata:: topgg.client.AutopostRetrievalCallback
25-
.. autodata:: topgg.client.AutopostRetrievalDecorator
28+
.. autodata:: topgg.client.BotAutopostRetrievalCallback
29+
.. autodata:: topgg.client.BotAutopostRetrievalDecorator
2630

27-
.. autodata:: topgg.client.AutopostSuccessCallback
28-
.. autodata:: topgg.client.AutopostSuccessDecorator
31+
.. autodata:: topgg.client.BotAutopostSuccessCallback
32+
.. autodata:: topgg.client.BotAutopostSuccessDecorator
2933

30-
.. autodata:: topgg.client.AutopostErrorCallback
31-
.. autodata:: topgg.client.AutopostErrorDecorator
34+
.. autodata:: topgg.client.BotAutopostErrorCallback
35+
.. autodata:: topgg.client.BotAutopostErrorDecorator

docs/data.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ Data reference
77
.. autoclass:: topgg.models.Vote()
88
:members:
99

10+
.. autoclass:: topgg.models.VoteEvent()
11+
:members:
12+
1013
.. autoclass:: topgg.models.Voter()
1114
:members:

docs/index.rst

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Implicit cleanup
2222
2323
import os
2424
25-
2625
async with topgg.Client(os.getenv('TOPGG_TOKEN')) as client:
2726
# ...
2827
@@ -35,7 +34,6 @@ Explicit cleanup
3534
3635
import os
3736
38-
3937
client = topgg.Client(os.getenv('TOPGG_TOKEN'))
4038
4139
# ...
@@ -75,8 +73,8 @@ With explicit arguments
7573
for bot in bots:
7674
print(bot)
7775
78-
Getting your bot's voters
79-
~~~~~~~~~~~~~~~~~~~~~~~~~
76+
Getting your project’s voters
77+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8078

8179
First page
8280
^^^^^^^^^^
@@ -98,49 +96,99 @@ Subsequent pages
9896
for voter in voters:
9997
print(voter)
10098
101-
Check if a user has voted for your bot
102-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99+
Getting your project’s vote information of a user
100+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101+
102+
Discord ID
103+
^^^^^^^^^^
103104

104105
.. code-block:: python
105106
106-
has_voted = await client.has_voted(661200758510977084)
107+
vote = await client.get_vote(661200758510977084)
108+
109+
if vote:
110+
print(f'User has voted: {vote!r}')
107111
108-
Getting your bot's server count
112+
Top.gg ID
113+
^^^^^^^^^
114+
115+
.. code-block:: python
116+
117+
vote = await client.get_vote(8226924471638491136, source=topgg.UserSource.TOPGG)
118+
119+
if vote:
120+
print(f'User has voted: {vote!r}')
121+
122+
Getting your bot’s server count
109123
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110124

111125
.. code-block:: python
112126
113-
posted_server_count = await client.get_server_count()
127+
posted_server_count = await client.get_bot_server_count()
114128
115-
Posting your bot's server count
129+
Posting your bots server count
116130
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117131

118132
.. code-block:: python
119133
120-
await client.post_server_count(bot.server_count)
134+
await client.post_bot_server_count(bot.server_count)
135+
136+
Posting your bot’s application commands list
137+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138+
139+
Discord.py/Pycord/Nextcord/Disnake
140+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
142+
.. code-block:: python
121143
122-
Automatically posting your bot's server count every few minutes
144+
app_id = bot.user.id
145+
commands = await bot.http.get_global_commands(app_id)
146+
147+
await client.post_bot_commands(commands)
148+
149+
Hikari
150+
^^^^^^
151+
152+
.. code-block:: python
153+
154+
app_id = ...
155+
commands = await bot.rest.request('GET', f'/applications/{app_id}/commands')
156+
157+
await client.post_bot_commands(commands)
158+
159+
Discord.http
160+
^^^^^^^^^^^^
161+
162+
.. code-block:: python
163+
164+
http = discordhttp.HTTP(f'BOT {os.getenv("BOT_TOKEN")}')
165+
app_id = ...
166+
commands = await http.get(f'/applications/{app_id}/commands')
167+
168+
await client.post_bot_commands(commands)
169+
170+
Automatically posting your bot’s server count every few minutes
123171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124172

125173
.. code-block:: python
126174
127-
@client.autopost_retrieval
175+
@client.bot_autopost_retrieval
128176
def get_server_count() -> int:
129177
return bot.server_count
130178
131-
@client.autopost_success
179+
@client.bot_autopost_success
132180
def success(server_count: int) -> None:
133181
print(f'Successfully posted {server_count} servers to Top.gg!')
134182
135-
@client.autopost_error
183+
@client.bot_autopost_error
136184
def error(error: topgg.Error) -> None:
137185
print(f'Error: {error!r}')
138186
139-
client.start_autoposter()
187+
client.start_bot_autoposter()
140188
141189
# ...
142190
143-
client.stop_autoposter() # Optional
191+
client.stop_bot_autoposter() # Optional
144192
145193
Checking if the weekend vote multiplier is active
146194
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -183,8 +231,8 @@ Social
183231
Webhooks
184232
~~~~~~~~
185233

186-
Being notified whenever someone voted for your bot
187-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
234+
Being notified whenever someone voted for your project
235+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
188236

189237
.. code-block:: python
190238
@@ -193,11 +241,10 @@ Being notified whenever someone voted for your bot
193241
import asyncio
194242
import os
195243
196-
197244
webhooks = topgg.Webhooks(os.getenv('MY_TOPGG_WEBHOOK_SECRET'), 8080)
198245
199246
@webhooks.on_vote('/votes')
200-
def voted(vote: topgg.Vote) -> None:
247+
def voted(vote: topgg.VoteEvent) -> None:
201248
print(f'A user with the ID of {vote.voter_id} has voted us on Top.gg!')
202249
203250
async def main() -> None:

test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ async def run() -> None:
5252
test_attributes(b)
5353

5454
await asyncio.sleep(1)
55-
await tg.post_server_count(2)
55+
await tg.post_bot_commands([{'name': 'test', 'description': 'command description'}])
5656

5757
await asyncio.sleep(1)
58-
posted_server_count = await tg.get_server_count()
58+
await tg.post_bot_server_count(2)
59+
60+
await asyncio.sleep(1)
61+
posted_server_count = await tg.get_bot_server_count()
5962

6063
assert posted_server_count == 2
6164

@@ -66,9 +69,10 @@ async def run() -> None:
6669
test_attributes(voter)
6770

6871
await asyncio.sleep(1)
69-
has_voted = await tg.has_voted(661200758510977084)
72+
await tg.get_vote(661200758510977084)
7073

71-
assert isinstance(has_voted, bool)
74+
await asyncio.sleep(1)
75+
await tg.get_vote(8226924471638491136, source=topgg.UserSource.TOPGG)
7276

7377
await asyncio.sleep(1)
7478
is_weekend = await tg.is_weekend()

0 commit comments

Comments
 (0)