예제 #1
0
    def trigger(self, *args, **kwargs):
        """Registered hooks for this event are called from highest to lowest priority.
        
        """

        if minqlbot.IS_DEBUG and self.name not in EventHandler.no_debug:
            minqlbot.debug("{}{}".format(self.name, args))

        plugins = self.plugins.copy()
        for i in range(5):
            for plugin in plugins:
                for handler in plugins[plugin][i]:
                    try:
                        retval = handler(*args, **kwargs)
                        if retval == minqlbot.RET_NONE or retval == None:
                            continue
                        elif retval == minqlbot.RET_STOP:
                            return
                        else:
                            debug("{}: unexpected return value '{}'".format(self.name, retval))
                    except:
                        e = traceback.format_exc().rstrip("\n")
                        debug("========== ERROR: {}@{} ==========".format(handler.__name__, plugin))
                        for line in e.split("\n"):
                            debug(line)
                        continue
예제 #2
0
    def trigger(self, *args, **kwargs):
        """Registered hooks for this event are called from highest to lowest priority.
        
        """

        if minqlbot.IS_DEBUG and self.name not in EventHandler.no_debug:
            minqlbot.debug("{}{}".format(self.name, args))

        plugins = self.plugins.copy()
        for i in range(5):
            for plugin in plugins:
                for handler in plugins[plugin][i]:
                    try:
                        retval = handler(*args, **kwargs)
                        if retval == minqlbot.RET_NONE or retval == None:
                            continue
                        elif retval == minqlbot.RET_STOP:
                            return
                        else:
                            debug("{}: unexpected return value '{}'".format(
                                self.name, retval))
                    except:
                        e = traceback.format_exc().rstrip("\n")
                        debug("========== ERROR: {}@{} ==========".format(
                            handler.__name__, plugin))
                        for line in e.split("\n"):
                            debug(line)
                        continue
예제 #3
0
def debug(dbgstr, only_debug=False):
    """A wrapper for minqlbot.debug ensuring the passed argument is a string.

    """
    if only_debug and not minqlbot.IS_DEBUG:
        return

    minqlbot.debug(str(dbgstr))
예제 #4
0
def debug(dbgstr, only_debug=False):
    """A wrapper for minqlbot.debug ensuring the passed argument is a string.

    """
    if only_debug and not minqlbot.IS_DEBUG:
        return

    minqlbot.debug(str(dbgstr))
예제 #5
0
 def debug(self, msg, only_debug=False):
     """Send a debug string that can be picked up by DebugView or similar applications.
     
     Args:
         msg (str): The string to be passed.
         only_debug (bool, optional): If true, only send if this is a debug build.
             Send otherwise.
     
     """
     if only_debug and not minqlbot.IS_DEBUG:
         return
     else:
         minqlbot.debug("[{}] {}".format(type(self).__name__, str(msg)))
예제 #6
0
 def debug(cls, msg, only_debug=False):
     """Send a debug string that can be picked up by DebugView or similar applications.
     
     Args:
         msg (str): The string to be passed.
         only_debug (bool, optional): If true, only send if this is a debug build.
             Send otherwise.
     
     """
     if only_debug and not minqlbot.IS_DEBUG:
         return
     else:
         minqlbot.debug("[{}] {}".format(cls.__name__, str(msg)))
예제 #7
0
    def run(self):
        try:
            self.plugin.debug("QLRanks thread #{} started!".format(self.uid))
            if self.check_alias:
                for i in range(len(self.players)):
                    c = self.plugin.db_query(
                        "SELECT name FROM Aliases WHERE other_name=?",
                        self.players[i])
                    res = c.fetchone()
                    if res:
                        self.aliases[res["name"]] = self.players[i]
                        self.players[i] = res["name"]
                self.plugin.db_close()

            try:
                player_list = "+".join(self.players)
                data = self.get_data("www.qlranks.com",
                                     "/api.aspx?nick={}".format(player_list))
            except:
                self.status = -2
                self.plugin.cache_players(None, self)
                self.plugin.execute_pending(
                )  # execute_pending has endless loop prevention.
                return

            if "players" not in data:
                raise Exception(
                    "QLRanks returned a valid, but unexpected JSON response.")

            if self.check_alias:
                # Replace alias nicknames with real names.
                for player in data["players"]:
                    name = player["nick"].lower()
                    if name in self.aliases:
                        player["nick"] = self.aliases[name]
                        player["alias_of"] = name
                        del self.aliases[name]

            self.plugin.cache_players(data, self)
            # Check for pending teams info/balancing needed. Execute if so.
            self.plugin.execute_pending()
        except:
            self.status = -3
            e = traceback.format_exc().rstrip("\n")
            minqlbot.debug(
                "========== ERROR: QLRanks Fetcher #{} ==========".format(
                    self.uid))
            for line in e.split("\n"):
                minqlbot.debug(line)
            self.plugin.cache_players(None, self)
            self.plugin.execute_pending()
예제 #8
0
    def run(self):
        try:
            self.plugin.debug("QLRanks thread #{} started!".format(self.uid))
            if self.check_alias:
                for i in range(len(self.players)):
                    c = self.plugin.db_query("SELECT name FROM Aliases WHERE other_name=?", self.players[i])
                    res = c.fetchone()
                    if res:
                        self.aliases[res["name"]] = self.players[i]
                        self.players[i] = res["name"]
                self.plugin.db_close()
            
            try:
                player_list = "+".join(self.players)
                data = self.get_data("www.qlranks.com", "/api.aspx?nick={}".format(player_list))
            except:
                self.status = -2
                self.plugin.cache_players(None, self)
                self.plugin.execute_pending() # execute_pending has endless loop prevention.
                return

            if "players" not in data:
                raise Exception("QLRanks returned a valid, but unexpected JSON response.")


            if self.check_alias:
                # Replace alias nicknames with real names.
                for player in data["players"]:
                    name = player["nick"].lower()
                    if name in self.aliases:
                        player["nick"] = self.aliases[name]
                        player["alias_of"] = name
                        del self.aliases[name]

            self.plugin.cache_players(data, self)
            # Check for pending teams info/balancing needed. Execute if so.
            self.plugin.execute_pending()
        except:
            self.status = -3
            e = traceback.format_exc().rstrip("\n")
            minqlbot.debug("========== ERROR: QLRanks Fetcher #{} ==========".format(self.uid))
            for line in e.split("\n"):
                minqlbot.debug(line)
            self.plugin.cache_players(None, self)
            self.plugin.execute_pending()
예제 #9
0
 def handle_error(self):
     self.ibuf = ""
     e = traceback.format_exc().rstrip("\n")
     minqlbot.debug("========== ERROR: SimpleIrc ==========")
     for line in e.split("\n"):
         minqlbot.debug(line)
예제 #10
0
 def handle_error(self):
     self.ibuf = ""
     e = traceback.format_exc().rstrip("\n")
     minqlbot.debug("========== ERROR: SimpleIrc ==========")
     for line in e.split("\n"):
         minqlbot.debug(line)