fix(ranks): Fix typos in refresh.

This commit is contained in:
2023-09-24 09:22:50 +03:00
parent 5675f72853
commit fe0d120907
2 changed files with 13 additions and 7 deletions

View File

@@ -622,7 +622,7 @@ class RankCog(LionCog):
error = t(_p( error = t(_p(
'rank_refresh|error:unassignable_roles|desc', 'rank_refresh|error:unassignable_roles|desc',
"I have insufficient permissions to assign the following role(s):\n{roles}" "I have insufficient permissions to assign the following role(s):\n{roles}"
)).format(roles='\n'.join(role.mention for role in failing)), )).format(roles='\n'.join(role.mention for role in failing))
await ui.set_error(error) await ui.set_error(error)
return return
@@ -707,8 +707,8 @@ class RankCog(LionCog):
'rank_refresh|remove_roles|small_error', 'rank_refresh|remove_roles|small_error',
"*Could not remove ranks from {member}*" "*Could not remove ranks from {member}*"
)).format(member=to_remove[index][0].mention) )).format(member=to_remove[index][0].mention)
self.ui.errors.append(error) ui.errors.append(error)
if len(self.ui.errors) > 10: if len(ui.errors) > 10:
await ui.set_error( await ui.set_error(
t(_p( t(_p(
'rank_refresh|remove_roles|error:too_many_issues', 'rank_refresh|remove_roles|error:too_many_issues',
@@ -742,8 +742,8 @@ class RankCog(LionCog):
'rank_refresh|add_roles|small_error', 'rank_refresh|add_roles|small_error',
"*Could not add {role} to {member}*" "*Could not add {role} to {member}*"
)).format(member=to_add[index][0].mention, role=to_add[index][1].mention) )).format(member=to_add[index][0].mention, role=to_add[index][1].mention)
self.ui.errors.append(error) ui.errors.append(error)
if len(self.ui.errors) > 10: if len(ui.errors) > 10:
await ui.set_error( await ui.set_error(
t(_p( t(_p(
'rank_refresh|add_roles|error:too_many_issues', 'rank_refresh|add_roles|error:too_many_issues',

View File

@@ -24,6 +24,9 @@ _p = babel._p
class RankRefreshUI(MessageUI): class RankRefreshUI(MessageUI):
# Cache of live rank UIs, mainly for introspection
_running = set()
def __init__(self, bot: LionBot, guild: discord.Guild, **kwargs): def __init__(self, bot: LionBot, guild: discord.Guild, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.bot = bot self.bot = bot
@@ -66,6 +69,7 @@ class RankRefreshUI(MessageUI):
def start(self): def start(self):
self._loop_task = asyncio.create_task(self._refresh_loop(), name='Rank RefreshUI Monitor') self._loop_task = asyncio.create_task(self._refresh_loop(), name='Rank RefreshUI Monitor')
self._running.add(self)
async def run(self, *args, **kwargs): async def run(self, *args, **kwargs):
await super().run(*args, **kwargs) await super().run(*args, **kwargs)
@@ -74,6 +78,7 @@ class RankRefreshUI(MessageUI):
async def cleanup(self): async def cleanup(self):
if self._loop_task and not self._loop_task.done(): if self._loop_task and not self._loop_task.done():
self._loop_task.cancel() self._loop_task.cancel()
self._running.discard(self)
await super().cleanup() await super().cleanup()
def progress_bar(self, value, minimum, maximum, width=10) -> str: def progress_bar(self, value, minimum, maximum, width=10) -> str:
@@ -107,12 +112,13 @@ class RankRefreshUI(MessageUI):
# Join all the sections together and return # Join all the sections together and return
return ''.join(bar) return ''.join(bar)
@log_wrap('refresh ui loop') @log_wrap(action='refresh ui loop')
async def _refresh_loop(self): async def _refresh_loop(self):
while True: while True:
try: try:
await asyncio.sleep(1) await asyncio.sleep(5)
await self._wakeup.wait() await self._wakeup.wait()
self._wakeup.clear()
await self.refresh() await self.refresh()
except asyncio.CancelledError: except asyncio.CancelledError:
break break