Correction des multiples bugs
This commit is contained in:
parent
5fe70d754b
commit
07198c20b7
15 changed files with 707 additions and 348 deletions
|
|
@ -7,16 +7,15 @@ import discord
|
|||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..data.models import GuildTicketConfig
|
||||
from ..data.models import GuildTicketConfig, TicketCategory
|
||||
|
||||
def is_staff(interaction: discord.Interaction, config: 'GuildTicketConfig') -> bool:
|
||||
def is_staff(interaction: discord.Interaction, config: 'GuildTicketConfig', category: Optional['TicketCategory'] = None) -> bool:
|
||||
"""
|
||||
Check if the user has staff permissions.
|
||||
|
||||
Checks:
|
||||
1. Administrator permission
|
||||
2. Staff roles
|
||||
3. Staff users (specific user IDs)
|
||||
If a category is provided and has specific staff_roles defined,
|
||||
only those roles (and admins) are considered staff for this check.
|
||||
Otherwise, global staff roles from the config are used.
|
||||
"""
|
||||
# Get user and permissions based on object type
|
||||
user = getattr(interaction, "author", getattr(interaction, "user", None))
|
||||
|
|
@ -26,16 +25,29 @@ def is_staff(interaction: discord.Interaction, config: 'GuildTicketConfig') -> b
|
|||
if user.guild_permissions.administrator:
|
||||
return True
|
||||
|
||||
|
||||
# Check specific users
|
||||
# Check specific users (always allowed)
|
||||
if user.id in config.staff_users:
|
||||
return True
|
||||
|
||||
# Check roles
|
||||
# If category has specific roles, only those are allowed
|
||||
if category and category.staff_roles:
|
||||
for role_id in category.staff_roles:
|
||||
try:
|
||||
role = interaction.guild.get_role(int(role_id))
|
||||
if role and role in user.roles:
|
||||
return True
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
return False
|
||||
|
||||
# Check global roles
|
||||
for role_id in config.staff_roles:
|
||||
role = interaction.guild.get_role(int(role_id))
|
||||
if role and role in user.roles:
|
||||
return True
|
||||
try:
|
||||
role = interaction.guild.get_role(int(role_id))
|
||||
if role and role in user.roles:
|
||||
return True
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue