Exemplo n.º 1
0
    def from_dict(cls, bot: vbu.Bot, location_data: dict, quotes_data: dict):
        """
        Loads an :class:`Item` from a dictionary.

        Args:
            bot (:class:`voxelbot.VoxelBot`): The bot used for loading emojis.
            data (`dict`): The dictionary to load the item from.
        """

        return cls(
            bot,
            location_data["level"],
            location_data["id"],
            location_data["name"],
            location_data["description"],
            bot.get_emoji(location_data["emoji"])
            if isinstance(location_data["emoji"], int)
            else location_data["emoji"],
            LootTable(*(LootTableItem(**item) for item in location_data["loot_table"])),
            Quotes(
                (location_data["quotes"]["success"]) + quotes_data["success"],
                (location_data["quotes"]["fail"]) + quotes_data["fail"],
                MiniGames(
                    FillInTheBlank(
                        **location_data["quotes"]["minigames"]["fill_in_the_blank"],
                    ),
                    Scramble(
                        **location_data["quotes"]["minigames"]["scramble"],
                    ),
                    Retype(**location_data["quotes"]["minigames"]["retype"]),
                ),
            ),
        )
Exemplo n.º 2
0
    def from_dict(cls, bot: vbu.Bot, data: dict):
        """
        Loads an :class:`Item` from a dictionary. This can be used to load an item from `./config/items.toml`.

        Args:
            data (`dict`): The dictionary to load the item from.
        """

        return cls(
            bot,
            data["id"],
            data["type"],
            data["rarity"],
            bot.get_emoji(data["emoji"])
            if isinstance(data["emoji"], int) else data["emoji"],
            data["name"],
            data["description"],
            [
                SkillRequirements(**req)
                for req in data["skill_requirements"] if req
            ],
            ShopSettings(**data["shop_settings"]),
            [Recipe(**r) for r in data["recipe"] if r],
            Usage.from_dict(data["usage"]),
        )
Exemplo n.º 3
0
 def __init__(
     self,
     bot: vbu.Bot,
     level: int,
     id: str,
     name: str,
     description: str,
     emoji: typing.Union[str, int, discord.Emoji],
     loot_table: LootTable,
     quotes: Quotes,
 ):
     self.level = level
     self.id = id
     self.name = name
     self.description = description
     self.emoji = bot.get_emoji(emoji) if isinstance(emoji, int) else emoji
     self.loot_table = loot_table
     self.quotes = quotes
Exemplo n.º 4
0
    def __init__(
        self,
        bot: vbu.Bot,
        id: str,
        type: str,
        rarity: str,
        emoji: typing.Union[int, discord.Emoji],
        name: str,
        description: str,
        skill_requirements: typing.List[SkillRequirements],
        shop_settings: ShopSettings,
        recipe: typing.List[Recipe],
        usage: Usage,
        amount: int = 1,
    ):
        """
        Args:
            bot (:class:`vbu.Bot`): The bot.
            id (`str` UPPER_SNAKE_CASE): The ID of the item.
            type (`str` UPPER_SNAKE_CASE): The type of the item..
            rarity (`str` UPPER_SNAKE_CASE): The rarity of the item.
            emoji (`int` or `str`): The custom ID of the emoji associated with the item.
            name (`str`): The name of the item.
            description (`str`): The description of the item.
            skill_requirements (`list` of :class:`SkillRequirements`): The skill requirements of the item.
            shop_settings (`list` of :class:`ShopSettings`): The shop settings of the item.
            recipe (`list` of :class:`Recipe`): The recipe of the item.
            usage (:class:`Usage`): The usage of the item.
            amount (`int`): The amount of the item.
        """

        self.id = id
        self.type = type
        self.rarity = rarity
        self.emoji = bot.get_emoji(emoji) if isinstance(emoji, int) else emoji
        self.name = name
        self.description = description
        self.skill_requirements = skill_requirements
        self.shop_settings = shop_settings
        self.recipe = recipe
        self.usage = usage
        self.amount = amount
Exemplo n.º 5
0
def setup(bot: vbu.Bot):
    x = MovieCommand(bot)
    bot.add_cog(x)
Exemplo n.º 6
0
def setup(bot: vbu.Bot):
    x = LibraryDocs(bot)
    bot.add_cog(x)
def setup(bot: vbu.Bot):
    x = TwitchFollowerUpdater(bot)
    bot.add_cog(x)
Exemplo n.º 8
0
def setup(bot: vbu.Bot):
    x = FAQHandler(bot)
    bot.add_cog(x)
Exemplo n.º 9
0
def setup(bot: vbu.Bot):
    x = RolePicker(bot)
    bot.add_cog(x)
Exemplo n.º 10
0
def setup(bot: vbu.Bot):
    x = GoogleCommands(bot)
    bot.add_cog(x)
