Skip to content

Commit bfcf8f5

Browse files
committed
Add DBlista as a service
1 parent 15408f0 commit bfcf8f5

File tree

4 files changed

+180
-4
lines changed

4 files changed

+180
-4
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
- [carbonitex.net](https://www.carbonitex.net/Discord/bots) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.Carbon))
115115
- [cloud-botlist.xyz](https://cloud-botlist.xyz) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.CloudBotList))
116116
- [cloudlist.xyz](https://cloudlist.xyz) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.CloudList))
117+
- [dblista.pl](https://dblista.pl) ([docs](https://dbots.readthedocs.io/en/latest/api.html#dbots.DBLista))
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/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ class HTTPNotFound(HTTPException):
5555
class EndpointRequiresToken(DBotsException):
5656
"""Exception that's thrown for when an endpoint is being used without a token."""
5757
def __init__(self):
58-
super().__init__('This endpoint requires a token.')
58+
super().__init__('This endpoint requires a token.')
59+
60+
class PostingUnsupported(ServiceException):
61+
"""Exception that's thrown for services that cannot be posted to."""
62+
def __init__(self):
63+
super().__init__('This service does not support posting.')

dbots/service.py

Lines changed: 170 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .http import HTTPClient, HTTPResponse
2-
from .errors import EndpointRequiresToken, ServiceException
2+
from .errors import EndpointRequiresToken, ServiceException, PostingUnsupported
33
from urllib.parse import urlencode as _encode_query
4+
from urllib.parse import quote as _encode_uri
45

56
class Service:
67
"""
@@ -624,6 +625,172 @@ def get_bot_votes(self, bot_id: str) -> HTTPResponse:
624625
requires_token = True
625626
)
626627

628+
class DBLista(Service):
629+
"""
630+
Represents the DBLista service.
631+
632+
.. seealso::
633+
- `DBLista Website <https://dblista.pl/>`_
634+
- `DBLista API Documentation <https://docs.dblista.pl/>`_
635+
"""
636+
637+
BASE_URL = 'https://www.cloudlist.xyz/api'
638+
639+
@staticmethod
640+
def aliases() -> list:
641+
return ['dblistapl', 'dblista.pl', 'dblista']
642+
643+
@staticmethod
644+
def _post(
645+
http_client: HTTPClient, bot_id: str, token: str
646+
) -> HTTPResponse:
647+
raise PostingUnsupported()
648+
649+
def add_bot(self, data: dict) -> HTTPResponse:
650+
"""|httpres|\n
651+
Updates the bot's listing with the data provided.
652+
653+
Parameters
654+
-----------
655+
data: :class:`dict`
656+
The data being posted. This should include the ID of the bot.
657+
"""
658+
return self._request(
659+
method = 'POST',
660+
path = '/bots',
661+
json = data,
662+
headers = { 'Authorization': self.token },
663+
requires_token = True
664+
)
665+
666+
def update_bot(self, data: dict) -> HTTPResponse:
667+
"""|httpres|\n
668+
Updates the bot's listing with the data provided.
669+
670+
Parameters
671+
-----------
672+
data: :class:`dict`
673+
The data being posted. This should include the ID of the bot.
674+
"""
675+
return self._request(
676+
method = 'PUT',
677+
path = '/bots',
678+
json = data,
679+
headers = { 'Authorization': self.token },
680+
requires_token = True
681+
)
682+
683+
def get_bot(self, bot_id: str) -> HTTPResponse:
684+
"""|httpres|\n
685+
Gets the bot's stats on this service.
686+
687+
Parameters
688+
-----------
689+
bot_id: :class:`str`
690+
The bot's ID.
691+
"""
692+
return self._request(
693+
method = 'GET',
694+
path = f'/bots/{bot_id}'
695+
)
696+
697+
def get_bots(self, page: int = 0) -> HTTPResponse:
698+
"""|httpres|\n
699+
Gets the bot's stats on this service.
700+
701+
Parameters
702+
-----------
703+
page: :class:`int`
704+
The page you want to get.
705+
"""
706+
return self._request(
707+
method = 'GET',
708+
path = f'/bots/list/{page}'
709+
)
710+
711+
def get_unverified_bots(self) -> HTTPResponse:
712+
"""|httpres|\n
713+
Gets a list of unverified bots on this service.
714+
"""
715+
return self._request(
716+
method = 'GET',
717+
path = '/bots/list/unverified'
718+
)
719+
720+
def get_rejected_bots(self) -> HTTPResponse:
721+
"""|httpres|\n
722+
Gets a list of rejected bots on this service.
723+
"""
724+
return self._request(
725+
method = 'GET',
726+
path = '/bots/list/rejected'
727+
)
728+
729+
def rate_bot(self, bot_id: str, data: dict) -> HTTPResponse:
730+
"""|httpres|\n
731+
Adds a rating to a bot on the service.
732+
733+
Parameters
734+
-----------
735+
bot_id: :class:`str`
736+
The bot's ID.
737+
data: :class:`dict`
738+
The data being posted. This should include the ID of the bot.
739+
"""
740+
return self._request(
741+
method = 'POST',
742+
path = f'/bots/{bot_id}/rate',
743+
json = data,
744+
headers = { 'Authorization': self.token },
745+
requires_token = True
746+
)
747+
748+
def remove_rating(self, bot_id: str) -> HTTPResponse:
749+
"""|httpres|\n
750+
Removes a rating from a bot on the service.
751+
752+
Parameters
753+
-----------
754+
bot_id: :class:`str`
755+
The bot's ID.
756+
"""
757+
return self._request(
758+
method = 'DELETE',
759+
path = f'/bots/{bot_id}/rate',
760+
headers = { 'Authorization': self.token },
761+
requires_token = True
762+
)
763+
764+
def remove_bot(self, bot_id: str) -> HTTPResponse:
765+
"""|httpres|\n
766+
Removes a bot from the service.
767+
768+
Parameters
769+
-----------
770+
bot_id: :class:`str`
771+
The bot's ID.
772+
"""
773+
return self._request(
774+
method = 'DELETE',
775+
path = f'/bots/{bot_id}',
776+
headers = { 'Authorization': self.token },
777+
requires_token = True
778+
)
779+
780+
def search(self, query: str) -> HTTPResponse:
781+
"""|httpres|\n
782+
Searches for bots on the service.
783+
784+
Parameters
785+
-----------
786+
query: :class:`str`
787+
The query to search for.
788+
"""
789+
return self._request(
790+
method = 'GET',
791+
path = f'/bots/search/{_encode_uri(query, safe='~()*!.\'')}'
792+
)
793+
627794
class DiscordBotsGG(Service):
628795
"""
629796
Represents the Discord Bots service.
@@ -1944,8 +2111,8 @@ def get_unverified_bots(self) -> HTTPResponse:
19442111
)
19452112

19462113
Service.SERVICES = [
1947-
Arcane, BotListSpace, BotsForDiscord, BotsOfDiscord, BotsOnDiscord,
1948-
Carbon, CloudBotList, CloudList, DiscordBotsGG, DiscordAppsDev, DiscordBoats,
2114+
Arcane, BotListSpace, BotsForDiscord, BotsOfDiscord, BotsOnDiscord, Carbon,
2115+
CloudBotList, CloudList, DBLista, DiscordBotsGG, DiscordAppsDev, DiscordBoats,
19492116
DiscordBotList, DiscordBotWorld, DiscordExtremeList, DivineDiscordBots, GlennBotList,
19502117
LBots, ListMyBots, MythicalBots, SpaceBotsList, TopGG, WonderBotList, YABL
19512118
]

docs/api.rst

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

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

0 commit comments

Comments
 (0)