small fixes + correct checks
This commit is contained in:
		
							parent
							
								
									e2b8a20fa6
								
							
						
					
					
						commit
						14037bf5d8
					
				|  | @ -13,7 +13,7 @@ class Developer(commands.Cog): | ||||||
| 		await self.bot.change_presence(status=discord.Status.online, activity=discord.Game('One Night Ultimate Werewolf')) | 		await self.bot.change_presence(status=discord.Status.online, activity=discord.Game('One Night Ultimate Werewolf')) | ||||||
| 		print('We have logged in as {0.user}'.format(self.bot)) | 		print('We have logged in as {0.user}'.format(self.bot)) | ||||||
| 
 | 
 | ||||||
| 	async def is_dev(ctx): | 	async def is_dev(self, ctx): | ||||||
| 		if ctx.author.id == 461892912821698562: | 		if ctx.author.id == 461892912821698562: | ||||||
| 			return True | 			return True | ||||||
| 		await ctx.send("This command is not for you!") | 		await ctx.send("This command is not for you!") | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ from typing import Dict, Type | ||||||
| 
 | 
 | ||||||
| # discord imports | # discord imports | ||||||
| import discord | import discord | ||||||
|  | from discord.ext import commands | ||||||
| 
 | 
 | ||||||
| # local imports | # local imports | ||||||
| from ..send_message import Send_message | from ..send_message import Send_message | ||||||
|  | @ -17,7 +18,7 @@ class Game_cog(Send_message): | ||||||
| 	def __init__(self, bot, game_cls: Type[Game]): | 	def __init__(self, bot, game_cls: Type[Game]): | ||||||
| 		self.bot = bot | 		self.bot = bot | ||||||
| 		self.game_cls = game_cls | 		self.game_cls = game_cls | ||||||
| 		self.game_instances = Dict[discord.TextChannel, self.game_cls] | 		self.game_instances = {}  # TODO: type hint? Dict[discord.TextChannel, self.game_cls] | ||||||
| 
 | 
 | ||||||
| 	async def setup_check(self, ctx): | 	async def setup_check(self, ctx): | ||||||
| 		if ctx.channel not in self.game_instances: | 		if ctx.channel not in self.game_instances: | ||||||
|  | @ -60,8 +61,10 @@ class Game_cog(Send_message): | ||||||
| 		embed.set_footer(text="Have fun!") | 		embed.set_footer(text="Have fun!") | ||||||
| 		await ctx.send(embed=embed) | 		await ctx.send(embed=embed) | ||||||
| 
 | 
 | ||||||
| 	async def pre_game_check(self, ctx): | 	def pre_game(): | ||||||
| 		return self.setup_check(ctx) and self.not_running_check(ctx) | 		async def predicate(ctx): | ||||||
|  | 			return await ctx.cog.setup_check(ctx) and await ctx.cog.not_running_check(ctx) | ||||||
|  | 		return commands.check(predicate) | ||||||
| 
 | 
 | ||||||
| 	async def players(self, ctx): | 	async def players(self, ctx): | ||||||
| 		await self.game_instances[ctx.channel].set_players(ctx.message) | 		await self.game_instances[ctx.channel].set_players(ctx.message) | ||||||
|  | @ -70,8 +73,10 @@ class Game_cog(Send_message): | ||||||
| 		self.game_instances[ctx.channel].game = self.bot.loop.create_task(self.game_instances[ctx.channel].round()) | 		self.game_instances[ctx.channel].game = self.bot.loop.create_task(self.game_instances[ctx.channel].round()) | ||||||
| 		await self.game_instances[ctx.channel].game | 		await self.game_instances[ctx.channel].game | ||||||
| 
 | 
 | ||||||
| 	async def in_game_check(self, ctx): | 	def in_game(): | ||||||
| 		return self.setup_check(ctx) and self.running_check(ctx) | 		async def predicate(ctx): | ||||||
|  | 			return await ctx.cog.setup_check(ctx) and await ctx.cog.running_check(ctx) | ||||||
|  | 		return commands.check(predicate) | ||||||
| 
 | 
 | ||||||
