Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivixer committed Mar 5, 2024
2 parents 05fe059 + 00f9478 commit f3da67a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 4 additions & 2 deletions sggwbot/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,9 @@ async def _remove(

event = self._model.get_event_with_index(index)
self._model.remove_event_from_json(event)
await self._ctrl.update_embed()

if not event.is_hidden:
await self._ctrl.update_embed()

# We edit the original message here
# instead of in the `with_info` decorator,
Expand Down Expand Up @@ -453,7 +455,7 @@ async def _remove_expired_events_task(self) -> None:
await self._bot.wait_until_ready()
while True:
removed_events = self._model.remove_expired_events()
if removed_events:
if any(map(lambda i: not i.is_hidden, removed_events)):
await self._ctrl.update_embed()
await wait_until_midnight()

Expand Down
2 changes: 1 addition & 1 deletion sggwbot/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def to_embed(self) -> Embed:
"First name": self.first_name,
"Last name": self.last_name,
"Student ID": self.index,
"Non-student reason": self.other_account_reason,
"Non-student reason": self.non_student_reason,
"Another account reason": self.other_account_reason,
}

Expand Down
30 changes: 26 additions & 4 deletions sggwbot/role_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, bot: SGGWBot) -> None:
"""Initialize the cog."""

self._bot = bot
self._load_controllers.start() # pylint: disable=no-member
self._load_controllers_task.start() # pylint: disable=no-member

@staticmethod
def _validate_identifier(func: _FUNC) -> _FUNC:
Expand Down Expand Up @@ -304,23 +304,45 @@ async def change_role():
except nextcord.DiscordException:
return

@_role_assignment.subcommand(
name="reload_controllers",
description="Reload the role_assignment controllers.",
)
@InteractionUtils.with_log()
@InteractionUtils.with_info(
before="Reloading role_assignment controllers...",
after="The role_assignment controllers have been reloaded.",
)
async def _reload_controllers(self, _: Interaction) -> None:
"""Reloads the role_assignment controllers.
Parameters
----------
interaction: :class:`Interaction`
The interaction that triggered the command.
"""
self._controllers = await self._load_controllers()

@tasks.loop(count=1)
async def _load_controllers(self):
async def _load_controllers_task(self):
await self._bot.wait_until_ready()
self._controllers = await self._load_controllers()

self._controllers = {}
async def _load_controllers(self) -> dict[str, RoleAssignmentController]:
controllers = {}
for path in RoleAssignmentModel.get_settings_directory().iterdir():
identifier = path.stem
model = RoleAssignmentModel(identifier)
embed_model = RoleAssignmentEmbedModel(model, self._bot)
self._controllers[identifier] = RoleAssignmentController(model, embed_model)
controllers[identifier] = RoleAssignmentController(model, embed_model)
Console.specific(
f"'{identifier}' controller has been loaded.",
"RoleAssignment",
FontColour.GREEN,
bold_type=True,
bold_text=True,
)
return controllers


# pylint: disable=no-member
Expand Down

0 comments on commit f3da67a

Please sign in to comment.