コード例 #1
0
async def queue(ctx: lightbulb.Context):
    node = await lavalink.get_guild_node(ctx.guild_id)
    if node is not None:
        embed = None
        if len(node.queue) == 0:
            embed = helpers.get_default_embed(
                timestamp=dt.datetime.now().astimezone(),
                author=ctx.author,
            )
            embed.description = "*There are no songs currently in queue.*"
            await ctx.respond(embed=embed, reply=True)
        elif len(node.queue) == 1:
            current_track = node.queue[0]
            embed = helpers.get_default_embed(
                title=f"Queue for {ctx.get_guild().name}",
                timestamp=dt.datetime.now().astimezone(),
                author=ctx.author
            ).add_field(
                name="Now playing:",
                value=
                f"[{current_track.title}]({current_track.uri}) - {dt.timedelta(milliseconds = current_track.length)}",
                inline=False)
            await ctx.respond(embed=embed, reply=True)
        else:
            current_track = node.queue[0]
            upcoming = node.queue[1:]

            page_list = []
            text = ""
            embed = None
            for index, track in enumerate(upcoming):
                if index % 5 == 0:
                    embed = helpers.get_default_embed(
                        title=f"Queue for {ctx.get_guild().name}",
                        timestamp=dt.datetime.now().astimezone(),
                        author=ctx.author
                    ).add_field(
                        name="Now playing:",
                        value=
                        f"[{current_track.title}]({current_track.uri}) - {dt.timedelta(milliseconds = current_track.length)}",
                        inline=False)

                text += f"`{index + 1}`. [{track.title}]({track.uri}) - {dt.timedelta(milliseconds = track.length)}\n"

                if index % 5 == 4:
                    embed.add_field(name="Up Next:", value=text, inline=False)
                    page_list.append(embed)
                    text = ""
                    embed = None
            # We're updating text rather than embed every loop, this should be the check instead of embed is None.
            if text != "":
                embed.add_field(name="Up Next:", value=text, inline=False)
                page_list.append(embed)

            await ButtonPages(page_list).run(ctx)
    else:
        await ctx.respond("Bot is not in a voice channel.",
                          reply=True,
                          mentions_reply=True)
コード例 #2
0
ファイル: core.py プロジェクト: MikeJollie2707/MichaelBot
async def info(ctx: lightbulb.Context):
    embed = helpers.get_default_embed(
        title=ctx.bot.get_me().username,
        description=ctx.bot.d.description,
        timestamp=dt.datetime.now().astimezone()).add_field(
            name="Version:", value=ctx.bot.d.version, inline=False).add_field(
                name="Team:",
                value=dedent('''
                **Original Owner + Tester:** <@462726152377860109>
                **Developer:** <@472832990012243969>
                **Web Dev (?):** *Hidden*
                '''),
                inline=False).add_field(name="Bot Info:",
                                        value=dedent('''
                **Language:** Python
                **Created on:** Jan 10, 2022 (originally Nov 13, 2019)
                **Library:** [hikari](https://github.com/hikari-py/hikari), [hikari-lightbulb](https://github.com/tandemdude/hikari-lightbulb), [Lavalink](https://github.com/freyacodes/Lavalink), [lavaplayer](https://github.com/HazemMeqdad/lavaplayer)
                **Source:** [GitHub](https://github.com/MikeJollie2707/MichaelBot \"MichaelBot\")
                '''),
                                        inline=False).set_thumbnail(
                                            ctx.bot.get_me().avatar_url)

    up_time = dt.datetime.now().astimezone() - ctx.bot.d.online_at
    embed.add_field(name="Host Info:",
                    value=dedent(f'''
                **Processor:** Intel Core i3-10100 CPU @ 3.60GHz x 8
                **Memory:** 15.6 GiB of RAM
                **Bot Uptime:** {humanize.precisedelta(up_time, "minutes", format = "%0.0f")}
                '''),
                    inline=False)

    await ctx.respond(embed=embed, reply=True)
