|
6 | 6 | from loguru import logger |
7 | 7 |
|
8 | 8 | from tux.core.base_cog import BaseCog |
9 | | -from tux.shared.config.settings import CONFIG |
| 9 | +from tux.shared.config import CONFIG |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class StatusRoles(BaseCog): |
13 | 13 | """Assign roles to users based on their status.""" |
14 | 14 |
|
15 | 15 | def __init__(self, bot: commands.Bot): |
16 | 16 | self.bot = bot |
17 | | - self.status_roles = CONFIG.STATUS_ROLES |
18 | 17 | self._unload_task = None # Store task reference here |
19 | 18 |
|
20 | | - # Check if config exists and is valid |
21 | | - if not self.status_roles: |
22 | | - logger.warning("No status roles configurations found. Unloading StatusRoles cog.") |
| 19 | + # Check if mappings exist and are valid |
| 20 | + if not CONFIG.STATUS_ROLES.MAPPINGS: |
| 21 | + logger.warning("No status role mappings found. Unloading StatusRoles cog.") |
23 | 22 | # Store the task reference |
24 | 23 | self._unload_task = asyncio.create_task(self._unload_self()) |
25 | 24 | else: |
26 | | - logger.info(f"StatusRoles cog initialized with {len(self.status_roles)} role configurations") |
| 25 | + logger.info(f"StatusRoles cog initialized with {len(CONFIG.STATUS_ROLES.MAPPINGS)} mappings") |
27 | 26 |
|
28 | 27 | async def _unload_self(self): |
29 | 28 | """Unload this cog if configuration is missing.""" |
@@ -86,17 +85,17 @@ async def check_and_update_roles(self, member: discord.Member): |
86 | 85 | if status_text is None: |
87 | 86 | status_text = "" # Use empty string for regex matching if no status |
88 | 87 |
|
89 | | - for config in self.status_roles: |
90 | | - # Skip if the config is for a different server |
91 | | - if int(config.get("server_id", 0)) != member.guild.id: |
| 88 | + for mapping in CONFIG.STATUS_ROLES.MAPPINGS: |
| 89 | + # Skip if the mapping is for a different server |
| 90 | + if int(mapping.get("server_id", 0)) != member.guild.id: |
92 | 91 | continue |
93 | 92 |
|
94 | | - role_id = int(config.get("role_id", 0)) |
95 | | - pattern = str(config.get("status_regex", ".*")) |
| 93 | + role_id = int(mapping.get("role_id", 0)) |
| 94 | + pattern = str(mapping.get("status_regex", ".*")) |
96 | 95 |
|
97 | 96 | role = member.guild.get_role(role_id) |
98 | 97 | if not role: |
99 | | - logger.warning(f"Role {role_id} configured in STATUS_ROLES not found in guild {member.guild.name}") |
| 98 | + logger.warning(f"Role {role_id} configured in status roles not found in guild {member.guild.name}") |
100 | 99 | continue |
101 | 100 |
|
102 | 101 | try: |
|
0 commit comments