Esempio n. 1
0
 def __init__(self):
     """Set up IRC Client."""
     # Right now, only one bot can listen, so we take the values of the first one.
     with open(CONFIG_PATH.format(self.bots[0].root), "r",
               encoding="utf-8") as file:
         CONFIG = json.load(file)
     self.nickname = str(CONFIG["username"])
     self.clientID = str(CONFIG["clientID"])
     self.password = str(CONFIG["oauth_key"])
Esempio n. 2
0
    def __init__(self, bots, lport, password=None):
        """Initiate Web API."""
        global api_bots
        api_bots = bots

        global api_server
        api_server = StoppableWSGIRefServer(host='localhost', port=lport)

        global api_port
        api_port = lport

        global api_password
        api_password = password

        global clientID
        with open(CONFIG_PATH.format(bots[0].root), 'r', encoding="utf-8") as file:
            CONFIG = json.load(file)
        clientID = str(CONFIG['clientID'])

        threading.Thread(target=run, kwargs=dict(server=api_server,)).start()
Esempio n. 3
0
    def __init__(self, bot):
        """Set up connection to database and create tables if they do not yet exist."""
        self.bot = bot
        self.connection = sqlite3.connect(DATABASE_PATH.format(bot.root))
        sql_create_command = """
            CREATE TABLE IF NOT EXISTS points (
            'viewer_id' INTEGER NOT NULL,
            'amount'    INTEGER NOT NULL,
            PRIMARY KEY('viewer_id')
            );
            """
        self.cursor = self.connection.cursor()
        self.cursor.execute(sql_create_command)
        self.cursor.close()
        self.connection.commit()
        self.connection.close()

        with open(CONFIG_PATH.format(bot.root), encoding="utf-8") as fp:
            CONFIG = json.load(fp)

        self.BASE = CONFIG["ranking"][
            "base"]  # points from min rank to second min rank
        self.FACTOR = CONFIG["ranking"]["factor"]
        self.RANKS = CONFIG["ranking"]["ranks"]
Esempio n. 4
0
    def reloadConfig(self, firstRun=False):
        """Reload the entire config."""
        with open(CONFIG_PATH.format(self.root), 'r',
                  encoding="utf-8") as file:
            CONFIG = json.load(file)

        with open(TRUSTED_MODS_PATH.format(self.root), encoding="utf-8") as fp:
            self.trusted_mods = json.load(fp)

        with open(IGNORED_USERS_PATH.format(self.root),
                  encoding="utf-8") as fp:
            self.ignored_users = json.load(fp)

        with open(PRONOUNS_PATH.format(self.root), encoding="utf-8") as fp:
            self.pronouns = json.load(fp)

        # load template responses first
        with open(TEMPLATE_RESPONSES_PATH, 'r', encoding="utf-8") as file:
            RESPONSES = json.load(file)

        # load custom responses
        try:
            with open(CUSTOM_RESPONSES_PATH.format(self.root),
                      'r',
                      encoding="utf-8") as file:
                CUSTOM_RESPONSES = json.load(file)
        except FileNotFoundError:  # noqa
            logging.warning("No custom responses file for {}.".format(
                self.root))
            CUSTOM_RESPONSES = {}
        except Exception:
            # Any errors else
            logging.error(
                "Unknown errors when reading custom responses of {}.".format(
                    self.root))
            logging.error(traceback.format_exc())
            CUSTOM_RESPONSES = {}

        # then merge with custom responses
        RESPONSES = self.deepMergeDict(RESPONSES, CUSTOM_RESPONSES)

        self.last_warning = defaultdict(int)
        self.owner_list = CONFIG['owner_list']
        self.nickname = str(CONFIG['username'])
        self.clientID = str(CONFIG['clientID'])
        self.password = str(CONFIG['oauth_key'])
        # Not really part of config, but getuserID() will need this, so we use this hacky way to put it here

        self.TWITCH_API_COMMON_HEADERS = {
            'Accept': 'application/vnd.twitchtv.v5+json',
            'Client-ID': self.clientID,
            'Authorization': self.password
        }

        self.channel = "#" + str(CONFIG['channel'])
        self.channelID = self.getuserID(str(CONFIG['channel']))
        self.pleb_cooldowntime = CONFIG[
            "pleb_cooldown"]  # time between non-sub commands
        self.pleb_gametimer = CONFIG[
            "pleb_gametimer"]  # time between pleb games
        self.last_plebcmd = time.time() - self.pleb_cooldowntime
        self.last_plebgame = time.time() - self.pleb_gametimer
        self.config = CONFIG
        self.responses = RESPONSES
        self.KAPPAGAMEP = CONFIG["points"]["kappa_game"]
        self.EMOTEGAMEEMOTES = CONFIG["EmoteGame"]
        self.EMOTEGAMEP = CONFIG["points"]["emote_game"]
        self.MINIONGAMEP = CONFIG["points"]["minion_game"]
        self.PYRAMIDP = CONFIG["points"]["pyramid"]
        self.GAMESTARTP = CONFIG["points"]["game_start"]
        self.AUTO_GAME_INTERVAL = CONFIG["auto_game_interval"]
        self.NOTIFICATION_INTERVAL = CONFIG[
            "notification_interval"]  # time between notification posts
        self.RAID_ANNOUNCE_THRESHOLD = CONFIG.get(
            "raid_announce_threshold", DEFAULT_RAID_ANNOUNCE_THRESHOLD)

        if not firstRun:
            self.reload_commands()
Esempio n. 5
0
 def setConfig(self, config):
     """Write the config file and reload."""
     with open(CONFIG_PATH.format(self.root), 'w',
               encoding="utf-8") as file:
         json.dump(config, file, indent=4)
     self.reloadConfig()
Esempio n. 6
0
 def has_bot_permission(username, bot):
     """Check if the user is allowed to access the bot."""
     with open(CONFIG_PATH.format(bot.root), "r", encoding="utf-8") as file:
         CONFIG = json.load(file)
     admins = CONFIG["owner_list"]
     return username in admins