| 	async def stop(self, ctx): | 	async def stop(self, ctx): | ||||||
| 		self.game_instances[ctx.channel].game.cancel() | 		self.game_instances[ctx.channel].game.cancel() | ||||||
|  |  | ||||||
|  | @ -19,12 +19,12 @@ class Werewolf_cog(Game_cog, commands.Cog): | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	async def info(self, ctx): | 	async def info(self, ctx): | ||||||
| 		"""Send information about the subcommands for the game""" | 		"""Send information about the subcommands for the game""" | ||||||
| 		await super().info(ctx, Werewolf_game) | 		await super().info(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	async def setup(self, ctx): | 	async def setup(self, ctx): | ||||||
| 		"""This function creates an game instance for this channel""" | 		"""This function creates an game instance for this channel""" | ||||||
| 		await super().setup(ctx, Werewolf_game) | 		await super().setup(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	async def reset(self, ctx): | 	async def reset(self, ctx): | ||||||
|  | @ -32,37 +32,38 @@ class Werewolf_cog(Game_cog, commands.Cog): | ||||||
| 		await super().reset(ctx) | 		await super().reset(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.pre_game_check) | 	@Game_cog.pre_game() | ||||||
| 	async def players(self, ctx): | 	async def players(self, ctx): | ||||||
| 		"""registers all mentioned players for the game""" | 		"""registers all mentioned players for the game""" | ||||||
| 		await super().players(ctx) | 		await super().players(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.pre_game_check) | 	@Game_cog.pre_game() | ||||||
| 	async def roles(self, ctx, *args): | 	async def roles(self, ctx, *args): | ||||||
| 		"""registers roles you want to play with""" | 		"""registers roles you want to play with""" | ||||||
| 		await self.game_instances[ctx.channel].set_roles(args) | 		await self.game_instances[ctx.channel].set_roles(args) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.pre_game_check) | 	@Game_cog.pre_game() | ||||||
| 	async def minutes(self, ctx, i): | 	async def minutes(self, ctx, i: int): | ||||||
| 		"""set discussion time""" | 		"""set discussion time""" | ||||||
| 		await self.game_instances[ctx.channel].set_time(i) | 		await self.game_instances[ctx.channel].set_time(i) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.pre_game_check) | 	@Game_cog.pre_game() | ||||||
| 	async def start(self, ctx): | 	async def start(self, ctx): | ||||||
|  | 		print(await self.setup_check(ctx), await self.not_running_check(ctx)) | ||||||
| 		"""starts a round of werewolf""" | 		"""starts a round of werewolf""" | ||||||
| 		await super().start(ctx) | 		await super().start(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.in_game_check) | 	@Game_cog.in_game() | ||||||
| 	async def stop(self, ctx): | 	async def stop(self, ctx): | ||||||
| 		"""aborts the current round of werewolf""" | 		"""aborts the current round of werewolf""" | ||||||
| 		await super().stop(ctx) | 		await super().stop(ctx) | ||||||
| 
 | 
 | ||||||
| 	@werewolf.command() | 	@werewolf.command() | ||||||
| 	@commands.check(Game_cog.in_game_check) | 	@Game_cog.in_game() | ||||||
| 	async def time(self, ctx): | 	async def time(self, ctx): | ||||||
| 		"""checks how much discussion time there is left""" | 		"""checks how much discussion time there is left""" | ||||||
| 		await self.send_friendly(ctx, self.game_instances[ctx.channel].remaining_time_string()) | 		await self.send_friendly(ctx, self.game_instances[ctx.channel].remaining_time_string()) | ||||||
|  |  | ||||||
|  | @ -39,6 +39,7 @@ class Werewolf_game: | ||||||
| 		await self.send(f"You have set the discussion time to {self.discussion_time//60} minutes")  # send confirmation | 		await self.send(f"You have set the discussion time to {self.discussion_time//60} minutes")  # send confirmation | ||||||
| 
 | 
 | ||||||
| 	def check(self): | 	def check(self): | ||||||
|  | 		# TODO: min. player | ||||||
| 		if not 0 <= len(self.player_list) <= 10: | 		if not 0 <= len(self.player_list) <= 10: | ||||||
| 			raise ValueError(f"Invalid number of players: {len(self.player_list)}") | 			raise ValueError(f"Invalid number of players: {len(self.player_list)}") | ||||||
| 		if not len(self.role_list) == (len(self.player_list) + 3): | 		if not len(self.role_list) == (len(self.player_list) + 3): | ||||||
|  | @ -62,7 +63,7 @@ class Werewolf_game: | ||||||
| 		shuffle(self.role_list) | 		shuffle(self.role_list) | ||||||
| 		for i in range(len(self.player_list)): | 		for i in range(len(self.player_list)): | ||||||
| 			role_obj = self.role_list[i](self, self.player_list[i]) | 			role_obj = self.role_list[i](self, self.player_list[i]) | ||||||
| 			self.player_list[i].setRole(role_obj) | 			self.player_list[i].set_role(role_obj) | ||||||
| 			role_obj.add_yourself() | 			role_obj.add_yourself() | ||||||
| 		self.middle_card = [r(self) for r in self.role_list[-3:]] | 		self.middle_card = [r(self) for r in self.role_list[-3:]] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue