Example #1
0
 async def convert(self, ctx: commands.Context, name: str) -> discord.Member:
     member = self.nickname_fit(name)
     if member is None:
         try:
             member = await super().convert(ctx, name)
         except commands.BadArgument:
             raise commands.MemberNotFound(name)
         if member not in get_guild().members:
             member = get_member(member.id)
         if member is None:
             raise commands.MemberNotFound(name)
     if self.player_only and member not in get_player_role().members:
         raise MemberNotPlaying('This person is not playing.')
     return member
Example #2
0
    async def snipe_msg(
        self,
        ctx: commands.Context,
        channel_or_thread: Optional[TextChannelOrThread],
        edit: bool = False,
    ) -> None:
        await ctx.trigger_typing()
        if channel_or_thread is None:
            channel_or_thread = ctx.channel
        author = channel_or_thread.guild.get_member(ctx.author.id)
        if not isinstance(author, discord.Member):
            raise commands.MemberNotFound(author)
        if (not channel_or_thread.permissions_for(author).read_messages
                or not channel_or_thread.permissions_for(
                    author).read_message_history):
            await ctx.send(await
                           self.bot.localize("META_command_noperms",
                                             getattr(ctx.guild, "id", None),
                                             "error"))
        else:
            if guild := ctx.guild:
                perms = ctx.channel.permissions_for(ctx.me)
                if not perms.send_messages:
                    return
                if not perms.embed_links:
                    await ctx.send(await
                                   self.bot.localize("META_perms_noembed",
                                                     guild.id, "error"))
                    return

            await self._send_snipe(ctx, channel_or_thread, edit)
Example #3
0
 async def convert(self, ctx: Context, argument: str = None):
     try:
         member_converter = commands.MemberConverter()
         member = await member_converter.convert(ctx, argument)
         image = member.avatar.replace(format="png",
                                       static_format="png",
                                       size=1024)
         return str(image)
     except Exception:
         try:
             url = await emoji_to_url(argument)
             if re.match(regex_url, url):
                 image = str(url)
                 return image
             if re.match(regex_url, argument):
                 image = argument
                 return image
             if re.match(emoji_regex, argument):
                 emoji_converter = commands.EmojiConverter()
                 emoji = await emoji_converter.convert(ctx, argument)
                 image = emoji.url_as(format="png",
                                      static_format="png",
                                      size=1024)
                 return image
         except Exception:
             return None
     raise commands.MemberNotFound(argument)
Example #4
0
    async def convert(self, ctx, arg):
        with suppress(commands.MemberNotFound):
            return await commands.MemberConverter().convert(ctx, arg)

        try:
            return FakeUser(int(arg))
        except ValueError:
            raise commands.MemberNotFound(arg)
Example #5
0
    async def convert(self, ctx, arg):
        try:
            return await commands.MemberConverter().convert(ctx, arg)
        except commands.MemberNotFound:
            pass

        try:
            return FakeUser(int(arg))
        except ValueError:
            raise commands.MemberNotFound(arg)
Example #6
0
def get_mafia_player(game: MafiaGame, arg: str) -> Player:
    if not game:
        raise commands.BadArgument(
            "No game playing for this guild, cannot grab players"
        )

    result = None
    players = game.players
    match = re.match(r"([0-9]{15,20})$", arg) or re.match(r"<@!?([0-9]{15,20})>$", arg)
    if match is None:
        choices = {player: player.member.name for player in game.players}
        best = process.extractBests(arg, choices, score_cutoff=80, limit=1)

        if best:
            result = best[0][2]
    else:
        user_id = int(match.group(1))
        result = discord.utils.get(players, member__id=user_id)

    if not result:
        raise commands.MemberNotFound(arg)

    return result
Example #7
0
 async def convert(self, ctx, argument):
     member = utils.get_member_named(ctx, argument)
     if member is None:
         raise commands.MemberNotFound(argument)
     else:
         return member