def get_emoji(self, emoji_name): # emoji = commands.EmojiConverter().convert(ctx, emoji_name) emoji = discord.utils.get(self.bot.emojis, name=emoji_name) if emoji: return emoji else: raise commands.EmojiNotFound(emoji_name)
async def convert(cls, ctx: commands.Context, argument: str) -> Union[discord.Emoji, str]: argument = re.sub("\ufe0f", "", argument) # remove trailing whitespace try: emoji = await ctx.bot.convert_emoji(argument) # method in `bot.py` except commands.BadArgument: raise commands.EmojiNotFound(argument) return emoji
async def convert(cls, ctx: commands.Context, argument: str) -> Union[discord.Emoji, str]: try: emoji = await ctx.bot.convert_emoji(argument) # method in `bot.py` except commands.BadArgument: raise commands.EmojiNotFound(argument) return emoji
async def connect_four( self, ctx: commands.Context, board_size: int = 7, emoji1: EMOJI_CHECK = "\U0001f535", emoji2: EMOJI_CHECK = "\U0001f534" ) -> None: """ Play the classic game of Connect Four with someone! Sets up a message waiting for someone else to react and play along. The game will start once someone has reacted. All inputs will be through reactions. """ check, emoji = self.check_emojis(emoji1, emoji2) if not check: raise commands.EmojiNotFound(emoji) check_author_result = await self.check_author(ctx, board_size) if not check_author_result: return announcement = await ctx.send( "**Connect Four**: A new game is about to start!\n" f"Press {Emojis.hand_raised} to play against {ctx.author.mention}!\n" f"(Cancel the game with {CROSS_EMOJI}.)" ) self.waiting.append(ctx.author) await announcement.add_reaction(Emojis.hand_raised) await announcement.add_reaction(CROSS_EMOJI) try: reaction, user = await self.bot.wait_for( "reaction_add", check=partial(self.get_player, ctx, announcement), timeout=60.0 ) except asyncio.TimeoutError: self.waiting.remove(ctx.author) await announcement.delete() await ctx.send( f"{ctx.author.mention} Seems like there's no one here to play. " f"Use `{ctx.prefix}{ctx.invoked_with} ai` to play against a computer." ) return if str(reaction.emoji) == CROSS_EMOJI: self.waiting.remove(ctx.author) await announcement.delete() await ctx.send(f"{ctx.author.mention} Game cancelled.") return await announcement.delete() self.waiting.remove(ctx.author) if self.already_playing(ctx.author): return await self._play_game(ctx, user, board_size, str(emoji1), str(emoji2))
async def convert(self, ctx, argument): try: emoji = await commands.EmojiConverter().convert(ctx, argument) return emoji except commands.BadArgument: if argument in UNICODE_EMOJI: return argument else: raise commands.EmojiNotFound(argument)
async def reactrole_add(self, ctx, msg: dc.Message, emoji: EmojiUnion, role: dc.Role): # Add a reaction to a message that will be attached to a toggleable role when reacted to. try: await msg.add_reaction(emoji) except dc.HTTPException as exc: if exc.args and exc.args[0].endswith('Unknown Emoji'): raise commands.EmojiNotFound('invalid emoji argument') await ctx.send(response_bank.reactrole_add_error) return self.data[msg.channel.id][msg.id][get_react_id(emoji)] = role.id self.data_save() await ctx.send(response_bank.reactrole_add_confirm.format(role=role))
async def ai(self, ctx: commands.Context, board_size: int = 7, emoji1: EMOJI_CHECK = "\U0001f535", emoji2: EMOJI_CHECK = "\U0001f534") -> None: """Play Connect Four against a computer player.""" check, emoji = self.check_emojis(emoji1, emoji2) if not check: raise commands.EmojiNotFound(emoji) check_author_result = await self.check_author(ctx, board_size) if not check_author_result: return await self._play_game(ctx, None, board_size, str(emoji1), str(emoji2))
async def connect_four(self, ctx: commands.Context, member: discord.Member = None, board_size: int = 7, emoji1: EMOJI_CHECK = "\U0001f535", emoji2: EMOJI_CHECK = "\U0001f534") -> None: """ Plays the classic game of Connect Four with someone! Sets up a message waiting for someone else to react and play along. The game will start once someone has reacted. All inputs will be through reactions. :param ctx: The context. :param board_size: The size of the game board. :param emoji1: The first emoji. :param emoji2: The second emoji. """ if not member or member.bot: return await self.ai(ctx) if member.id == ctx.author.id: return await ctx.send("**You cannot play against yourself!**") check, emoji = self.check_emojis(emoji1, emoji2) if not check: raise commands.EmojiNotFound(emoji) check_author_result = await self.check_author(ctx, board_size) if not check_author_result: return if self.already_playing(ctx.author): return if self.already_playing(member): return await ctx.reply("**This member is already playing!**") await self._play_game(ctx, member, board_size, str(emoji1), str(emoji2))