From b5ac3283ebaf3025957b7cf301effa653426f894 Mon Sep 17 00:00:00 2001 From: "Mr. Pink" <94206142+forevercynical@users.noreply.github.com> Date: Sun, 3 Sep 2023 21:42:29 -0700 Subject: [PATCH] # --- PKG-INFO | 2 +- pymino/__init__.py | 2 +- pymino/ext/community.py | 48 ++++++++++++++++++++-------------------- pymino/ext/dispatcher.py | 13 +---------- pymino/ext/socket.py | 9 ++++---- setup.cfg | 3 +-- 6 files changed, 33 insertions(+), 44 deletions(-) diff --git a/PKG-INFO b/PKG-INFO index 03716c4e..da7255e5 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pymino -Version: 1.2.5.2 +Version: 1.2.5.3 Summary: Easily create a bot for Amino Apps using a modern easy to use synchronous library. Home-page: https://github.com/forevercynical/pymino Author: forevercynical diff --git a/pymino/__init__.py b/pymino/__init__.py index 1941156d..0ea59463 100644 --- a/pymino/__init__.py +++ b/pymino/__init__.py @@ -6,7 +6,7 @@ __author__ = 'cynical' __license__ = 'MIT' __copyright__ = 'Copyright 2023 Cynical' -__version__ = '1.2.5.2' +__version__ = '1.2.5.3' __description__ = 'A Python wrapper for the aminoapps.com API' from .bot import Bot diff --git a/pymino/ext/community.py b/pymino/ext/community.py index b25c67f0..d0f7d4e6 100644 --- a/pymino/ext/community.py +++ b/pymino/ext/community.py @@ -5301,12 +5301,12 @@ def invite_to_vc(self, chatId: str, userId: str, comId: Union[str, int] = None) data = {"uid": userId})) @community - def feature_user(self, time: int, userId: str, comId: Union[str, int] = None) -> ApiResponse: + def feature_user(self, feature_time: int, userId: str, comId: Union[str, int] = None) -> ApiResponse: """ Features a user in the current or specified community. - :param time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. - :type time: int + :param feature_time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. + :type feature_time: int :param userId: The ID of the user to feature. :type userId: str :param comId: The ID of the community to feature the user in. If not provided, the current community ID is used. @@ -5327,7 +5327,7 @@ def feature_user(self, time: int, userId: str, comId: Union[str, int] = None) -> To feature a user with ID "0000-0000-0000-0000" for 1 day in the current community: - >>> response = client.community.feature_user(time=1, userId="0000-0000-0000-0000") + >>> response = client.community.feature_user(feature_time=1, userId="0000-0000-0000-0000") ... if response.statuscode == 0: ... print("User featured successfully!") ... else: @@ -5335,7 +5335,7 @@ def feature_user(self, time: int, userId: str, comId: Union[str, int] = None) -> To feature a user with ID "1111-1111-1111-1111" for 2 days in a community with ID "123": - >>> response = client.community.feature_user(time=2, userId="1111-1111-1111-1111", comId=123) + >>> response = client.community.feature_user(feature_time=2, userId="1111-1111-1111-1111", comId=123) ... if response.statuscode == 0: ... print("User featured successfully!") ... else: @@ -5346,17 +5346,17 @@ def feature_user(self, time: int, userId: str, comId: Union[str, int] = None) -> url = f"/x{self.community_id if comId is None else comId}/s/user-profile/{userId}/admin", data = { "adminOpName": 114, - "adminOpValue": {"featuredType": 4, "featuredDuration": 86400 if time == 1 else 172800 if time == 2 else 259200 if time == 3 else None}, + "adminOpValue": {"featuredType": 4, "featuredDuration": 86400 if feature_time == 1 else 172800 if feature_time == 2 else 259200 if feature_time == 3 else None}, "timestamp": int(time() * 1000) })) @community - def feature_chat(self, time: int, chatId: str, comId: Union[str, int] = None) -> ApiResponse: + def feature_chat(self, feature_time: int, chatId: str, comId: Union[str, int] = None) -> ApiResponse: """ Features a chat in the current or specified community. - :param time: The duration of the feature. 1 = 1 hour, 2 = 2 hours, 3 = 3 hours. - :type time: int + :param feature_time: The duration of the feature. 1 = 1 hour, 2 = 2 hours, 3 = 3 hours. + :type feature_time: int :param chatId: The ID of the chat to feature. :type chatId: str :param comId: The ID of the community to feature the chat in. If not provided, the current community ID is used. @@ -5377,7 +5377,7 @@ def feature_chat(self, time: int, chatId: str, comId: Union[str, int] = None) -> To feature a chat with ID "0000-0000-0000-0000" for 1 hour in the current community: - >>> response = client.community.feature_chat(time=1, chatId="0000-0000-0000-0000") + >>> response = client.community.feature_chat(feature_time=1, chatId="0000-0000-0000-0000") ... if response.statuscode == 0: ... print("Chat featured successfully!") ... else: @@ -5385,7 +5385,7 @@ def feature_chat(self, time: int, chatId: str, comId: Union[str, int] = None) -> To feature a chat with ID "1111-1111-1111-1111" for 2 hours in a community with ID "123": - >>> response = client.community.feature_chat(time=2, chatId="1111-1111-1111-1111", comId=123) + >>> response = client.community.feature_chat(feature_time=2, chatId="1111-1111-1111-1111", comId=123) ... if response.statuscode == 0: ... print("Chat featured successfully!") ... else: @@ -5396,17 +5396,17 @@ def feature_chat(self, time: int, chatId: str, comId: Union[str, int] = None) -> url = f"/x{self.community_id if comId is None else comId}/s/chat/thread/{chatId}/admin", data = { "adminOpName": 114, - "adminOpValue": {"featuredType": 5, "featuredDuration": 3600 if time == 1 else 7200 if time == 2 else 10800 if time == 3 else None}, + "adminOpValue": {"featuredType": 5, "featuredDuration": 3600 if feature_time == 1 else 7200 if feature_time == 2 else 10800 if feature_time == 3 else None}, "timestamp": int(time() * 1000) })) @community - def feature_blog(self, time: int, blogId: str, comId: Union[str, int] = None) -> ApiResponse: + def feature_blog(self, feature_time: int, blogId: str, comId: Union[str, int] = None) -> ApiResponse: """ Features a blog in the current or specified community. - :param time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. - :type time: int + :param feature_time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. + :type feature_time: int :param blogId: The ID of the blog to feature. :type blogId: str :param comId: The ID of the community to feature the blog in. If not provided, the current community ID is used. @@ -5427,7 +5427,7 @@ def feature_blog(self, time: int, blogId: str, comId: Union[str, int] = None) -> To feature a blog with ID "0000-0000-0000-0000" for 1 day in the current community: - >>> response = client.community.feature_blog(time=1, blogId="0000-0000-0000-0000") + >>> response = client.community.feature_blog(feature_time=1, blogId="0000-0000-0000-0000") ... if response.statuscode == 0: ... print("Blog featured successfully!") ... else: @@ -5435,7 +5435,7 @@ def feature_blog(self, time: int, blogId: str, comId: Union[str, int] = None) -> To feature a blog with ID "1111-1111-1111-1111" for 2 days in a community with ID "123": - >>> response = client.community.feature_blog(time=2, blogId="1111-1111-1111-1111", comId=123) + >>> response = client.community.feature_blog(feature_time=2, blogId="1111-1111-1111-1111", comId=123) ... if response.statuscode == 0: ... print("Blog featured successfully!") ... else: @@ -5446,17 +5446,17 @@ def feature_blog(self, time: int, blogId: str, comId: Union[str, int] = None) -> url = f"/x{self.community_id if comId is None else comId}/s/blog/{blogId}/admin", data = { "adminOpName": 114, - "adminOpValue": {"featuredType": 1, "featuredDuration": 86400 if time == 1 else 172800 if time == 2 else 259200 if time == 3 else None}, + "adminOpValue": {"featuredType": 1, "featuredDuration": 86400 if feature_time == 1 else 172800 if feature_time == 2 else 259200 if feature_time == 3 else None}, "timestamp": int(time() * 1000) })) @community - def feature_wiki(self, time: int, wikiId: str, comId: Union[str, int] = None) -> ApiResponse: + def feature_wiki(self, feature_time: int, wikiId: str, comId: Union[str, int] = None) -> ApiResponse: """ Features a wiki in the current or specified community. - :param time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. - :type time: int + :param feature_time: The duration of the feature. 1 = 1 day, 2 = 2 days, 3 = 3 days. + :type feature_time: int :param wikiId: The ID of the wiki to feature. :type wikiId: str :param comId: The ID of the community to feature the wiki in. If not provided, the current community ID is used. @@ -5477,7 +5477,7 @@ def feature_wiki(self, time: int, wikiId: str, comId: Union[str, int] = None) -> To feature a wiki with ID "0000-0000-0000-0000" for 1 day in the current community: - >>> response = client.community.feature_wiki(time=1, wikiId="0000-0000-0000-0000") + >>> response = client.community.feature_wiki(feature_time=1, wikiId="0000-0000-0000-0000") ... if response.statuscode == 0: ... print("Wiki featured successfully!") ... else: @@ -5485,7 +5485,7 @@ def feature_wiki(self, time: int, wikiId: str, comId: Union[str, int] = None) -> To feature a wiki with ID "1111-1111-1111-1111" for 2 days in a community with ID "123": - >>> response = client.community.feature_wiki(time=2, wikiId="1111-1111-1111-1111", comId=123) + >>> response = client.community.feature_wiki(feature_time=2, wikiId="1111-1111-1111-1111", comId=123) ... if response.statuscode == 0: ... print("Wiki featured successfully!") ... else: @@ -5496,7 +5496,7 @@ def feature_wiki(self, time: int, wikiId: str, comId: Union[str, int] = None) -> url = f"/x{self.community_id if comId is None else comId}/s/item/{wikiId}/admin", data = { "adminOpName": 114, - "adminOpValue": {"featuredType": 2, "featuredDuration": 86400 if time == 1 else 172800 if time == 2 else 259200 if time == 3 else None}, + "adminOpValue": {"featuredType": 2, "featuredDuration": 86400 if feature_time == 1 else 172800 if feature_time == 2 else 259200 if feature_time == 3 else None}, "timestamp": int(time() * 1000) })) diff --git a/pymino/ext/dispatcher.py b/pymino/ext/dispatcher.py index f8704c65..c24606be 100644 --- a/pymino/ext/dispatcher.py +++ b/pymino/ext/dispatcher.py @@ -1,14 +1,4 @@ from typing import Callable -from threading import Thread -from contextlib import contextmanager - - -@contextmanager -def thread_executor(handler: Callable, message: dict): - thread = Thread(target=handler, args=(message,)) - thread.start() - yield - thread.join() class MessageDispatcher: """ @@ -39,8 +29,7 @@ def handle(self, message: dict): message_type = message.get("t") if message_type not in self.dispatch_table: return None - with thread_executor(self.dispatch_table[message_type], message): - pass + self.dispatch_table[message_type](message) class AsyncMessageDispatcher: diff --git a/pymino/ext/socket.py b/pymino/ext/socket.py index 3477a1d5..73301188 100644 --- a/pymino/ext/socket.py +++ b/pymino/ext/socket.py @@ -153,14 +153,15 @@ def _handle_message(self, message: dict) -> None: ) else self._communities.add(_message.ndcId) key = self.event_types.get(f"{_message.type}:{_message.mediaType}") - if key != None: - return self._handle_event(key, _message) + + return Thread(self._handle_event, args=(key, _message)) if key else None def _handle_notification(self, message: dict) -> None: """Handles notifications.""" notification: Notification = Notification(message) key = self.notif_types.get(notification.notification_type) - return self._handle_event(key, notification) if key else None + + return Thread(self._handle_event, args=(key, notification)) if key else None def _handle_agora_channel(self, message: dict) -> None: """Sets the agora channel.""" @@ -168,7 +169,7 @@ def _handle_agora_channel(self, message: dict) -> None: def _handle_user_online(self, message: dict) -> None: """Handles user online events.""" - return self._handle_event("user_online", OnlineMembers(message)) + return Thread(self._handle_event, args=("user_online", OnlineMembers(message))) def on_websocket_close(self, ws: WebSocket, close_status_code: int, close_msg: str) -> None: """Handles websocket close events.""" diff --git a/setup.cfg b/setup.cfg index 0c206301..90c3189c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pymino -version = 1.2.5.1 +version = 1.2.5.3 author = forevercynical author_email = me@cynical.gg description = Easily create a bot for Amino Apps using a modern easy to use synchronous library. @@ -19,7 +19,6 @@ classifiers = packages = find: install_requires = requests==2.28.2 - ujson==5.5.0 colorama==0.4.6 websocket-client==1.4.1 python_requires = >=3.8