Пример #1
0
class DiscordConverter(commands.Converter):
    @classmethod
    async def convert(cls,
                      ctx,
                      argument: str,
                      *,
                      globally: bool = True) -> discord.abc.Messageable:
        results = await cls.search(ctx, argument, globally=globally)
        if len(results) == 0:
            m = _("No destinations found.")
            await ctx.send(m)
            raise commands.BadArgument(m)
        if len(results) == 1:
            return results[0]
        message = _("Multiple results found. Choose a destination:\n\n")
        for i, result in enumerate(results):
            m = f"{i}: {result} ({result.id})"
            if guild := getattr(result, "guild", None):
                m = f"{m}, in {guild}"
            message = f"{message}\n{m}"
        await ctx.send(message)
        predicate = MessagePredicate.less(len(results), ctx=ctx)
        try:
            await ctx.bot.wait_for("message", check=predicate, timeout=30)
        except asyncio.TimeoutError as te:
            m = _("No destination selected.")
            await ctx.send(m)
            raise commands.BadArgument(m)
        return results[predicate]
Пример #2
0
    async def get_song(self, ctx: commands.Context, music_lyrics,
                       send_question: bool):
        message, available_musics = await self._title_choose(music_lyrics)
        if not send_question:
            return available_musics["0"]

        bot_message = await ctx.maybe_send_embed(message)
        predicator = MessagePredicate.less(10, ctx)
        try:
            user_message = await self.bot.wait_for("message",
                                                   check=predicator,
                                                   timeout=60)
        except Te:
            await ctx.send("Rude.")
            return
        finally:
            await bot_message.delete()

        chosen_music = user_message.content
        if chosen_music not in available_musics:
            if chosen_music != "-1":
                await ctx.send(
                    "I was unable to find the corresponding music in the available music list."
                )
            return
        return available_musics[chosen_music]
Пример #3
0
    async def lyrics(self, ctx: commands.Context, *, song_name: str):
        """Return the lyrics of a given music/song name.

        Powered by KSoft.Si.
        """
        song_name = BOT_SONG_RE.sub("", song_name)
        try:
            client = await self.obtain_client()
        except AttributeError:
            await ctx.send("Not key for KSoft.Si has been set, ask owner to add a key.")
            return
        try:
            music_lyrics = await client.music.lyrics(song_name)
        except ksoftapi.NoResults:
            await ctx.send("No lyrics were found for your music.")
            return
        except ksoftapi.APIError as e:
            await ctx.send(
                "The API returned an unknown error: {error}".format(error=inline(str(e)))
            )
            return
        except ksoftapi.Forbidden:
            await ctx.send("Request forbidden by the API.")
            return
        except KeyError:
            await ctx.send("The set API key seem to be wrong. Please contact the bot owner.")
            return
        message, available_musics = await self._title_choose(music_lyrics)
        bot_message = await ctx.maybe_send_embed(message)
        predicator = MessagePredicate.less(10, ctx)
        try:
            user_message = await self.bot.wait_for("message", check=predicator, timeout=60)
            await bot_message.delete()
        except Te:
            await ctx.send("Rude.")
            await bot_message.delete()
            return

        chosen_music = user_message.content
        if chosen_music not in available_musics:
            await ctx.send(
                "I was unable to find the corresponding music in the available music list."
            )
            return
        music = available_musics[chosen_music]
        embeds = []
        color = await ctx.embed_color()
        for text in pagify(music.lyrics):
            embed = discord.Embed(color=color, title=music.name, description=None)
            embed.set_thumbnail(
                url=music.album_art
                if str(music.album_art) != "https://cdn.ksoft.si/images/Logo1024%20-%20W.png"
                else discord.Embed.Empty
            )
            embed.set_footer(text="Powered by KSoft.Si.", icon_url=ctx.author.avatar_url)
            embed.description = text
            embeds.append(embed)
        if len(embeds) > 1:
            create_task(
                menu(ctx, embeds, DEFAULT_CONTROLS, timeout=600)
            )  # No await since max_concurrency is here
        else:
            await ctx.send(embed=embeds[0])