From e1a24b21dd5c2f59a4764b337de86c7e558b2f0e Mon Sep 17 00:00:00 2001 From: ShowierData9978 Date: Thu, 11 Jan 2024 00:37:53 -0600 Subject: [PATCH] Fix: Forgot an argument Fix: Got rid of illegal HTTP passthrough argument Feat: Added assert tests --- MeowerBot/_version.py | 2 +- MeowerBot/api/user.py | 11 +++++++++-- MeowerBot/context.py | 2 +- pyproject.toml | 2 +- tests/intergration/integration_login.py | 15 ++++++++++++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/MeowerBot/_version.py b/MeowerBot/_version.py index 6a157dc..310a75d 100644 --- a/MeowerBot/_version.py +++ b/MeowerBot/_version.py @@ -1 +1 @@ -__version__ = '3.3.0' +__version__ = '3.3.1' diff --git a/MeowerBot/api/user.py b/MeowerBot/api/user.py index 1c7496d..719bf6d 100644 --- a/MeowerBot/api/user.py +++ b/MeowerBot/api/user.py @@ -16,8 +16,15 @@ class User: def __init__(self, client: AsyncClient) -> None: self.client = client - async def _get(self, username, url, json=None, page=1, query=None, params=None): - return await self.client.get(urljoin(f"/users/{username}/", url), json=json, params={"q": query, "p": page, **params}) + async def _get(self, username, url, page=1, query=None, params=None): + + if query is None: + query = dict() + + if params is None: + params = dict() + + return await self.client.get(urljoin(f"/users/{username}/", url), params={"q": query, "p": page, **params}) async def get_posts(self, username, query, page=1): return api_resp(PagedRequest[Post], await self._get(username, "posts", query=query, page=page, params={"autoget": None})) diff --git a/MeowerBot/context.py b/MeowerBot/context.py index 3a4f478..5222172 100644 --- a/MeowerBot/context.py +++ b/MeowerBot/context.py @@ -22,7 +22,7 @@ async def send_msg(self, message) -> Optional["Post"]: return Post(self.bot, data.to_dict(), self) async def fetch(self) -> Optional["Chat"]: - chat = self.bot.cache.get_chat() + chat = self.bot.cache.get_chat(self.id) if isinstance(chat, Chat): return chat data, status = await self.bot.api.chats.get(self.id) diff --git a/pyproject.toml b/pyproject.toml index c8f6192..5327c1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "MeowerBot" -version = "3.3.0" +version = "3.3.1" description = "A meower bot lib for py" authors = ["showierdata9978 <68120127+showierdata9978@users.noreply.github.com>"] license = "MIT" diff --git a/tests/intergration/integration_login.py b/tests/intergration/integration_login.py index e8c0fb3..85b50b5 100644 --- a/tests/intergration/integration_login.py +++ b/tests/intergration/integration_login.py @@ -1,5 +1,5 @@ from MeowerBot import Bot, CallBackIds -from MeowerBot.context import Context, Post +from MeowerBot.context import Context, PartialUser, Post, User from MeowerBot.cog import Cog from MeowerBot.command import command @@ -90,8 +90,17 @@ async def ping(self, ctx: Context): await ctx.send_msg("Pong!\n My latency is: " + str(self.bot.latency)) - - +@bot.event +async def login(token): + assert await bot.get_chat("9bf5bddd-cd1a-4c0d-a34c-31ae554ed4a7").fetch() is not None + assert await bot.get_chat("9bf5bddd").fetch() is None + assert await PartialUser(bot.user.username, bot).fetch() is not None + assert await PartialUser("A" * 21, bot).fetch() is None + +@bot.listen(CallBackIds.message) +async def on_message(message: Post): + assert isinstance(message, Post) + assert isinstance(bot.get_context(message), Context) bot.register_cog(Ping(bot)) bot.register_cog(HelpExt(bot, disable_command_newlines=True))