fix shutdown

This commit is contained in:
Nexus 2023-02-23 14:12:59 +00:00
parent aecde04c39
commit c6c0cd3b75
Signed by: nex
GPG key ID: 0FA334385D0B689F
2 changed files with 10 additions and 10 deletions

View file

@ -187,32 +187,32 @@ class TimeTableCog(commands.Cog):
async def update_status(self): async def update_status(self):
if config.dev: if config.dev:
return return
console.log("[TimeTable Updater Task] Running!") # console.log("[Timetable Updater Task] Running!")
if not self.bot.is_ready(): if not self.bot.is_ready():
console.log("[TimeTable Updater Task] Bot is not ready, waiting until ready.") # console.log("[Timetable Updater Task] Bot is not ready, waiting until ready.")
await self.bot.wait_until_ready() await self.bot.wait_until_ready()
guild: discord.Guild = self.bot.get_guild(994710566612500550) guild: discord.Guild = self.bot.get_guild(994710566612500550)
console.log("[TimeTable Updater Task] Fetched source server.") # console.log("[Timetable Updater Task] Fetched source server.")
channel = discord.utils.get(guild.text_channels, name="timetable") channel = discord.utils.get(guild.text_channels, name="timetable")
channel = channel or discord.utils.get(guild.text_channels, name="general") channel = channel or discord.utils.get(guild.text_channels, name="general")
if not channel: if not channel:
console.log("[TimeTable Updater Task] No channel to update in!!", file=sys.stderr) # console.log("[Timetable Updater Task] No channel to update in!!", file=sys.stderr)
return return
channel: discord.TextChannel channel: discord.TextChannel
console.log("[TimeTable Updater Task] Updating in channel %r." % channel.name) # console.log("[Timetable Updater Task] Updating in channel %r." % channel.name)
async for _message in channel.history(limit=20, oldest_first=False): async for _message in channel.history(limit=20, oldest_first=False):
if _message.author == self.bot.user and _message.content.startswith("[tt]"): if _message.author == self.bot.user and _message.content.startswith("[tt]"):
message = _message message = _message
break break
else: else:
console.log(f"[TimeTable Updater Task] Sending new message in {channel.name!r}.") # console.log(f"[TimeTable Updater Task] Sending new message in {channel.name!r}.")
message = await channel.send("[tt] (loading)") message = await channel.send("[tt] (loading)")
message: discord.Message message: discord.Message
console.log(f"[TimeTable Updater Task] Updating message: {channel.id}/{message.id}") # console.log(f"[TimeTable Updater Task] Updating message: {channel.id}/{message.id}")
r = await self.update_timetable_message(message) await self.update_timetable_message(message)
console.log("[TimeTable Updater Task] Done! (exit result %r)" % r) # console.log("[Timetable Updater Task] Done! (exit result %r)" % r)
@commands.slash_command() @commands.slash_command()
async def lesson(self, ctx: discord.ApplicationContext, *, date: str = None): async def lesson(self, ctx: discord.ApplicationContext, *, date: str = None):

View file

@ -65,7 +65,7 @@ class Bot(commands.Bot):
del self.web["task"] del self.web["task"]
del self.web del self.web
try: try:
await asyncio.wait_for(asyncio.create_task(super().close()), timeout=10) await super().close()
except asyncio.TimeoutError: except asyncio.TimeoutError:
self.console.log("Timed out while closing, forcing shutdown.") self.console.log("Timed out while closing, forcing shutdown.")
sys.exit(1) sys.exit(1)