mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
fix shutdown
This commit is contained in:
parent
aecde04c39
commit
c6c0cd3b75
2 changed files with 10 additions and 10 deletions
|
@ -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):
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue