From f5326f6d6b7f5ba425f2340c4040112028e751d1 Mon Sep 17 00:00:00 2001 From: Jason <81298350+Deutscher775@users.noreply.github.com> Date: Sun, 1 Dec 2024 18:48:33 +0100 Subject: [PATCH] updated nerimity package - @SupertigerDev --- src/Bot/nerimity/LICENSE.txt | 6 ----- src/Bot/nerimity/__init__.py | 2 +- src/Bot/nerimity/_enums.py | 14 ------------ src/Bot/nerimity/channel.py | 6 +---- src/Bot/nerimity/client.py | 9 ++------ src/Bot/nerimity/member.py | 44 +----------------------------------- src/Bot/nerimity/roles.py | 6 +---- src/Bot/nerimity/server.py | 6 ++--- 8 files changed, 8 insertions(+), 85 deletions(-) delete mode 100644 src/Bot/nerimity/LICENSE.txt diff --git a/src/Bot/nerimity/LICENSE.txt b/src/Bot/nerimity/LICENSE.txt deleted file mode 100644 index 259c013..0000000 --- a/src/Bot/nerimity/LICENSE.txt +++ /dev/null @@ -1,6 +0,0 @@ -Copyright 2023 "Fiiral" - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/Bot/nerimity/__init__.py b/src/Bot/nerimity/__init__.py index a8f18c3..d093b18 100644 --- a/src/Bot/nerimity/__init__.py +++ b/src/Bot/nerimity/__init__.py @@ -1,4 +1,4 @@ -from nerimity._enums import GlobalClientInformation, Colors, ChannelPermissions, RolePermissions, ChannelTypes, PresenceTypes, BadgeTypes, AttachmentTypes +from nerimity._enums import GlobalClientInformation, Colors, ChannelTypes, PresenceTypes, BadgeTypes, AttachmentTypes from nerimity.attachment import Attachment from nerimity.channel import Channel from nerimity.client import Client diff --git a/src/Bot/nerimity/_enums.py b/src/Bot/nerimity/_enums.py index b9e0035..9df5e73 100644 --- a/src/Bot/nerimity/_enums.py +++ b/src/Bot/nerimity/_enums.py @@ -20,20 +20,6 @@ class Colors(): CYAN = "\u001b[36m" WHITE = "\u001b[37m" -class ChannelPermissions(): - PRIVATE_CHANNEL = 1 - SEND_MESSAGES = 2 - JOIN_VOICE = 4 - -class RolePermissions(): - ADMINISTRATOR = 1 - SEND_MESSAGES = 2 - MANAGE_ROLES = 4 - MANAGE_CHANNELS = 8 - KICK_USER = 16 - BAN_USER = 32 - MENTION_EVERYONE = 64 - class ChannelTypes(): DM_TEXT = 0 SERVER_TEXT = 1 diff --git a/src/Bot/nerimity/channel.py b/src/Bot/nerimity/channel.py index b581fa3..de0bf2b 100644 --- a/src/Bot/nerimity/channel.py +++ b/src/Bot/nerimity/channel.py @@ -11,7 +11,6 @@ class Channel(): id: Snowflake ID of the channel name: Name of the channel. - permissions: Integer that represents the permissions of the channel. type: Type of the channel creator_id: ID of the creator of the channel. server_id: ID of the server the channel is in. @@ -30,7 +29,6 @@ class Channel(): def __init__(self) -> None: self.id : int = None self.name : str = None - self.permissions : int = None self.type : int = None self.creator_id : int = None self.server_id : int = None @@ -40,7 +38,7 @@ def __init__(self) -> None: self.order : int | None = None # Public: Updates itself with specified information. - def update_channel(self, server_id: int, permissions: int=None, name: str=None, icon: str=None, content: str=None) -> None: + def update_channel(self, server_id: int, name: str=None, icon: str=None, content: str=None) -> None: """Updates itself with specified information.""" api_endpoint = f"https://nerimity.com/api/servers/{server_id}/channels/{self.id}" @@ -50,7 +48,6 @@ def update_channel(self, server_id: int, permissions: int=None, name: str=None, "Content-Type": "application/json", } data = { - "permissions": permissions, "name": name, "icon": icon, } @@ -157,7 +154,6 @@ def deserialize(json: dict) -> 'Channel': new_channel = Channel() new_channel.id = int(json["id"]) new_channel.name = str(json["name"]) - new_channel.permissions = int(json["permissions"]) if json["permissions"] is not None else 0 new_channel.type = int(json["type"]) new_channel.creator_id = int(json["createdById"]) if json["createdById"] is not None else 0 new_channel.server_id = int(json["serverId"]) if json["serverId"] is not None else 0 diff --git a/src/Bot/nerimity/client.py b/src/Bot/nerimity/client.py index 5eae3c7..d7abd3f 100644 --- a/src/Bot/nerimity/client.py +++ b/src/Bot/nerimity/client.py @@ -1,5 +1,5 @@ from nerimity.message import Message -from nerimity._enums import GlobalClientInformation, ConsoleShortcuts, RolePermissions +from nerimity._enums import GlobalClientInformation, ConsoleShortcuts from nerimity.context import Context from nerimity.channel import Channel from nerimity.member import Member, ServerMember, ClientMember @@ -73,14 +73,13 @@ def __init__(self, token: str, prefix: str) -> None: GlobalClientInformation.TOKEN = token # Public: Decorator to register a prefixed command. - def command(self, name: str = None, aliases: list[str] = None, permissions: int = RolePermissions.SEND_MESSAGES) -> None: + def command(self, name: str = None, aliases: list[str] = None) -> None: """Decorator to register a prefixed command.""" def decorator(func): command_name = name if name is not None else func.__name__ self.commands[command_name] = func - func.permissions = permissions if aliases is not None: if not isinstance(aliases, list): @@ -156,10 +155,6 @@ async def _process_commands(self, message: Message) -> None: if command in self.commands: ctx = Context(message) - if ctx.author.has_permission(self.commands[command].permissions) == False: - print(f"{ConsoleShortcuts.ok()} {ctx.author.username}#{ctx.author.tag} attempted to run a command that required permissions they did not have.") - ctx.respond("You do not have the required permissions to execute this command.") - return arguments = message.content.split(' ')[1:] parsed_arguments = [] diff --git a/src/Bot/nerimity/member.py b/src/Bot/nerimity/member.py index e641ab3..f0bfaea 100644 --- a/src/Bot/nerimity/member.py +++ b/src/Bot/nerimity/member.py @@ -1,4 +1,4 @@ -from nerimity._enums import GlobalClientInformation, ConsoleShortcuts, RolePermissions +from nerimity._enums import GlobalClientInformation, ConsoleShortcuts from nerimity.roles import Role from nerimity.attachment import Attachment from nerimity.post import Post @@ -151,8 +151,6 @@ class ServerMember(Member): kick(): Kicks the user from the server. ban(soft_ban): Bans the user from the server, a softban does not remove all messages send in the last 7 hours. unban(): Unbans the user from the server. - has_permission(permission): Checks if the user has the specified Permissions. - has_exact_permission(permission): Checks if the user has exactly the specified Permissions. deserialize(json): static | overwrite | Deserialize a json string to a ServerMember object. """ @@ -162,47 +160,7 @@ def __init__(self) -> None: self.server_id : int = None self.joined_at : float = None self.role_ids : list[int] = None - - # Public: Checks if the user has the specified Permissions. - def has_permission(self, permission: int) -> bool: - """Checks if the user has the specified Permissions.""" - - # Check if the user is the owner - server_owner_id = GlobalClientInformation.SERVERS[f"{self.server_id}"].created_by_id - if server_owner_id == self.id: - return True - - # Combine role permissions using bitwise OR - user_permissions = 0 - for role_id in self.role_ids: - role = GlobalClientInformation.SERVERS[f"{self.server_id}"].roles[f"{role_id}"] - user_permissions |= role.permissions - - # Everyone role check - everyone_role_id = GlobalClientInformation.SERVERS[f"{self.server_id}"].default_role_id - everyone_role = GlobalClientInformation.SERVERS[f"{self.server_id}"].roles[f"{everyone_role_id}"] - user_permissions |= everyone_role.permissions - - if user_permissions & RolePermissions.ADMINISTRATOR: - return True - - # Check if role permissions and target permission match using AND - return (user_permissions & permission) != 0 - - # Public: Checks if the user has the specified Permissions. - def has_exact_permission(self, permission: int) -> bool: - """Checks if the user has exactly the specified Permissions.""" - - # Combine role permissions using bitwise OR - user_permissions = 0 - for role_id in self.role_ids: - role = GlobalClientInformation.SERVERS[f"{self.server_id}"].roles[f"{role_id}"] - user_permissions |= role.permissions - - # Check if role permissions and target permission match using AND - return (user_permissions & permission) == permission - # Public: Kicks the user from the server. def kick(self) -> None: """Kicks the user from the server.""" diff --git a/src/Bot/nerimity/roles.py b/src/Bot/nerimity/roles.py index c94c604..7c42794 100644 --- a/src/Bot/nerimity/roles.py +++ b/src/Bot/nerimity/roles.py @@ -9,7 +9,6 @@ class Role(): id: Snowflake ID of the role. name: The name of the role. - permissions: Integer that represents the permissions of the role. update_role(): Updates itself with the specified information. @@ -19,7 +18,6 @@ class Role(): def __init__(self) -> None: self.id : int = None self.name : str = None - self.permissions : int = None self.hex_color : str = None self.creator_id : int = None self.server_id : int = None @@ -29,7 +27,7 @@ def __init__(self) -> None: self.created_at : float = None # Public: Updates itself with the specified information. - def update_role(self, server_id: int, name: str=None, hex_color: str=None, hide_role: bool=None, permissions: int=None) -> None: + def update_role(self, server_id: int, name: str=None, hex_color: str=None, hide_role: bool=None) -> None: """Updates itself with the specified information.""" api_endpoint = f"https://nerimity.com/api/servers/{server_id}/roles/{self.id}" @@ -42,7 +40,6 @@ def update_role(self, server_id: int, name: str=None, hex_color: str=None, hide_ "name": name, "hexColor": hex_color, "hideRole": hide_role, - "permissions": permissions } response = requests.post(api_endpoint, headers=headers, data=json.dumps(data)) @@ -58,7 +55,6 @@ def deserialize(json: dict) -> 'Role': new_role = Role() new_role.id = int(json["id"]) new_role.name = str(json["name"]) - new_role.permissions = int(json["permissions"]) if json["permissions"] is not None else 0 new_role.hex_color = str(json["hexColor"]) new_role.creator_id = int(json["createdById"]) new_role.server_id = int(json["serverId"]) diff --git a/src/Bot/nerimity/server.py b/src/Bot/nerimity/server.py index 7a82215..f421e26 100644 --- a/src/Bot/nerimity/server.py +++ b/src/Bot/nerimity/server.py @@ -178,7 +178,7 @@ def delete_role(self, role_id: int) -> None: raise requests.RequestException # Public: Updates the specified role with new information. - def update_role(self, role_id: int, name: str=None, hex_color: str=None, hide_role: bool=None, permissions: int=None) -> None: + def update_role(self, role_id: int, name: str=None, hex_color: str=None, hide_role: bool=None) -> None: """Updates the specified role with new information.""" api_endpoint = f"https://nerimity.com/api/servers/{self.id}/roles/{role_id}" @@ -191,7 +191,6 @@ def update_role(self, role_id: int, name: str=None, hex_color: str=None, hide_ro "name": name, "hexColor": hex_color, "hideRole": hide_role, - "permissions": permissions } response = requests.post(api_endpoint, headers=headers, data=json.dumps(data)) @@ -238,7 +237,7 @@ def delete_channel(self, channel_id: int) -> None: raise requests.RequestException # Public: Updates the specified channel with new information. - def update_channel(self, channel_id: int, permissions: int=None, name: str=None, icon: str=None, content: str=None) -> None: + def update_channel(self, channel_id: int, name: str=None, icon: str=None, content: str=None) -> None: """Updates the specified channel with new information.""" api_endpoint = f"https://nerimity.com/api/servers/{self.id}/channels/{channel_id}" @@ -248,7 +247,6 @@ def update_channel(self, channel_id: int, permissions: int=None, name: str=None, "Content-Type": "application/json", } data = { - "permissions": permissions, "name": name, "icon": icon, }