Skip to content

Commit f3bfd54

Browse files
authored
Add service: Blist (#5)
1 parent 08b5c5e commit f3bfd54

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ See more examples [here](/examples).
107107

108108
### Supported Services
109109
- [arcane-center.xyz](https://arcane-center.xyz) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.Arcane))
110+
- [blist.xyz](https://blist.xyz) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.Blist))
110111
- [botlist.space](https://botlist.space) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.BotListSpace))
111112
- [botsdatabase.com](https://botsdatabase.com/) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.BotsDataBase))
112113
- [botsfordiscord.com](https://botsfordiscord.com) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.BotsForDiscord))

dbots/service.py

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,98 @@ def _post(
135135
json = payload
136136
)
137137

138+
class Blist(Service):
139+
"""
140+
Represents the Blist service.
141+
142+
.. seealso::
143+
- `Blist Website <https://blist.xyz/>`_
144+
- `Blist API Documentation <https://blist.xyz/docs/>`_
145+
"""
146+
147+
BASE_URL = 'https://blist.xyz/api'
148+
149+
@staticmethod
150+
def aliases() -> list:
151+
return ['blist', 'blist.xyz']
152+
153+
@staticmethod
154+
def _post(
155+
http_client: HTTPClient, bot_id: str, token: str,
156+
server_count = 0, user_count = 0,
157+
voice_connections = 0, shard_count: int = None,
158+
shard_id: int = None
159+
) -> HTTPResponse:
160+
payload = { 'server_count': server_count }
161+
if shard_id and shard_count:
162+
payload['shard_count'] = shard_count
163+
return http_client.request(
164+
method = 'POST',
165+
path = f'{Blist.BASE_URL}/bot/{bot_id}/stats',
166+
headers = { 'Authorization': token },
167+
json = payload
168+
)
169+
170+
def get_user(self, user_id: str) -> HTTPResponse:
171+
"""|httpres|\n
172+
Gets the user listed on this service.
173+
174+
Parameters
175+
-----------
176+
user_id: :class:`str`
177+
The user's ID.
178+
"""
179+
return self._request(
180+
method = 'GET',
181+
path = f'/user/{user_id}'
182+
)
183+
184+
def get_bot(self, bot_id: str) -> HTTPResponse:
185+
"""|httpres|\n
186+
Gets the bot listed on this service.
187+
188+
Parameters
189+
-----------
190+
bot_id: :class:`str`
191+
The bot's ID.
192+
"""
193+
return self._request(
194+
method = 'GET',
195+
path = f'/bot/{bot_id}/stats'
196+
)
197+
198+
def get_bot_votes(self, bot_id: str) -> HTTPResponse:
199+
"""|httpres|\n
200+
Gets the list of people who voted this bot on this service.
201+
202+
Parameters
203+
-----------
204+
bot_id: :class:`str`
205+
The bot's ID.
206+
"""
207+
return self._request(
208+
method = 'GET',
209+
path = f'/bot/{bot_id}/votes',
210+
headers = { 'Authorization': self.token },
211+
requires_token = True
212+
)
213+
214+
def get_widget_url(self, bot_id: str, widget_type: str = 'normal', **query) -> str:
215+
"""
216+
Gets the widget URL for this bot.
217+
218+
Parameters
219+
-----------
220+
bot_id: :class:`str`
221+
The bot's ID.
222+
widget_type: Optional[:class:`str`]
223+
The type of widget to show.
224+
**query
225+
The query string to append to the URL.
226+
"""
227+
query['type'] = widget_type
228+
return f'{Blist.BASE_URL}/widget/{subpath}{bot_id}.svg?{_encode_query(query)}'
229+
138230
class BotListSpace(Service):
139231
"""
140232
Represents the botlist.space service.
@@ -1945,7 +2037,7 @@ def get_unverified_bots(self) -> HTTPResponse:
19452037
)
19462038

19472039
Service.SERVICES = [
1948-
Arcane, BotListSpace, BotsDataBase, BotsForDiscord, BotsOnDiscord, Carbon,
2040+
Arcane, Blist, BotListSpace, BotsDataBase, BotsForDiscord, BotsOnDiscord, Carbon,
19492041
DBLista, DiscordBotsGG, DiscordAppsDev, DiscordBoats,
19502042
DiscordBotList, DiscordBotWorld, DiscordExtremeList, GlennBotList,
19512043
LBots, ListMyBots, MythicalBots, SpaceBotsList, TopGG, WonderBotList, YABL

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Services
4949
.. autoclass:: Arcane
5050
:members:
5151

52+
.. autoclass:: Blist
53+
:members:
54+
5255
.. autoclass:: BotListSpace
5356
:members:
5457

0 commit comments

Comments
 (0)