diff --git a/pymino/__init__.py b/pymino/__init__.py index 56a6378f..f4b6f069 100644 --- a/pymino/__init__.py +++ b/pymino/__init__.py @@ -2,7 +2,7 @@ __author__ = 'cynical' __license__ = 'MIT' __copyright__ = 'Copyright 2023 Cynical' -__version__ = '1.2.1.6' +__version__ = '1.2.1.7' __description__ = 'A Python wrapper for the aminoapps.com API' from .bot import Bot as Bot diff --git a/pymino/ext/async_community.py b/pymino/ext/async_community.py index 39a54ecb..5b87b290 100644 --- a/pymino/ext/async_community.py +++ b/pymino/ext/async_community.py @@ -7278,7 +7278,8 @@ async def fetch_admin_log(self, fileId: str = None, pageToken: str = None, size: int = 25, - comId: Union[str, int] = None): + comId: Union[str, int] = None + ) -> AdminLogList: """ Fetches the admin log entries for the specified parameters. @@ -7313,51 +7314,129 @@ async def fetch_admin_log(self, ... print(entry.timestamp) """ if pageToken is None: - if userId: return await self.session.handler( + if userId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={userId}&objectType=0&pagingType=t&size={size}" - ) - elif blogId: return await self.session.handler( + )) + elif blogId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={blogId}&objectType=1&pagingType=t&size={size}" - ) - elif wikiId: return await self.session.handler( + )) + elif wikiId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={wikiId}&objectType=2&pagingType=t&size={size}" - ) - elif quizId: return await self.session.handler( + )) + elif quizId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={quizId}&objectType=1&pagingType=t&size={size}" - ) - elif fileId: return await self.session.handler( + )) + elif fileId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={fileId}&objectType=109&pagingType=t&size={size}" - ) - else: return await self.session.handler( + )) + else: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?pagingType=t&size={size}" - ) - elif userId: return await self.session.handler( + )) + elif userId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={userId}&objectType=0&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif blogId: return await self.session.handler( + )) + elif blogId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={blogId}&objectType=1&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif wikiId: return await self.session.hadler( + )) + elif wikiId: return AdminLogList(await self.session.hadler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={wikiId}&objectType=2&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif quizId: return await self.session.handler( + )) + elif quizId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={quizId}&objectType=1&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif fileId: return await self.session.handler( + )) + elif fileId: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={fileId}&objectType=109&pagingType=t&size={size}&pageToken={pageToken}" - ) - else: return await self.session.handler( + )) + else: return AdminLogList(await self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?pagingType=t&size={size}&pageToken={pageToken}" - ) \ No newline at end of file + )) + + + @community + async def fetch_user_moderation_history( + self, + userId: str, + pageToken: str = None, + size: int = 25, + comId: Union[str, int] = None + ) -> AdminLogList: + """ + Fetches the moderation history for the specified user. + + :param userId: The ID of the user to fetch the moderation history for. + :type userId: str + :param pageToken: The token for pagination. (Optional) + :type pageToken: str, optional + :param size: The number of log entries to fetch per page. (Default: 25) + :type size: int, optional + :param comId: The ID of the community to fetch the moderation history from. If not provided, the current community ID is used. + :type comId: Union[str, int], optional + :return: The moderation history for the specified user. + :rtype: response object + + This function fetches the moderation history for the specified user in the community. + + Note: The response object may vary based on the implementation. + + **Example usage:** + + >>> moderation_history = client.community.fetch_user_moderation_history("12345") + ... for entry in moderation_history: + ... print(entry.action) + ... print(entry.timestamp) + """ + return await self.fetch_admin_log(userId=userId, pageToken=pageToken, size=size, comId=comId) + + + @community + async def fetch_leader_log( + self, + userId: str, + size: int = 25, + pageToken: str = None, + comId: Union[str, int] = None + ) -> AdminLogList: + """ + Fetches the admin log entries for the specified parameters. + + :param userId: The ID of the user to filter the admin log by. + :type userId: str + :param size: The number of log entries to fetch per page. (Default: 25) + :type size: int, optional + :param pageToken: The token for pagination. (Optional) + :type pageToken: str, optional + :param comId: The ID of the community to fetch the admin log from. If not provided, the current community ID is used. + :type comId: Union[str, int], optional + :return: The admin log entries matching the specified parameters. + :rtype: response object + + This function fetches the admin log entries for the specified parameters in the community. + + Note: The response object may vary based on the implementation. + + **Example usage:** + + >>> admin_log = client.community.fetch_admin_log(userId=client.userId) + ... for penalty_type, ban_reason, userId in zip(adminLog.operation_name, adminLog.ext_data.note, adminLog.objectId): + ... print(f"{penalty_type} - {ban_reason} - {userId}") + """ + if pageToken: return AdminLogList(await self.session.handler( + method = "GET", + url = f"/x{comId or self.community_id}/s/admin/operation?size={size}&operatorUid={userId}&pageToken={pageToken}&pagingType=t" + )) + else: return AdminLogList(await self.session.handler( + method = "GET", + url = f"/x{comId or self.community_id}/s/admin/operation?size={size}&operatorUid={userId}&pagingType=t" + )) \ No newline at end of file diff --git a/pymino/ext/community.py b/pymino/ext/community.py index ddd68e7d..5a505132 100644 --- a/pymino/ext/community.py +++ b/pymino/ext/community.py @@ -7196,7 +7196,8 @@ def fetch_admin_log(self, fileId: str = None, pageToken: str = None, size: int = 25, - comId: Union[str, int] = None): + comId: Union[str, int] = None + ) -> AdminLogList: """ Fetches the admin log entries for the specified parameters. @@ -7231,51 +7232,129 @@ def fetch_admin_log(self, ... print(entry.timestamp) """ if pageToken is None: - if userId: return self.session.handler( + if userId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={userId}&objectType=0&pagingType=t&size={size}" - ) - elif blogId: return self.session.handler( + )) + elif blogId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={blogId}&objectType=1&pagingType=t&size={size}" - ) - elif wikiId: return self.session.handler( + )) + elif wikiId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={wikiId}&objectType=2&pagingType=t&size={size}" - ) - elif quizId: return self.session.handler( + )) + elif quizId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={quizId}&objectType=1&pagingType=t&size={size}" - ) - elif fileId: return self.session.handler( + )) + elif fileId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={fileId}&objectType=109&pagingType=t&size={size}" - ) - else: return self.session.handler( + )) + else: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?pagingType=t&size={size}" - ) - elif userId: return self.session.handler( + )) + elif userId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={userId}&objectType=0&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif blogId: return self.session.handler( + )) + elif blogId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={blogId}&objectType=1&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif wikiId: return self.session.hadler( + )) + elif wikiId: return AdminLogList(self.session.hadler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={wikiId}&objectType=2&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif quizId: return self.session.handler( + )) + elif quizId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={quizId}&objectType=1&pagingType=t&size={size}&pageToken={pageToken}" - ) - elif fileId: return self.session.handler( + )) + elif fileId: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?objectId={fileId}&objectType=109&pagingType=t&size={size}&pageToken={pageToken}" - ) - else: return self.session.handler( + )) + else: return AdminLogList(self.session.handler( method = "GET", url = f"/x{comId or self.community_id}/s/admin/operation?pagingType=t&size={size}&pageToken={pageToken}" - ) \ No newline at end of file + )) + + + @community + def fetch_user_moderation_history( + self, + userId: str, + pageToken: str = None, + size: int = 25, + comId: Union[str, int] = None + ) -> AdminLogList: + """ + Fetches the moderation history for the specified user. + + :param userId: The ID of the user to fetch the moderation history for. + :type userId: str + :param pageToken: The token for pagination. (Optional) + :type pageToken: str, optional + :param size: The number of log entries to fetch per page. (Default: 25) + :type size: int, optional + :param comId: The ID of the community to fetch the moderation history from. If not provided, the current community ID is used. + :type comId: Union[str, int], optional + :return: The moderation history for the specified user. + :rtype: response object + + This function fetches the moderation history for the specified user in the community. + + Note: The response object may vary based on the implementation. + + **Example usage:** + + >>> moderation_history = client.community.fetch_user_moderation_history("12345") + ... for entry in moderation_history: + ... print(entry.action) + ... print(entry.timestamp) + """ + return self.fetch_admin_log(userId=userId, pageToken=pageToken, size=size, comId=comId) + + + @community + def fetch_leader_log( + self, + userId: str, + size: int = 25, + pageToken: str = None, + comId: Union[str, int] = None + ) -> AdminLogList: + """ + Fetches the admin log entries for the specified parameters. + + :param userId: The ID of the user to filter the admin log by. + :type userId: str + :param size: The number of log entries to fetch per page. (Default: 25) + :type size: int, optional + :param pageToken: The token for pagination. (Optional) + :type pageToken: str, optional + :param comId: The ID of the community to fetch the admin log from. If not provided, the current community ID is used. + :type comId: Union[str, int], optional + :return: The admin log entries matching the specified parameters. + :rtype: response object + + This function fetches the admin log entries for the specified parameters in the community. + + Note: The response object may vary based on the implementation. + + **Example usage:** + + >>> admin_log = client.community.fetch_admin_log(userId=client.userId) + ... for penalty_type, ban_reason, userId in zip(adminLog.operation_name, adminLog.ext_data.note, adminLog.objectId): + ... print(f"{penalty_type} - {ban_reason} - {userId}") + """ + if pageToken: return AdminLogList(self.session.handler( + method = "GET", + url = f"/x{comId or self.community_id}/s/admin/operation?size={size}&operatorUid={userId}&pageToken={pageToken}&pagingType=t" + )) + else: return AdminLogList(self.session.handler( + method = "GET", + url = f"/x{comId or self.community_id}/s/admin/operation?size={size}&operatorUid={userId}&pagingType=t" + )) \ No newline at end of file diff --git a/pymino/ext/entities/__init__.py b/pymino/ext/entities/__init__.py index 634a5c90..7de5a160 100644 --- a/pymino/ext/entities/__init__.py +++ b/pymino/ext/entities/__init__.py @@ -13,4 +13,5 @@ from .acm import * from .member import * from .bubble import * -from .sticker import * \ No newline at end of file +from .sticker import * +from .admin_log import * \ No newline at end of file diff --git a/pymino/ext/entities/admin_log.py b/pymino/ext/entities/admin_log.py new file mode 100644 index 00000000..48d97f1d --- /dev/null +++ b/pymino/ext/entities/admin_log.py @@ -0,0 +1,294 @@ +from typing import List + + +class ExtData: + def __init__(self, data: dict) -> None: + try: + self.data = data + except AttributeError: + self.data = None + + def _check_ext_data(F): + def wrapper(*args, **kwargs): + return None if args[0].data is None else F(*args, **kwargs) + return wrapper + + @property + @_check_ext_data + def value(self) -> dict: + """Returns the value of the ext data""" + return self.data.get("value") + + @property + @_check_ext_data + def note(self) -> int: + """Returns the note the moderator/admin left on the request""" + return self.data.get("note") + + def json(self) -> dict: + """Returns the raw json data""" + return self.data + + +class ExtDataList: + def __init__(self, data: list) -> None: + try: + self.data = data + except AttributeError: + self.data = None + + def _check_ext_data_list(F): + def wrapper(*args, **kwargs): + return None if args[0].data is None else F(*args, **kwargs) + return wrapper + + @property + @_check_ext_data_list + def value(self) -> List[dict]: + """Returns a list of values of the ext data""" + return [data.get("value") if data is not None else None for data in self.data] + + @property + @_check_ext_data_list + def note(self) -> List[str]: + """Returns a list of notes the moderator/admin left on the request""" + return [str(note.get("note")) if note is not None else None for note in self.data] + + def json(self) -> List[dict]: + """Returns the raw json data""" + return self.data + + +class AdminLog: + def __init__(self, data: dict) -> None: + try: + self.data = data + except AttributeError: + self.data = None + + def _check_admin_log(F): + def wrapper(*args, **kwargs): + return None if args[0].data is None else F(*args, **kwargs) + return wrapper + + @property + @_check_admin_log + def operation_name(self) -> str: + """Returns the name of the operation""" + return self.data.get("operationName") + + @property + @_check_admin_log + def comId(self) -> int: + """Returns the comId of the community the operation was performed on""" + return self.data.get("comId") + + @property + @_check_admin_log + def refer_ticket_id(self) -> int: + """Returns the ticket id of the operation""" + return self.data.get("referTicketId") + + @property + @_check_admin_log + def object_url(self) -> str: + """Returns the url of the object the operation was performed on""" + return self.data.get("objectUrl") + + @property + @_check_admin_log + def created_time(self) -> str: + """Returns the time the operation was performed""" + return self.data.get("createdTime") + + @property + @_check_admin_log + def ext_data(self) -> ExtData: + """Returns the ext data of the operation""" + return ExtData(self.data.get("extData")) + + @property + @_check_admin_log + def operation_level(self) -> int: + """Returns the level of the operation""" + return self.data.get("operationLevel") + + @property + @_check_admin_log + def operation_id(self) -> int: + """Returns the id of the operation""" + return self.data.get("operation") + + @property + @_check_admin_log + def object_type(self) -> int: + """Returns the type of the object the operation was performed on""" + return self.data.get("objectType") + + @property + @_check_admin_log + def operation_details(self) -> str: + """Returns the details of the operation""" + return self.data.get("operationDetail") + + @property + @_check_admin_log + def log_id(self) -> int: + """Returns the log id of the operation""" + return self.data.get("logId") + + @property + @_check_admin_log + def moderation_level(self) -> int: + """Returns the moderation level of the operation""" + return self.data.get("moderationLevel") + + @property + @_check_admin_log + def objectId(self) -> int: + """Returns the object id of the operation""" + return self.data.get("objectId") + + @property + @_check_admin_log + def moderator(self) -> dict: + """Returns the moderator of the operation""" + return self.data.get("author") + + @property + @_check_admin_log + def moderator_username(self) -> str: + """Returns the username of the moderator of the operation""" + return None if self.moderator is None else self.moderator.get("nickname") + + @property + @_check_admin_log + def moderator_uid(self) -> str: + """Returns the uid of the moderator of the operation""" + return None if self.moderator is None else self.moderator.get("uid") + + @property + @_check_admin_log + def moderator_icon(self) -> str: + """Returns the icon of the moderator of the operation""" + return None if self.moderator is None else self.moderator.get("icon") + + def json(self) -> dict: + """Returns the raw json data""" + return self.data + + +class AdminLogList: + def __init__(self, data: dict) -> None: + try: + self.data = data + except AttributeError: + self.data = None + + def parser(self) -> List[AdminLog]: + """Returns a list of AdminLog objects""" + return [AdminLog(i) for i in self.data.get("adminLogList")] + + @property + def paging(self) -> dict: + """Returns the paging data""" + return self.data.get("paging") + + @property + def next_page_token(self) -> int: + """Returns the next page token""" + return self.paging.get("nextPageToken") + + @property + def prev_page_token(self) -> int: + """Returns the previous page token""" + return self.paging.get("prevPageToken") + + @property + def operation_name(self) -> List[str]: + """Returns a list of operation names""" + return [i.operation_name for i in self.parser()] + + @property + def comId(self) -> List[int]: + """Returns a list of comIds""" + return [i.comId for i in self.parser()] + + @property + def refer_ticket_id(self) -> List[int]: + """Returns a list of ticket ids""" + return [i.refer_ticket_id for i in self.parser()] + + @property + def object_url(self) -> List[str]: + """Returns a list of object urls""" + return [i.object_url for i in self.parser()] + + @property + def created_time(self) -> List[str]: + """Returns a list of created times""" + return [i.created_time for i in self.parser()] + + @property + def ext_data(self) -> ExtDataList: + """Returns a list of ExtData objects""" + return ExtDataList([i.ext_data.json() for i in self.parser()]) + + @property + def operation_level(self) -> List[int]: + """Returns a list of operation levels""" + return [i.operation_level for i in self.parser()] + + @property + def operation_id(self) -> List[int]: + """Returns a list of operation ids""" + return [i.operation_id for i in self.parser()] + + @property + def object_type(self) -> List[int]: + """Returns a list of object types""" + return [i.object_type for i in self.parser()] + + @property + def operation_details(self) -> List[str]: + """Returns a list of operation details""" + return [i.operation_details for i in self.parser()] + + @property + def log_id(self) -> List[int]: + """Returns a list of log ids""" + return [i.log_id for i in self.parser()] + + @property + def moderation_level(self) -> List[int]: + """Returns a list of moderation levels""" + return [i.moderation_level for i in self.parser()] + + @property + def objectId(self) -> List[int]: + """Returns a list of object ids""" + return [i.objectId for i in self.parser()] + + @property + def moderator(self) -> List[dict]: + """Returns a list of moderators""" + return [i.moderator for i in self.parser()] + + @property + def moderator_username(self) -> List[str]: + """Returns a list of moderator usernames""" + return [i.moderator_username for i in self.parser()] + + @property + def moderator_uid(self) -> List[str]: + """Returns a list of moderator uids""" + return [i.moderator_uid for i in self.parser()] + + @property + def moderator_icon(self) -> str: + """Returns a list of moderator icons""" + return [i.moderator_icon for i in self.parser()] + + def json(self) -> dict: + """Returns the raw json data""" + return self.data \ No newline at end of file