コード例 #3
0
ファイル: core.py プロジェクト: MikeJollie2707/MichaelBot
async def report(ctx: lightbulb.Context):
    report_type = ctx.options.type
    reason = ctx.options.reason

    REPORT_CHANNEL = 644339079164723201
    if report_type.upper() == "BUG" or report_type.upper() == "SUGGEST":
        embed = helpers.get_default_embed(
            title=report_type.capitalize(),
            description=reason,
            timestamp=dt.datetime.now().astimezone()).set_author(
                name=ctx.author.username,
                icon=ctx.author.avatar_url).set_footer(
                    text=f"Sender ID: {ctx.author.id}")

        try:
            await ctx.bot.rest.create_message(REPORT_CHANNEL, embed=embed)
            await ctx.respond("Report sent successfully! Thank you.",
                              reply=True)
        except hikari.ForbiddenError:
            await ctx.respond(
                "I can't send the report for some reasons. Join the support server and notify them about this, along with whatever you're trying to send.",
                reply=True,
                mentions_reply=True)
    else:
        await ctx.respond("`type` argument must be either `bug` or `suggest`.",
                          reply=True,
                          mentions_reply=True)
コード例 #4
0
def command_help_format(ctx: lightbulb.Context,
                        command: lightbulb.Command) -> hikari.Embed:
    # Signature includes full command name.
    embed_title = command.signature
    embed_description = "*No help provided*"
    if command.description != "":
        embed_description = command.description + '\n'
    #if command.get_help(ctx) is not None and command.get_help(ctx) != "":
    #    embed_description += command.get_help(ctx)
    #command_signature = command.signature

    # Usage here.

    embed = helpers.get_default_embed(title=embed_title,
                                      description=embed_description,
                                      timestamp=dt.datetime.now().astimezone(),
                                      author=ctx.author)

    if isinstance(command, lightbulb.PrefixCommandGroup) or isinstance(
            command, lightbulb.PrefixSubGroup):
        field_value = ""
        # I swear this part looks so dumb just because Python refuses to easily sort the dictionary.
        subcommands_list = [
            command.subcommands[name] for name in command.subcommands
        ]
        for subcommand in sorted(subcommands_list, key=lambda cmd: cmd.name):
            field_value += f"- `{subcommand.name}`: {subcommand.description}\n"

        if len(command.subcommands) > 0:
            embed.add_field(name="**Subcommands:**",
                            value=field_value,
                            inline=False)

    return embed
コード例 #5
0
def plugin_help_format(ctx: lightbulb.Context,
                       plugin: lightbulb.Plugin) -> t.List[hikari.Embed]:
    MAX_COMMANDS = 10
    display = ""
    plugins = []

    commands: t.List[lightbulb.Command] = filter_command_type(
        plugin.all_commands, __PREFIX_COMMAND_TYPES__, True)
    commands.sort(key=lambda command: command.name)
    for index, command in enumerate(commands):
        # Signature includes command name.
        command_title = command.signature

        display += f"**{command_title}:**\n"
        description = command.description
        if description is None or description == "":
            description = "*No help provided*"
        display += f"- {description}\n\n"

        if index == MAX_COMMANDS - 1 or index == len(commands) - 1:
            title = f"{plugin.name} ({len(commands)} commands):"

            embed = helpers.get_default_embed(
                title=title,
                description=display,
                timestamp=dt.datetime.now().astimezone(),
                author=ctx.author).set_thumbnail(ctx.bot.get_me().avatar_url)
            plugins.append(embed)
            display = ""

    return plugins