Exemplo n.º 11
0
def setup(bot: vbu.Bot):
    x = PingCommand(bot)
    bot.add_cog(x)
Exemplo n.º 12
0
def setup(bot: vbu.Bot):
    x = ReplyCommand(bot)
    bot.add_cog(x)
Exemplo n.º 13
0
def setup(bot: vbu.Bot):
    x = WolframAlpha(bot)
    bot.add_cog(x)
Exemplo n.º 14
0
def setup(bot: vbu.Bot):
    x = UserInfo(bot)
    bot.add_cog(x)
Exemplo n.º 15
0
def setup(bot: vbu.Bot):
    x = SteamCommand(bot)
    bot.add_cog(x)
Exemplo n.º 16
0
def setup(bot: vbu.Bot):
    x = MiscCommands(bot)
    bot.add_cog(x)
Exemplo n.º 17
0
def setup(bot: vbu.Bot):
    x = RunescapeCommands(bot)
    bot.add_cog(x)
Exemplo n.º 18
0
def setup(bot: vbu.Bot):
    x = UserPoints(bot)
    bot.add_cog(x)
Exemplo n.º 19
0
def setup(bot: vbu.Bot):
    x = MeowChat(bot)
    bot.add_cog(x)
Exemplo n.º 20
0
def setup(bot: vbu.Bot):
    x = ScamBanner(bot)
    bot.add_cog(x)
Exemplo n.º 21
0
def setup(bot: vbu.Bot):
    x = NicknameHandler(bot)
    bot.add_cog(x)
Exemplo n.º 22
0
def setup(bot: vbu.Bot):
    x = GamblingCommands(bot)
    bot.add_cog(x)
Exemplo n.º 23
0
def setup(bot: vbu.Bot):
    x = StickerStealer(bot)
    bot.add_cog(x)
Exemplo n.º 24
0
def setup(bot: vbu.Bot):
    x = TimezoneInfo(bot)
    bot.add_cog(x)
Exemplo n.º 25
0
def setup(bot: vbu.Bot):
    x = QuoteCommands(bot)
    bot.add_cog(x)
Exemplo n.º 26
0
async def get_user_cache(
    user_id: int,
    *,
    db,
    bot: vbu.Bot,
    logger: typing.Optional[logging.Logger] = logging.Logger(
        "CachedUser", level=logging.DEBUG),
) -> CachedUser:
    """
    :coro: Returns user's cached information, if any. Otherwise returns data from the database.

    Args:
        bot (`:class:vbu.Bot`):  The bot.
        user_id (`int`): The user's ID.
        db (:class:`voxelbotutils.DatabaseConnection`): The database connection.
        logger (:class:`voxelbotutils.Logger` = :class:`Logger("utils.CacherUser")`): The logger.

    Returns:
        :class:`UserCache`: The user's cache.
    """

    # If the user is already cached, return it
    try:
        return bot.user_cache[user_id]

    # Otherwise, let's create it
    except KeyError:

        # Get the user's skills
        user_skill_rows = await db(
            "SELECT * FROM user_skill WHERE user_id = $1", user_id)
        user_skills = [Skill(**i) for i in user_skill_rows]

        # Now let's get the user's pp
        try:
            pp_rows = await db("SELECT * FROM user_pp WHERE user_id = $1",
                               user_id)
            user_pp = Pp(**pp_rows[0])

        # apparently the user doesn't have pp? Let's create one
        except IndexError:
            user_pp = Pp(user_id)

        # Get the user's settings
        try:
            settings_rows = await db(
                "SELECT * FROM user_settings WHERE user_id = $1", user_id)
            user_settings = dict(settings_rows[0])

        # No settings
        except IndexError:
            await db(
                "INSERT INTO user_settings (user_id) VALUES ($1)",
                user_id,
            )
            settings_rows = await db(
                "SELECT * FROM user_settings WHERE user_id = $1", user_id)
            user_settings = dict(settings_rows[0])

        # Now we add this to the user cache
        bot.user_cache[user_id] = CachedUser(user_id, user_skills, user_pp,
                                             user_settings)

        # we do a little logging. it's called: "We do a little logging"
        if logger is not None:
            logger.debug(f"Creating user cache for {user_id}... success")

        # and return the user cache
        return bot.user_cache[user_id]
Exemplo n.º 27
0
def setup(bot: vbu.Bot):
    x = CommandCounter(bot)
    bot.add_cog(x)
Exemplo n.º 28
0
def setup(bot: vbu.Bot):
    x = EconomyCommands(bot)
    bot.add_cog(x)
Exemplo n.º 29
0
def setup(bot: vbu.Bot):
    x = ReminderCommands(bot)
    bot.add_cog(x)