Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files cleanup on shutdown #100

Merged
merged 2 commits into from
Jan 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dnd-bot/dnd_bot/dc/cogs/command_shutdown.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from nextcord import slash_command
from nextcord.ext.commands import Cog, Bot

Expand All @@ -24,10 +26,18 @@ async def shutdown(self, interaction):
# stop all running game threads
for game in Multiverse.games.values():
game.game_state = "INACTIVE"
game.get_active_player().active = False
if game.get_active_player():
game.get_active_player().active = False
if game.game_loop_thread:
game.game_loop_thread.join()

# delete unusable images
print("\nDeleting old images...")
tmp_img_path = 'dnd_bot/assets/tmp/game_images'
for filename in os.listdir(tmp_img_path):
if filename.startswith('pov'):
os.remove('%s/%s' % (tmp_img_path, filename))

await self.bot.close()
else:
await interaction.response.send_message("You have no permission to shutdown me :man_gesturing_no:!")
Expand Down