示例#1
0
def topic_update(channel, topic_channel):
    """
    Creates an embed UI for the topic update

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to
        topic_channel: The new topic channel

    Returns:
        gui (embed.UI): The created embed
    """

    if topic_channel is not None:
        try:
            channel_message = "Topic channel is now `{}`.".format(topic_channel.name)
        except Exception as e:
            logger.exception(e)
            channel_message = "Topic channel has been updated."
    else:
        channel_message = "Topic channel has been cleared."

    # Create embed UI object
    gui = embed.UI(
            channel,
            "Topic channel updated",
            channel_message,
            modulename="music",
            colour=_data.MODULECOLOUR_INFO
    )

    return gui
示例#2
0
def success(channel, image, hex_str):
    """
    Creates an embed UI containing a hex color message

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to
        image (str): The url of the image to add
        hex_str (str): The hex value

    Returns:
        ui (embed.UI): The embed UI object that was created
    """

    hex_number = int(hex_str, 16)

    # Create embed UI object
    gui = embed.UI(
        channel,
        "",
        "#{}".format(hex_str),
        modulename="hex",
        colour=hex_number,
        thumbnail=image,
    )

    return gui
示例#3
0
    def construct_embed(self) -> embed.UI:
        """Constructs a new embed UI object with default values.

        Returns:
            constructed_embed (embed.UI): The new embed UI object.
        """

        # Create initial gui values
        queue_display = []
        for i in range(self.queue_display_size):
            queue_display.append("{}. ---\n".format(str(i + 1)))
        datapacks = [
            ("Now playing", "---", False),
            ("Author", "---", True),
            ("Source", "---", True),
            ("Time", "```http\n" + _timebar.make_timebar() + "\n```", False),
            ("Queue", "```md\n{}\n```".format(''.join(queue_display)), False),
            ("Songs left in queue", "---", True),
            ("Volume", "{}%".format(self.volume), True),
            ("Status", "```---```", False)
        ]

        # Create embed UI object
        constructed_embed = embed.UI(
            self.text_channel,
            "",
            "",
            modulename="music",
            colour=_data.MODULECOLOUR,
            datapacks=datapacks
        )

        # Add logging handlers for gui updates
        formatter_none = logging.Formatter("{message}", style="{")
        formatter_time = logging.Formatter("```http\n{message}\n```", style="{")
        formatter_md = logging.Formatter("```md\n{message}\n```", style="{")
        formatter_volume = logging.Formatter("{message}%", style="{")
        formatter_status = logging.Formatter("```__{levelname}__\n{message}\n```", style="{")
        for i in range(len(self.ui_fields)):
            field = self.ui_fields[i]
            handler = EmbedLogHandler(constructed_embed, i)

            if field in ["nowplaying", "author", "source", "queue_size"]:
                handler.setFormatter(formatter_none)
            elif field == "time":
                handler.setFormatter(formatter_time)
            elif field == "queue":
                handler.setFormatter(formatter_md)
            elif field == "volume":
                handler.setFormatter(formatter_volume)
            elif field == "status":
                handler.setFormatter(formatter_status)

            self.ui_loggers[field].addHandler(handler)

        return constructed_embed
示例#4
0
def fail_api(channel):
    """Creates an embed UI for when the API call didn't work

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to

    Returns:
        ui (embed.UI): The embed UI object
    """

    gui = embed.UI(channel,
                   "Couldn't get stats off RLTrackerNetwork.",
                   "Please tell a dev if you're getting this repeatedly.",
                   modulename="rocketleague",
                   colour=0x0088FF)

    return gui
示例#5
0
def success(channel, stats, name, platform, dp):
    """Creates an embed UI containing the Rocket League stats

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to
        stats (tuple): Tuples of (field, value, percentile)
        name (str): The name of the player
        platform (str): The playfor to search on, can be 'steam', 'ps', or 'xbox'
        dp (str): URL to the player's dp

    Returns:
        (discord.Embed): The created embed
    """

    # Create datapacks
    datapacks = [("Platform", platform, False)]
    for stat in stats:
        # Add stats
        if stat[0] in ("Duel 1v1", "Doubles 2v2", "Solo Standard 3v3",
                       "Standard 3v3"):
            stat_name = "__" + stat[0] + "__"
            stat_value = "**" + stat[1] + "**"
        else:
            stat_name = stat[0]
            stat_value = stat[1]

        # Add percentile if it exists
        if stat[2]:
            stat_value += " *({})*".format(stat[2])

        datapacks.append((stat_name, stat_value, True))

    # Create embed UI object
    gui = embed.UI(channel,
                   "Rocket League Stats: {}".format(name),
                   "*Stats obtained from [Rocket League Tracker Network]"
                   "(https://rocketleague.tracker.network/)*",
                   modulename="rocketleague",
                   colour=0x0088FF,
                   thumbnail=dp,
                   datapacks=datapacks)

    return gui