コード例 #6
0
    async def send_bot_help(self, ctx: lightbulb.context.base.Context) -> None:
        main_page: hikari.Embed = helpers.get_default_embed(
            title="Help",
            description="",
            timestamp=dt.datetime.now().astimezone(),
            author=ctx.author)

        plugins = ctx.bot.plugins
        plugin_info: t.Dict[str, int] = {}
        for name in plugins:
            public_commands = filter_command_type(plugins[name].all_commands,
                                                  __PREFIX_COMMAND_TYPES__,
                                                  True)
            public_commands_len = len(public_commands)

            if public_commands_len != 0:
                embed_name = f"{plugins[name].d.emote} {name} ({public_commands_len} commands):"
                embed_description = "*No description provided*"
                if plugins[name].description is not None and plugins[
                        name].description != "":
                    embed_description = plugins[name].description
                main_page.add_field(name=embed_name,
                                    value=embed_description,
                                    inline=False)

                plugin_info[name] = public_commands_len

        menu_root = MenuComponent(main_page)
        for name in plugin_info:
            menu_root.add_list_options(plugins[name].d.emote,
                                       plugin_help_format(ctx, plugins[name]))
        menu = MenuInteractionWrapper(menu_root)
        await menu.run(ctx)
コード例 #7
0
async def np(ctx: lightbulb.Context):
    await ctx.respond(
        "This command is currently not working as intended due to library limitation"
    )

    node = await lavalink.get_guild_node(ctx.guild_id)
    if node is not None:
        if not node.queue:
            await ctx.respond("*cricket noises*", reply=True)
            return

        # Imagine working on this cool af code then you realize there's no real way to get
        # the current position of the track. Sadge.

        current_track = node.queue[0]
        ratio = float(current_track.position) / float(current_track.length)
        # Milliseconds have this format hh:mm:ss.somerandomstuffs, so just split at the first dot.
        current_position = str(
            dt.timedelta(milliseconds=current_track.position)).split(
                '.', maxsplit=1)[0]
        full_duration = str(dt.timedelta(
            milliseconds=current_track.length)).split('.', maxsplit=1)[0]
        # We're using c-string here because when the dot is at the beginning and the end,
        # I need to deal with some weird string concat, so no.
        progress_cstring = ['-'] * 30

        # [30, -1) to make sure the dot can appear as the first character
        for i in range(30, -1, -1):
            if i / 30.0 <= ratio:
                progress_cstring[i] = '🔘'
                break

        progress_string = ''.join(progress_cstring)
        embed = helpers.get_default_embed(title="Now Playing",
                                          description=f"""
            [{current_track.title}]({current_track.uri})
            `{progress_string}`
            `{current_position}` / `{full_duration}`

            **Requested by:** {ctx.bot.cache.get_user(int(current_track.requester)).mention}
            """,
                                          author=ctx.author)

        if current_track.sourceName == "youtube":
            embed.set_thumbnail(
                get_yt_thumbnail_endpoint(current_track.identifier))
        await ctx.respond(embed=embed, reply=True)
    else:
        await ctx.respond("Bot is not in a voice channel.",
                          reply=True,
                          mentions_reply=True)
コード例 #8
0
async def search(ctx: lightbulb.Context):
    track = ctx.options.track

    # Ideally the user should provide keywords, but if they provide a link then I'll go with that too.
    results = await lavalink.auto_search_tracks(track)
    if results is None:
        await ctx.respond("Can't find any songs with the keywords provided.",
                          reply=True,
                          mentions_reply=True)
        return

    embed = helpers.get_default_embed(title="Top 10 search results",
                                      description="",
                                      timestamp=dt.datetime.now().astimezone(),
                                      author=ctx.author)

    for index, track in enumerate(results[:10]):
        embed.description += f"**{index + 1}.** [{track.title}]({track.uri}) - `{dt.timedelta(milliseconds = track.length)}`\n"
    await ctx.respond(embed=embed, reply=True)
コード例 #9
0
ファイル: core.py プロジェクト: MikeJollie2707/MichaelBot
async def changelog_dev(ctx: lightbulb.Context):
    if isinstance(ctx, lightbulb.PrefixContext):
        await ctx.event.message.delete()

    CHANNEL_ID = 759288597500788766
    channel: hikari.GuildTextChannel = ctx.bot.cache.get_guild_channel(
        CHANNEL_ID)
    if channel is None:
        return await ctx.respond(
            "Seems like I can't retrieve the change logs. You might wanna report this to the developers."
        )

    embeds = []
    async for message in channel.fetch_history().limit(10):
        embeds.append(
            helpers.get_default_embed(description=message.content,
                                      timestamp=dt.datetime.now().astimezone(),
                                      author=ctx.author))
    pages = ButtonPages(embeds)
    await pages.run(ctx)
