/botly/settings.py (bad6ea32f4705ce281bece3182f92778e472c3fa) (939 bytes) (mode 100644) (type blob)

#!/usr/bin/env python
"""Loads and manages the bot settings."""

from botly.db import Db


class Settings(Db):
    
    def __init__(self):
        self.settings = {}

    def get_string(self, key, default='None'):
        """Returns the string value if it exists."""
        if not key in self.settings: 
            self.settings[key] = self._load_setting(key, default)
        return self.settings[key]

    def get_int(self, key, default='0'):
        """Returns the int value if it exists."""
        # Default default is a string because passed to get_string.
        # It's converted back to int below
        v = self.get_string(key, default=default)
        return int(v)

    def _load_setting(self, key, default):
        assert self.is_loaded(), "Database is not loaded."
        setting = Db.dbxml.xpath('/BotDb/Settings/' + key)
        if setting:
            return setting[0].text
        else:
            return default


Mode Type Size Ref File
100644 blob 896 ac3944627b46e5914bc225d541cab61e13102ad4 README.md
040000 tree - c3633971c8e36cc59dd5c41fd76fa9255765416e botly
100644 blob 172 3f148ab99d152565c46e51fd45e51030417f7faa example.py
040000 tree - 902cb30cdf6276223ffa4043fbdaee680d0a984c examplebot
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/detche/Botly

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/detche/Botly

Clone this repository using git:
git clone git://git.rocketgit.com/user/detche/Botly

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main