示例#6
0
def fail_steamid(channel):
    """Creates an embed UI for invalid SteamIDs

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to

    Returns:
        ui (embed.UI): The embed UI object
    """

    gui = embed.UI(
        channel,
        "That SteamID doesn't exist.",
        "You can get your SteamID by going to your profile page and looking at "
        "the url, or you can set a custom ID by going to edit profile on your "
        "profile page.",
        modulename="rocketleague",
        colour=0x0088FF)

    return gui
示例#7
0
def fail_api(channel):
    """
    Creates an embed UI for when the API call didn't work

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to

    Returns:
        ui (embed.UI): The embed UI object
    """

    gui = embed.UI(
        channel,
        "Invalid value",
        "Hex values must be 3 or 6 characters long, " +
        "and must start with '#' or '0x'.",
        modulename="hex",
        colour=0x555555,
    )

    return gui
示例#8
0
def error_message(channel, err_title, err_message):
    """
    Creates an embed UI for the topic update

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to
        err_title: The title for the error
        err_message: The message for the error

    Returns:
        hui (embed.UI): The created embed
    """

    # Create embed UI object
    gui = embed.UI(
            channel,
            err_title,
            err_message,
            modulename="music",
            colour=_data.MODULECOLOUR_ERROR
    )

    return gui
示例#9
0
def vote_ui(channel, options):
    """
    Creates an embed UI for the topic update

    Args:
        channel (discord.Channel): The Discord channel to bind the embed to.
        options (dict): All the votable options with keys as the option and values as the number of votes the option has.

    Returns:
        gui (embed.UI): The created embed
    """

    # TODO parse [options] to create [message]

    # Create embed UI object
    gui = embed.UI(
            channel,
            "Ballot",
            message,
            modulename="decide",
            colour=_data.MODULECOLOUR_INFO
    )

    return gui
示例#10
0
    def new_embed_ui(self):
        """Create the embed UI object and save it to self"""

        self.logger.debug("Creating new embed ui object")

        # Initial queue display
        queue_display = []
        for i in range(self.queue_display):
            queue_display.append("{}. ---\n".format(str(i + 1)))

        # Initial datapacks
        datapacks = [
            ("Now playing", "---", False), ("Author", "---", True),
            ("Source", "---", True),
            ("Time", "```http\n" + _timebar.make_timebar() + "\n```", False),
            ("Queue", "```md\n{}\n```".format(''.join(queue_display)), False),
            ("Songs left in queue", "---", True),
            ("Volume", "{}%".format(self.volume), True),
            ("Status", "```---```", False)
        ]

        # Create embed UI object
        self.embed = ui_embed_tools.UI(self.mchannel,
                                       "",
                                       "",
                                       modulename="music",
                                       colour=_data.MODULECOLOUR,
                                       datapacks=datapacks)

        # Add handlers to update gui
        noformatter = logging.Formatter("{message}", style="{")
        timeformatter = logging.Formatter("```http\n{message}\n```", style="{")
        mdformatter = logging.Formatter("```md\n{message}\n```", style="{")
        statusformatter = logging.Formatter(
            "```__{levelname}__\n{message}\n```", style="{")
        volumeformatter = logging.Formatter("{message}%", style="{")

        nowplayinghandler = EmbedLogHandler(self, self.embed, 0)
        nowplayinghandler.setFormatter(noformatter)
        nowplayingauthorhandler = EmbedLogHandler(self, self.embed, 1)
        nowplayingauthorhandler.setFormatter(noformatter)
        nowplayingsourcehandler = EmbedLogHandler(self, self.embed, 2)
        nowplayingsourcehandler.setFormatter(noformatter)
        timehandler = EmbedLogHandler(self, self.embed, 3)
        timehandler.setFormatter(timeformatter)
        queuehandler = EmbedLogHandler(self, self.embed, 4)
        queuehandler.setFormatter(mdformatter)
        queuelenhandler = EmbedLogHandler(self, self.embed, 5)
        queuelenhandler.setFormatter(noformatter)
        volumehandler = EmbedLogHandler(self, self.embed, 6)
        volumehandler.setFormatter(volumeformatter)
        statushandler = EmbedLogHandler(self, self.embed, 7)
        statushandler.setFormatter(statusformatter)

        self.nowplayinglog.addHandler(nowplayinghandler)
        self.nowplayingauthorlog.addHandler(nowplayingauthorhandler)
        self.nowplayingsourcelog.addHandler(nowplayingsourcehandler)
        self.timelog.addHandler(timehandler)
        self.queuelog.addHandler(queuehandler)
        self.queuelenlog.addHandler(queuelenhandler)
        self.volumelog.addHandler(volumehandler)
        self.statuslog.addHandler(statushandler)