import discord class Player: @staticmethod async def make(member, game): p = Player() p.member = member p.dm = member.dm_channel or await member.create_dm() p.game = game return p def setRole(self, role): self.day_role = self.night_role = role def reset(self): self.tally = 0 self.won = self.dead = False def name(self): return self.member.name def __str__(self): return self.name() def swap(self, player_B): self.day_role, player_B.day_role = player_B.day_role, self.day_role def other(self): return [p for p in self.game.player_list if p != self] async def send_normal(self, message): await self.dm.send(message) async def send_embed(self, desc, color): await self.dm.send(embed=discord.Embed(description=desc, color=color)) async def send_wrong(self, message): await self.send_embed(message, 0xff8000) async def send_confirmation(self, message): await self.send_embed(message, 0x00ff00) async def send_info(self, message): await self.send_embed(message, 0x00ffff) async def ask_choice(self, question, options): text = f"{question}\n" + f"{'='*len(question)}\n\n" + '\n'.join(f"[{str(i)}]({str(options[i])})" for i in range(len(options))) await self.dm.send(f"```md\n{text}```") def check_num(self, choice, N): if not choice.isdigit(): raise ValueError(f"Your choice {choice} is not a number") if not 0 <= int(choice) < N: raise ValueError(f"Your choice {choice} is not in range 0 - {N-1}") async def receive_choice(self, options, n_ans=1): while True: def check(choice): return choice.channel == self.dm and choice.author == self.member choice = (await self.game.bot.wait_for('message', timeout=30.0, check=check)).content.split() if not len(choice) == n_ans: await self.send_wrong(f"Please give {n_ans} numbers not {len(choice)}") continue try: for c in choice: self.check_num(c, len(options)) except ValueError as error: await self.send_wrong(str(error)) continue await self.send_confirmation(f"Received: {', '.join(choice)}") return [int(c) for c in choice] async def get_choice(self, question, options): await self.ask_choice(question, options) return (await self.receive_choice(options))[0] async def get_double_choice(self, question, options): await self.ask_choice(question, options) return await self.receive_choice(options, 2) async def cast_vote(self, question, options): self.vote = options[await self.get_choice(question, options)] async def ready_to_vote(self): def check(msg): return msg.channel == self.dm and msg.author == self.member and msg.content.casefold() == "vote" await self.game.bot.wait_for('message', check=check) await self.send_confirmation("You are ready to vote") class No_player(Player): def name(self): return "no one"