Merge remote-tracking branch 'origin/rewrite' into pillow

This commit is contained in:
2023-09-24 11:37:55 +03:00
4 changed files with 39 additions and 18 deletions

View File

@@ -622,7 +622,7 @@ class RankCog(LionCog):
error = t(_p(
'rank_refresh|error:unassignable_roles|desc',
"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)
return
@@ -707,8 +707,8 @@ class RankCog(LionCog):
'rank_refresh|remove_roles|small_error',
"*Could not remove ranks from {member}*"
)).format(member=to_remove[index][0].mention)
self.ui.errors.append(error)
if len(self.ui.errors) > 10:
ui.errors.append(error)
if len(ui.errors) > 10:
await ui.set_error(
t(_p(
'rank_refresh|remove_roles|error:too_many_issues',
@@ -742,8 +742,8 @@ class RankCog(LionCog):
'rank_refresh|add_roles|small_error',
"*Could not add {role} to {member}*"
)).format(member=to_add[index][0].mention, role=to_add[index][1].mention)
self.ui.errors.append(error)
if len(self.ui.errors) > 10:
ui.errors.append(error)
if len(ui.errors) > 10:
await ui.set_error(
t(_p(
'rank_refresh|add_roles|error:too_many_issues',

View File

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