diff --git a/werewolf/game.py b/werewolf/game.py index 217bf5c..4ab529f 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -28,7 +28,7 @@ class Game: def __init__(self, guild: discord.Guild, role: discord.Role=None, category: discord.CategoryChannel=None, village: discord.TextChannel=None, - game_code=None): + log_channel: discord.TextChannel=None, game_code=None): self.guild = guild self.game_code = game_code self.game_role = role @@ -50,6 +50,7 @@ class Game: self.channel_category = category # discord.CategoryChannel self.village_channel = village # discord.TextChannel + self.log_channel = log_channel self.p_channels = {} # uses default_secret_channel self.vote_groups = {} # ID : VoteGroup() @@ -58,20 +59,20 @@ class Game: self.loop = asyncio.get_event_loop() - def __del__(self): - """ - Cleanup channels as necessary - :return: - """ - - print("Delete is called") - - self.game_over = True - if self.village_channel: - asyncio.ensure_future(self.village_channel.delete("Werewolf game-over")) - - for c_data in self.p_channels.values(): - asyncio.ensure_future(c_data["channel"].delete("Werewolf game-over")) + # def __del__(self): + # """ + # Cleanup channels as necessary + # :return: + # """ + # + # print("Delete is called") + # + # self.game_over = True + # if self.village_channel: + # asyncio.ensure_future(self.village_channel.delete("Werewolf game-over")) + # + # for c_data in self.p_channels.values(): + # asyncio.ensure_future(c_data["channel"].delete("Werewolf game-over")) async def setup(self, ctx: RedContext): """ @@ -115,16 +116,17 @@ class Game: self.game_role: discord.PermissionOverwrite(read_messages=True, send_messages=True) } if self.channel_category is None: - self.channel_category = await self.guild.create_category("ww-game", + self.channel_category = await self.guild.create_category("🔴 Werewolf Game (ACTIVE)", overwrites=overwrite, reason="(BOT) New game of werewolf") else: + await self.channel_category.edit(name="🔴 Werewolf Game (ACTIVE)", reason="(BOT) New game of werewolf") for target, ow in overwrite.items(): await self.channel_category.set_permissions(target=target, overwrite=ow, reason="(BOT) New game of werewolf") if self.village_channel is None: - self.village_channel = await self.guild.create_text_channel("Village Square", + self.village_channel = await self.guild.create_text_channel("village-square", overwrites=overwrite, reason="(BOT) New game of werewolf", category=self.channel_category) @@ -744,4 +746,5 @@ class Game: reason = '(BOT) End of WW game' await self.village_channel.set_permissions(self.game_role, overwrite=None, reason=reason) await self.channel_category.set_permissions(self.game_role, overwrite=None, reason=reason) - await self.channel_category.edit(reason=reason, name="Archived Game") + await self.channel_category.edit(reason=reason, name="Werewolf Game (INACTIVE)") + # Optional dynamic channels/categories diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index 89420d9..ebd15e9 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -7,7 +7,6 @@ from redbot.core.bot import Red from werewolf.builder import GameBuilder from werewolf.game import Game - class Werewolf: """ Base to host werewolf on a guild @@ -87,7 +86,7 @@ class Werewolf: @commands.guild_only() @wwset.command(name="logchannel") - async def wwset_channel(self, ctx: RedContext, channel: discord.TextChannel): + async def wwset_log_channel(self, ctx: RedContext, channel: discord.TextChannel): """ Assign the log channel """ @@ -237,7 +236,6 @@ class Werewolf: if ctx.guild is not None: await ctx.send("This action is only available in DM's") return - # DM nonsense, find their game # If multiple games, panic for game in self.games.values(): @@ -250,38 +248,48 @@ class Werewolf: await game.choose(ctx, data) async def _get_game(self, ctx: RedContext, game_code=None): - if ctx.guild is None: + guild: discord.Guild = ctx.guild + + if guild is None: # Private message, can't get guild await ctx.send("Cannot start game from PM!") return None - if ctx.guild.id not in self.games or self.games[ctx.guild.id].game_over: + if guild.id not in self.games or self.games[guild.id].game_over: await ctx.send("Starting a new game...") role = None category = None channel = None log_channel = None - role_id = await self.config.guild(ctx.guild).role_id() - category_id = await self.config.guild(ctx.guild).category_id() - channel_id = await self.config.guild(ctx.guild).channel_id() - log_channel_id = await self.config.guild(ctx.guild).log_channel_id() + role_id = await self.config.guild(guild).role_id() + category_id = await self.config.guild(guild).category_id() + channel_id = await self.config.guild(guild).channel_id() + log_channel_id = await self.config.guild(guild).log_channel_id() if role_id is not None: - role = discord.utils.get(ctx.guild.roles, id=role_id) + role = discord.utils.get(guild.roles, id=role_id) if role is None: - await ctx.send("Game role is invalid, cannot start new game") + await ctx.send("Game Role is invalid, cannot start new game") return None if category_id is not None: - category = discord.utils.get(ctx.guild.categories, id=category_id) - if role is None: - await ctx.send("Game role is invalid, cannot start new game") + category = discord.utils.get(guild.categories, id=category_id) + if category is None: + await ctx.send("Game Category is invalid, cannot start new game") + return None + if channel_id is not None: + channel = discord.utils.get(guild.text_channels, id=channel_id) + if channel is None: + await ctx.send("Village Channel is invalid, cannot start new game") + return None + if log_channel_id is not None: + log_channel = discord.utils.get(guild.text_channels, id=log_channel_id) + if log_channel is None: + await ctx.send("Log Channel is invalid, cannot start new game") return None + self.games[guild.id] = Game(guild, role, category, channel, log_channel, game_code) - - self.games[ctx.guild.id] = Game(ctx.guild, role, game_code) - - return self.games[ctx.guild.id] + return self.games[guild.id] async def _game_start(self, game): await game.start()