mirror of
https://github.com/boticord/boticordpy.git
synced 2024-11-11 19:07:29 +03:00
add disnake library support
This commit is contained in:
parent
fd59896df9
commit
b271effd5a
7 changed files with 41 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
from discord.ext import commands
|
||||
from disnake.ext import commands as commandsnake
|
||||
import aiohttp
|
||||
|
||||
from typing import Union
|
||||
|
@ -11,6 +12,7 @@ class BoticordClient:
|
|||
|
||||
"""
|
||||
This class is used to make it much easier to use the Boticord API.
|
||||
You can pass `lib` parameter to specify the library. Supported: ["discordpy", "disnake"]
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
@ -34,17 +36,19 @@ class BoticordClient:
|
|||
"Servers",
|
||||
"Users",
|
||||
"bot",
|
||||
"events"
|
||||
"events",
|
||||
"lib"
|
||||
)
|
||||
|
||||
bot: Union[commands.Bot, commands.AutoShardedBot]
|
||||
bot: Union[commands.Bot, commands.AutoShardedBot, commandsnake.Bot, commandsnake.AutoShardedBot]
|
||||
|
||||
def __init__(self, bot, token=None, **kwargs):
|
||||
loop = kwargs.get('loop') or asyncio.get_event_loop()
|
||||
session = kwargs.get('session') or aiohttp.ClientSession(loop=loop)
|
||||
self.lib = kwargs.get('lib') or "discordpy"
|
||||
self.events = {}
|
||||
self.bot = bot
|
||||
self.Bots = Bots(bot, token=token, loop=loop, session=session)
|
||||
self.Bots = Bots(bot, token=token, loop=loop, session=session, lib=self.lib)
|
||||
self.Servers = Servers(bot, token=token, loop=loop, session=session)
|
||||
self.Users = Users(token=token, loop=loop, session=session)
|
||||
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
from aiohttp import ClientResponse
|
||||
|
||||
from disnake.ext import commands as commandsnake
|
||||
from discord.ext import commands
|
||||
|
||||
from typing import Union
|
||||
import json
|
||||
|
||||
from aiohttp import ClientResponse
|
||||
|
||||
from . import exceptions
|
||||
from . import types
|
||||
|
@ -22,6 +26,10 @@ class Config:
|
|||
"delete_bot_comment": types.Comment,
|
||||
"new_bot_bump": types.BotVote
|
||||
}
|
||||
libs = {
|
||||
"discordpy": commands,
|
||||
"disnake": commandsnake
|
||||
}
|
||||
|
||||
|
||||
async def _json_or_text(response: ClientResponse) -> Union[dict, str]:
|
||||
|
|
|
@ -22,6 +22,7 @@ class Bots:
|
|||
self.token = kwargs.get('token')
|
||||
self.loop = kwargs.get('loop') or asyncio.get_event_loop()
|
||||
self.session = kwargs.get('session') or aiohttp.ClientSession(loop=self.loop)
|
||||
self.lib = Config.libs.get(kwargs.get("lib"))
|
||||
|
||||
async def get_bot_info(self, bot_id: int):
|
||||
"""
|
||||
|
@ -77,7 +78,7 @@ class Bots:
|
|||
if stats is None:
|
||||
data_to_send = {"servers": len(self.bot.guilds), "users": len(self.bot.users)}
|
||||
|
||||
if isinstance(self.bot, commands.AutoShardedBot):
|
||||
if isinstance(self.bot, self.lib.AutoShardedBot):
|
||||
data_to_send["shards"] = self.bot.shard_count
|
||||
|
||||
async with self.session.post(f'{Config.general_api}/stats', headers=headers, json=stats) as resp:
|
||||
|
|
|
@ -7,6 +7,7 @@ else:
|
|||
from typing_extensions import TypedDict
|
||||
|
||||
from discord.ext.commands import Bot, AutoShardedBot
|
||||
from disnake.ext import commands as commandsnake
|
||||
from aiohttp.web_urldispatcher import _WebHandler
|
||||
from aiohttp import web
|
||||
import aiohttp
|
||||
|
@ -38,7 +39,10 @@ class BoticordWebhook:
|
|||
]
|
||||
_webserver: web.TCPSite
|
||||
|
||||
def __init__(self, bot: Union[Bot, AutoShardedBot], boticord_client: BoticordClient):
|
||||
def __init__(self, bot: Union[Bot,
|
||||
AutoShardedBot,
|
||||
commandsnake.Bot,
|
||||
commandsnake.AutoShardedBot], boticord_client: BoticordClient):
|
||||
self.bot = bot
|
||||
self.boticord_client = boticord_client
|
||||
self._webhooks = {}
|
||||
|
|
14
examples/disnake/postdata.py
Normal file
14
examples/disnake/postdata.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from discord.ext import commands
|
||||
|
||||
from boticordpy import BoticordClient
|
||||
|
||||
bot = commands.Bot(command_prefix="!")
|
||||
boticord = BoticordClient(bot, "your-boticord-token", lib="disnake")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
await boticord.Bots.post_stats()
|
||||
|
||||
|
||||
bot.run("your-bot-token")
|
|
@ -8,8 +8,7 @@ boticord = BoticordClient(bot, "your-boticord-token")
|
|||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
stats = {"servers": len(bot.guilds), "shards": bot.shard_count, "users": len(bot.users)}
|
||||
await boticord.Bots.post_stats(stats)
|
||||
await boticord.Bots.post_stats()
|
||||
|
||||
|
||||
bot.run("your-bot-token")
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
discord.py
|
||||
aiohttp
|
||||
aiohttp~=3.7.4.post0
|
||||
setuptools==58.2.0
|
||||
disnake~=2.1.2
|
Loading…
Reference in a new issue