Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
wittiness authored Sep 4, 2023
1 parent 7899fce commit b5ac328
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 44 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pymino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions pymino/ext/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -5327,15 +5327,15 @@ 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:
... print("Failed to feature user.")
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:
Expand All @@ -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.
Expand All @@ -5377,15 +5377,15 @@ 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:
... print("Failed to feature chat.")
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:
Expand All @@ -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.
Expand All @@ -5427,15 +5427,15 @@ 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:
... print("Failed to feature blog.")
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:
Expand All @@ -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.
Expand All @@ -5477,15 +5477,15 @@ 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:
... print("Failed to feature wiki.")
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:
Expand All @@ -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)
}))

Expand Down
13 changes: 1 addition & 12 deletions pymino/ext/dispatcher.py
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions pymino/ext/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,23 @@ 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."""
self.channel: Channel = Channel(message)

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."""
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down

0 comments on commit b5ac328

Please sign in to comment.