Skip to content

Commit

Permalink
updated nerimity package - @SupertigerDev
Browse files Browse the repository at this point in the history
  • Loading branch information
Deutscher775 committed Dec 1, 2024
1 parent 730e3f7 commit f5326f6
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 85 deletions.
6 changes: 0 additions & 6 deletions src/Bot/nerimity/LICENSE.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/Bot/nerimity/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/Bot/nerimity/_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/Bot/nerimity/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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}"
Expand All @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions src/Bot/nerimity/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down
44 changes: 1 addition & 43 deletions src/Bot/nerimity/member.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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."""

Expand Down
6 changes: 1 addition & 5 deletions src/Bot/nerimity/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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}"
Expand All @@ -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))
Expand All @@ -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"])
Expand Down
6 changes: 2 additions & 4 deletions src/Bot/nerimity/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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))
Expand Down Expand Up @@ -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}"
Expand All @@ -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,
}
Expand Down

0 comments on commit f5326f6

Please sign in to comment.