Made project ready to release

This commit is contained in:
grey-cat-1908 2023-06-27 18:26:42 +03:00
parent 783c6cb9de
commit f036b31f21
9 changed files with 74 additions and 23 deletions

8
ACKNOWLEDGEMENTS.txt Normal file
View file

@ -0,0 +1,8 @@
These are the open source libraries we use:
- aiohttp (https://github.com/aio-libs/aiohttp)
- typing_extensions (https://github.com/python/typing_extensions)
- sphinx (https://github.com/sphinx-doc/sphinx)
- furo (https://github.com/pradyunsg/furo)
It is also important to note that some developments of Melisa (https://github.com/MelisaDev/melisa) were used in the development of the project.
I would also like to express my gratitude to the former admin staff of the BotiCord service (until 06/02/2023) and the entire project community.

View file

@ -22,12 +22,12 @@
* Object-oriented * Object-oriented
* Full BotiCord API Coverage * Full BotiCord API Coverage
* Modern Pythonic API using `async`/`await` syntax * Modern Pythonic API using `async`/`await` syntax
* BotiCord Webhooks * BotiCord Websocket
* It is not necessary to use any particular library used to interact with the Discord API. * It is not necessary to use any particular library used to interact with the Discord API.
<h2>Installation</h2> <h2>Installation</h2>
<b>Python 3.6 or newer is required.</b> <b>Python 3.8 or newer is required.</b>
Enter one of these commands to install the library: Enter one of these commands to install the library:
@ -49,28 +49,33 @@ You can find other examples in an examples folder.
```py ```py
from discord.ext import commands from discord.ext import commands
from boticordpy import BoticordClient from boticordpy import BoticordClient
bot = commands.Bot(command_prefix="!") bot = commands.Bot(command_prefix="!")
# Function that will return the current bot's stats.
async def get_stats(): async def get_stats():
return {"servers": len(bot.guilds), "shards": 0, "users": len(bot.users)} return {"servers": len(bot.guilds), "shards": 0, "users": len(bot.users)}
# Function that will be called if stats are posted successfully.
async def on_success_posting(): async def on_success_posting():
print("stats posting successfully") print("wow stats posting works")
boticord_client = BoticordClient("your_api_token")
boticord_client = BoticordClient(
"your_boticord_api_token", version=3
) # <--- BotiCord API token
autopost = ( autopost = (
boticord_client.autopost() boticord_client.autopost()
.init_stats(get_stats) .init_stats(get_stats)
.on_success(on_success_posting) .on_success(on_success_posting)
.start() .start("id_of_your_bot") # <--- ID of your bot
) )
bot.run("bot token") bot.run("bot token") # <--- Discord bot's token
``` ```
<h2>Links</h2> <h2>Links</h2>

View file

@ -10,7 +10,7 @@ __title__ = "boticordpy"
__author__ = "Marakarka" __author__ = "Marakarka"
__license__ = "MIT" __license__ = "MIT"
__copyright__ = "Copyright 2021 - 2023 Marakarka" __copyright__ = "Copyright 2021 - 2023 Marakarka"
__version__ = "3.0.0a" __version__ = "3.0.0"
from .client import BoticordClient from .client import BoticordClient
from .types import * from .types import *

View file

@ -199,9 +199,9 @@ class AutoPost:
task = asyncio.ensure_future(self._internal_loop()) task = asyncio.ensure_future(self._internal_loop())
self._task = task self._task = task
_logger.info("Started autoposting") _logger.info("Started autoposting")
return task return task
def stop(self) -> None: def stop(self) -> None:

View file

@ -46,7 +46,7 @@ class BoticordClient:
ResourceBot object. ResourceBot object.
""" """
_logger.info("Requesting information about bot") _logger.info("Requesting information about bot")
response = await self.http.get_bot_info(bot_id) response = await self.http.get_bot_info(bot_id)
return boticord_types.ResourceBot.from_dict(response) return boticord_types.ResourceBot.from_dict(response)
@ -75,7 +75,7 @@ class BoticordClient:
ResourceBot object. ResourceBot object.
""" """
_logger.info("Posting bot stats") _logger.info("Posting bot stats")
response = await self.http.post_bot_stats( response = await self.http.post_bot_stats(
bot_id, {"servers": servers, "shards": shards, "users": users} bot_id, {"servers": servers, "shards": shards, "users": users}
) )
@ -95,7 +95,7 @@ class BoticordClient:
ResourceServer object. ResourceServer object.
""" """
_logger.info("Requesting information about server") _logger.info("Requesting information about server")
response = await self.http.get_server_info(server_id) response = await self.http.get_server_info(server_id)
return boticord_types.ResourceServer.from_dict(response) return boticord_types.ResourceServer.from_dict(response)
@ -113,7 +113,7 @@ class BoticordClient:
UserProfile object. UserProfile object.
""" """
_logger.info("Requesting information about user") _logger.info("Requesting information about user")
response = await self.http.get_user_info(user_id) response = await self.http.get_user_info(user_id)
return boticord_types.UserProfile.from_dict(response) return boticord_types.UserProfile.from_dict(response)

View file

@ -1,4 +1,3 @@
from urllib.parse import urlparse
import asyncio import asyncio
import typing import typing
@ -23,7 +22,7 @@ class HttpClient:
def __init__(self, auth_token: str = None, version: int = 3, **kwargs): def __init__(self, auth_token: str = None, version: int = 3, **kwargs):
self.token = auth_token self.token = auth_token
self.API_URL = f"https://api.arbuz.pro/" self.API_URL = f"https://api.boticord.top/v{version}"
loop = kwargs.get("loop") or asyncio.get_event_loop() loop = kwargs.get("loop") or asyncio.get_event_loop()

View file

@ -13,7 +13,7 @@ _logger = logging.getLogger("boticord.websocket")
class BotiCordWebsocket: class BotiCordWebsocket:
"""Represents a client that can be used to interact with the BotiCord by websocket connection.""" """Represents a client that can be used to interact with the BotiCord by websocket connection."""
def __init__(self, token: str): def __init__(self, token: str):
self.__session = None self.__session = None
self.loop = asyncio.get_event_loop() self.loop = asyncio.get_event_loop()
@ -25,17 +25,17 @@ class BotiCordWebsocket:
def listener(self): def listener(self):
"""Decorator to set the listener. """Decorator to set the listener.
.. warning:: .. warning::
Callback functions must be a **coroutine**. If they aren't, then you might get unexpected Callback functions must be a **coroutine**. If they aren't, then you might get unexpected
errors. In order to turn a function into a coroutine they must be ``async def`` errors. In order to turn a function into a coroutine they must be ``async def``
functions. functions.
For example: For example:
.. code-block:: python .. code-block:: python
@websocket.listener() @websocket.listener()
async def comment_removed(data): async def comment_removed(data):
pass pass
@ -58,7 +58,7 @@ class BotiCordWebsocket:
Type of notification (Check reference page) Type of notification (Check reference page)
callback (:obj:`function`) callback (:obj:`function`)
Coroutine Callback Function Coroutine Callback Function
.. warning:: .. warning::
Callback functions must be a **coroutine**. If they aren't, then you might get unexpected Callback functions must be a **coroutine**. If they aren't, then you might get unexpected
@ -77,7 +77,7 @@ class BotiCordWebsocket:
try: try:
self.__session = aiohttp.ClientSession() self.__session = aiohttp.ClientSession()
self.ws = await self.__session.ws_connect( self.ws = await self.__session.ws_connect(
"wss://gateway.arbuz.pro/websocket/", "wss://gateway.boticord.top/websocket/",
timeout=30.0, timeout=30.0,
) )

16
examples/stats_melisa.py Normal file
View file

@ -0,0 +1,16 @@
import melisa
from boticordpy import BoticordClient
bot = melisa.Bot("your_discord_bot_token")
boticord = BoticordClient("your_boticord_api_token")
@bot.listen
async def on_message_create(message):
if message.content.startswith("!guilds"):
data = await boticord.get_bot_info(bot.user.id)
await bot.rest.create_message(message.channel.id, data.guilds)
bot.run_autosharded()

23
examples/websocket.py Normal file
View file

@ -0,0 +1,23 @@
# You can use any library to interact with the Discord API.
# This example uses discord.py.
# You can install it with `pip install discord.py`.
from discord.ext import commands
from boticordpy import BotiCordWebsocket
bot = commands.Bot(command_prefix="!")
websocket = BotiCordWebsocket("your_boticord_api_token") # <--- BotiCord API token
@websocket.listener()
async def comment_removed(data):
print(data["payload"])
@bot.event
async def on_ready():
await websocket.connect()
bot.run("bot token") # <--- Discord bot's token