コード例 #10
0
ファイル: core.py プロジェクト: MikeJollie2707/MichaelBot
async def profile(ctx: lightbulb.Context):
    member: hikari.Member = ctx.options.member

    if member is None:
        # ctx.author returns a User instead of a Member.
        member = ctx.member

    embed = helpers.get_default_embed(
        timestamp=dt.datetime.now().astimezone(), author=member).set_author(
            name=member.username, icon=member.avatar_url).add_field(
                name="Username:"******"Nickname:",
                    value=member.nickname
                    if member.nickname is not None else member.username,
                    inline=True).add_field(
                        name="Avatar URL:",
                        value=f"[Click here]({member.avatar_url})",
                        inline=True).set_thumbnail(member.avatar_url)

    account_age: str = humanize.precisedelta(dt.datetime.now().astimezone() -
                                             member.created_at,
                                             format='%0.0f')
    embed.add_field(name="Joined Discord for:",
                    value=account_age,
                    inline=False)
    member_age: str = humanize.precisedelta(dt.datetime.now().astimezone() -
                                            member.joined_at,
                                            format='%0.0f')
    embed.add_field(name=f"Joined {ctx.get_guild().name} for:",
                    value=member_age,
                    inline=False)

    roles = [helpers.mention(role) for role in member.get_roles()]
    s = " - "
    s = s.join(roles)
    embed.add_field(name="Roles:", value=s, inline=False)

    await ctx.respond(embed, reply=True)
コード例 #11
0
ファイル: core.py プロジェクト: MikeJollie2707/MichaelBot
async def serverinfo(ctx: lightbulb.Context):
    guild = ctx.get_guild()
    embed = helpers.get_default_embed(
        description="**Information about this server.**",
        timestamp=dt.datetime.now().astimezone()).set_thumbnail(
            guild.icon_url).set_author(name=guild.name, icon=guild.icon_url)

    embed.add_field(name="Name", value=guild.name, inline=True).add_field(
        name="Created On",
        value=guild.created_at.strftime("%b %d %Y"),
        inline=True).add_field(
            name="Owner",
            value=(await guild.fetch_owner()).mention,
            inline=True).add_field(name="Roles",
                                   value=str(len(guild.get_roles())) +
                                   " roles.",
                                   inline=True)

    guild_channel_count = {
        "text": 0,
        "voice": 0,
        "stage": 0,
        "category": 0,
        "news": 0,
    }
    channels = guild.get_channels()
    for channel_id in channels:
        if channels[channel_id].type == hikari.ChannelType.GUILD_TEXT:
            guild_channel_count["text"] += 1
        elif channels[channel_id].type == hikari.ChannelType.GUILD_VOICE:
            guild_channel_count["voice"] += 1
        elif channels[channel_id].type == hikari.ChannelType.GUILD_STAGE:
            guild_channel_count["stage"] += 1
        elif channels[channel_id].type == hikari.ChannelType.GUILD_CATEGORY:
            guild_channel_count["category"] += 1
        elif channels[channel_id].type == hikari.ChannelType.GUILD_NEWS:
            guild_channel_count["news"] += 1
    embed.add_field(name="Channels",
                    value=dedent(f'''
                Text Channels: {guild_channel_count["text"]}
                Voice Channels: {guild_channel_count["voice"]}
                Categories: {guild_channel_count["category"]}
                Stage Channels: {guild_channel_count["stage"]}
                News Channels: {guild_channel_count["news"]}
                '''),
                    inline=True)

    bot_count = 0
    members = guild.get_members()
    for member_id in members:
        if members[member_id].is_bot:
            bot_count += 1

    embed.add_field(name="Members Count",
                    value=dedent(f'''
                Total: {len(members)}
                Humans: {len(members) - bot_count}
                Bots: {bot_count}
                '''),
                    inline=True)

    embed.set_footer(f"Server ID: {guild.id}")

    await ctx.respond(embed=embed, reply=True)