Skip to content

Commit 05c50b3

Browse files
authored
Add Service: DiscordBotsCo (#6)
1 parent f3bfd54 commit 05c50b3

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ See more examples [here](/examples).
114114
- [bots.ondiscord.xyz](https://bots.ondiscord.xyz) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.BotsOnDiscord))
115115
- [carbonitex.net](https://www.carbonitex.net/Discord/bots) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.Carbon))
116116
- [dblista.pl](https://dblista.pl) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DBLista))
117+
- [discordbots.co](https://discordbots.co) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DiscordBotsCo))
117118
- [discord.bots.gg](https://discord.bots.gg) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DiscordBotsGG))
118119
- [discordapps.dev](https://discordapps.dev) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DiscordAppsDev))
119120
- [discord.boats](https://discord.boats) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DiscordBoats))

dbots/service.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,54 @@ def search(self, query: str) -> HTTPResponse:
801801
path = f'/bots/search/{uri}'
802802
)
803803

804+
class DiscordBotsCo(Service):
805+
"""
806+
Represents the DiscordBots.co service.
807+
808+
.. seealso::
809+
- `DiscordBots.co Website <https://discordbots.co/>`_
810+
- `DiscordBots.co API Documentation <https://discordbots.co/api/>`_
811+
"""
812+
813+
BASE_URL = 'https://api.discordbots.co/v1/public'
814+
815+
@staticmethod
816+
def aliases() -> list:
817+
return ['discordbotsco']
818+
819+
@staticmethod
820+
def _post(
821+
http_client: HTTPClient, bot_id: str, token: str,
822+
server_count = 0, user_count = 0,
823+
voice_connections = 0, shard_count: int = None,
824+
shard_id: int = None
825+
) -> HTTPResponse:
826+
payload = { 'serverCount': server_count }
827+
if shard_id and shard_count:
828+
payload['shardCount'] = shard_count
829+
return http_client.request(
830+
method = 'POST',
831+
path = f'{DiscordBotsCo.BASE_URL}/bot/{bot_id}',
832+
headers = { 'Authorization': token },
833+
json = payload
834+
)
835+
836+
def get_bot(self, bot_id: str) -> HTTPResponse:
837+
"""|httpres|\n
838+
Gets the bot listed on this service.
839+
840+
Parameters
841+
-----------
842+
bot_id: :class:`str`
843+
The bot's ID.
844+
"""
845+
return self._request(
846+
method = 'GET',
847+
path = f'/bot/{bot_id}',
848+
headers = { 'Authorization': self.token },
849+
requires_token = True
850+
)
851+
804852
class DiscordBotsGG(Service):
805853
"""
806854
Represents the Discord Bots service.
@@ -2038,7 +2086,7 @@ def get_unverified_bots(self) -> HTTPResponse:
20382086

20392087
Service.SERVICES = [
20402088
Arcane, Blist, BotListSpace, BotsDataBase, BotsForDiscord, BotsOnDiscord, Carbon,
2041-
DBLista, DiscordBotsGG, DiscordAppsDev, DiscordBoats,
2089+
DBLista, DiscordBotsCo, DiscordBotsGG, DiscordAppsDev, DiscordBoats,
20422090
DiscordBotList, DiscordBotWorld, DiscordExtremeList, GlennBotList,
20432091
LBots, ListMyBots, MythicalBots, SpaceBotsList, TopGG, WonderBotList, YABL
20442092
]

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Services
7070
.. autoclass:: DBLista
7171
:members:
7272

73+
.. autoclass:: DiscordBotsCo
74+
:members:
75+
7376
.. autoclass:: DiscordBotsGG
7477
:members:
7578

0 commit comments

Comments
 (0)