Ejemplo n.º 1
0
def main():
	global message_manager, stopping, throttle

	parser = argparse.ArgumentParser()
	parser.add_argument("host")
	parser.add_argument("port")
	parser.add_argument('--node', choices=['remote', 'local'], nargs=1, type=str, required=True)

	#node now contains the string value 'remote' or 'local'
	args = parser.parse_args()
	node = args.node[0]
	host = args.host
	port = int(args.port)

	if node == 'remote':
		throttle = 0.1
		message_manager = MessageManager(host, port, slave=True)

	else:
		message_manager = MessageManager(host, port)
		bootstrap_phase()

	hardware_monitor()
	processing_phase()

	if node == 'remote':
		message_manager.shutdown()
Ejemplo n.º 2
0
class ClientConnection(SockJSConnection):
    def __init__(self, *args, **kwargs):
        super(ClientConnection, self).__init__(*args, **kwargs)
        self.clients = ClientManager(application=app, handler=self)
        self.messages = MessageManager(application=app, handler=self)

    def on_open(self, info):
        client = self.clients.append(self, info)
        if client and not client.user:
            return self.send(self.messages.error_message("auth.error"))

    def on_message(self, msg):
        client = self.clients[self]
        self.messages.handle_message(client, msg)

    def on_close(self):
        self.clients.remove(self)
Ejemplo n.º 3
0
    def __init__(self, chat_id: int, token: str):
        self.chat_id = chat_id
        self.token = token
        self.updater = Updater(self.token)

        # Initiate the managers
        self.msg_mng = MessageManager(self)
        self.comm_mng = CommandManager(self)
        self.daemon_mng = DaemonManager(self)
Ejemplo n.º 4
0
def main():
    global message_manager, stopping, throttle

    parser = argparse.ArgumentParser()
    parser.add_argument("host")
    parser.add_argument("port")
    parser.add_argument('--node',
                        choices=['remote', 'local'],
                        nargs=1,
                        type=str,
                        required=True)

    #node now contains the string value 'remote' or 'local'
    args = parser.parse_args()
    node = args.node[0]
    host = args.host
    port = int(args.port)

    if node == 'remote':
        throttle = 0.1
        message_manager = MessageManager(host, port, slave=True)

    else:
        message_manager = MessageManager(host, port)
        bootstrap_phase()

    hardware_monitor()
    processing_phase()

    if node == 'remote':
        message_manager.shutdown()
Ejemplo n.º 5
0
    def __init__(self, streamUrl):

        # Create the driver
        self.driver = webdriver.Firefox()
        self.driver.get(streamUrl)

        # Give the driver a chance to connect
        time.sleep(2)

        self.authUsers = []
        self.commands = {}

        self.messageManager = MessageManager(getMessages(self.driver))
        self.messageLog = []
        self.lastMessageScrape = []
Ejemplo n.º 6
0
class DazBot(object):
    def __init__(self, streamUrl):

        # Create the driver
        self.driver = webdriver.Firefox()
        self.driver.get(streamUrl)

        # Give the driver a chance to connect
        time.sleep(2)

        self.authUsers = []
        self.commands = {}

        self.messageManager = MessageManager(getMessages(self.driver))
        self.messageLog = []
        self.lastMessageScrape = []

    def addAuthorizedUser(self, username):
        if username not in self.authUsers:
            self.authUsers.append(username)

    def addCommand(self, command, message):
        if command not in self.commands.keys():
            self.commands[command] = message

    def parseMessage(self, message):
        if message.message in self.commands.keys() and message.username in self.authUsers:
            sendMessage(self.driver, self.commands[message.message])

    def findMessageMatchPoint(self, scrapedMessages):
        # Find find the index to current message match point, start by iterating backwards through the log
        for logIdx in range(len(self.messageLog) - 1, -1, -1):

            # Compare against the messages in the last grab
            for msgIdx in range(0, len(scrapedMessages)):

                # If the username and message are the same, we have a tentative match
                if compareMessages(self.messageLog[logIdx], scrapedMessages[msgIdx]):
                    return msgIdx

        return 0

    def checkForMessages(self):
        newMessages = self.messageManager.processMessages(getMessages(self.driver))

        for msg in newMessages:
            self.parseMessage(msg)
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super(ClientConnection, self).__init__(*args, **kwargs)
     self.clients = ClientManager(application=app, handler=self)
     self.messages = MessageManager(application=app, handler=self)