예제 #1
0
파일: main.py 프로젝트: agile/sevabot
def main(settings="settings.py", verbose=False, daemon=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging
    level = getattr(logging, getattr(settings, "LOG_LEVEL", "INFO"), "INFO")
    logging.basicConfig(level=level, stream=sys.stdout, format=settings.LOG_FORMAT)

    # Setup logging file
    if getattr(settings, "LOG_FILE", None):
        if not settings.LOG_FILE.startswith("/"):
            log_path = settings.LOG_FILE
        else:
            log_path = os.path.join(os.path.dirname(settings.__file__), settings.LOG_FILE)

        formatter = logging.Formatter(settings.LOG_FORMAT)

        hdlr = logging.handlers.RotatingFileHandler(log_path,
            encoding="utf-8",
            maxBytes=settings.LOG_ROTATE_MAX_SIZE,
            backupCount=settings.LOG_ROTATE_COUNT)

        hdlr.setFormatter(formatter)

        logger.addHandler(hdlr)

    logger.info("Starting sevabot")

    for skype_logger_name in ["Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
                              "Skype4Py.api.darwin.SkypeAPI"]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    # Detach from the controlling terminal
    if daemon:
        create_daemon()

    from sevabot.bot import modules

    modules.load_modules()

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    api.configure(sevabot, settings, server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0
예제 #2
0
파일: bot.py 프로젝트: b2jrock/sevabot
    def handleMessages(self, msg, status):
        """
        Handle incoming messages
        """
        if status == "RECEIVED" or status == "SENT":
            logger.debug("%s - %s - %s: %s" % (status, msg.Chat.FriendlyName, msg.FromHandle, msg.Body))

        if status in ["RECEIVED", "SENT"] and msg.Body:

            words = msg.Body.split()

            if len(words) < 0:
                return

            keyword = words[0]

            if not keyword.startswith("!"):
                return

            keyword = keyword[1:]

            logger.debug("Trying to identify keyword: %s" % keyword)

            if keyword == "reload":
                commands = modules.load_modules()
                msg.Chat.SendMessage("Available commands: %s" % ", ".join(commands))
                return

            if modules.is_module(keyword):
                # Execute module asynchronously

                def callback(output):
                    msg.Chat.SendMessage(output)

                modules.run_module(keyword, words[1:], callback)
                return

            if msg.Body == "!loadModules":
                msg.Chat.SendMessage("Loading modules...")
                try:
                    modules.load_modules()
                except Exception as e:
                    msg.Chat.SendMessage(str(e))
                    return
                return

            elif msg.Body == "!loadChats":
                self.cacheChats()
                return
예제 #3
0
    def builtin_reload(self, args, msg, status):
        """Reload command modules.
        """
        request = urllib.urlopen('http://vast-castle-1062.herokuapp.com/tags')
        self.tagWords = json.loads(request.read())  

        commands = modules.load_modules(self.sevabot)
        msg.Chat.SendMessage('I feel refreshed! Awaiting your command.')
예제 #4
0
파일: main.py 프로젝트: tenpn/sevabot
def main(settings="settings.py", verbose=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging
    level = verbose if logging.DEBUG else logging.INFO
    logging.basicConfig(level=level, stream=sys.stdout, format=LOG_FORMAT)
    logger.info("Starting sevabot")

    for skype_logger_name in ["Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
                              "Skype4Py.api.darwin.SkypeAPI"]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    from sevabot.bot import modules

    modules.load_modules()

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    configure_api(server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0
예제 #5
0
파일: bot.py 프로젝트: Juraldinio/sevabot
    def handleMessages(self, msg, status):
        """
        Handle incoming messages
        """
        if status == "RECEIVED" or status == "SENT":
            logger.debug("%s - %s - %s: %s" % (status, msg.Chat.FriendlyName, msg.FromHandle, msg.Body))

        if status in ["RECEIVED", "SENT"] and msg.Body:

            body = msg.Body.encode("utf-8")

            # shlex dies on unicode on OSX with null bytes all over the string
            words = shlex.split(body, comments=False, posix=True)

            if len(words) < 0:
                return

            keyword = words[0]

            if not keyword.startswith("!"):
                return

            keyword = keyword[1:]

            logger.debug("Trying to identify keyword: %s" % keyword)

            # reload must be built in
            if keyword == "reload":
                commands = modules.load_modules()
                msg.Chat.SendMessage("Available commands: %s" % ", ".join(commands))
                return

            if modules.is_module(keyword):
                # Execute module asynchronously

                def callback(output):
                    msg.Chat.SendMessage(output)

                modules.run_module(keyword, words[1:], callback)
                return
            else:
                msg.Chat.SendMessage("Don't know about command: !" + keyword)

            # XXX: Deprecated. See if we can rid of this
            if body == "!loadChats":
                self.cacheChats()
                return
예제 #6
0
파일: handlers.py 프로젝트: mutoso/sevabot
 def builtin_reload(self, args, msg, status):
     """Reload command modules.
     """
     commands = modules.load_modules(self.sevabot)
     msg.Chat.SendMessage('Available commands: %s' % ', '.join(commands))
예제 #7
0
 def builtin_reload(self, args, msg, status):
     """Reload command modules.
     """
     msg.Chat.SendMessage('I alive: ')
     commands = modules.load_modules(self.sevabot)
     msg.Chat.SendMessage('Available commands: %s' % ', '.join(commands))
예제 #8
0
def main(settings="settings.py", verbose=False, daemon=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging

    level = getattr(logging,
                    getattr(settings, "LOG_LEVEL", "INFO").upper(), "INFO")

    logging.basicConfig(level=level,
                        stream=sys.stdout,
                        format=settings.LOG_FORMAT)

    # Setup logging file
    if getattr(settings, "LOG_FILE", None):
        if not settings.LOG_FILE.startswith("/"):
            log_path = settings.LOG_FILE
        else:
            log_path = os.path.join(os.path.dirname(settings.__file__),
                                    settings.LOG_FILE)

        formatter = logging.Formatter(settings.LOG_FORMAT)

        hdlr = logging.handlers.RotatingFileHandler(
            log_path,
            encoding="utf-8",
            maxBytes=settings.LOG_ROTATE_MAX_SIZE,
            backupCount=settings.LOG_ROTATE_COUNT)

        hdlr.setFormatter(formatter)

        logger.addHandler(hdlr)

    logger.info("Starting sevabot")

    for skype_logger_name in [
            "Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
            "Skype4Py.api.darwin.SkypeAPI"
    ]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    # Detach from the controlling terminal
    if daemon:
        create_daemon()

    from sevabot.bot import modules

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    modules.load_modules(sevabot)

    api.configure(sevabot, settings, server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0
예제 #9
0
 def builtin_reload(self, args, msg, status):
     """Reload command modules.
     """
     commands = modules.load_modules(self.sevabot)
예제 #10
0
 def builtin_reload(self, args, msg, status):
     """Reload command modules.
     """
     commands = modules.load_modules(self.sevabot)