示例#1
0
文件: bot.py 项目: rhorama/ircBot
 def listener(self):
     while 1:
         exitcode = f"bye {botnick}"
         reload_command = "reload environment"
         ircmsg = self.ircsock.recv(2048).decode("UTF-8")
         ircmsg = ircmsg.strip('\n\r')
         if ircmsg.find("PING :") != -1:
             self.ping()
         if ircmsg.find("PRIVMSG") != -1:
             name = ircmsg.split('!', 1)[0][1:]
             message = ircmsg.split('PRIVMSG', 1)[1].split(':', 1)[1]
             if len(name) < 17:
                 if name.lower() == adminname.lower():
                     if exitcode in message.rstrip():
                         print("exit code received")
                         self.ircsock.send("QUIT \n".encode())
                         return
                     if reload_command in message.rstrip():
                         print("reloading dotenv")
                         self.sendmsg("ok")
                         load_dotenv()
                 if message.startswith("!"):
                     mes = str(switchboard.main(
                         message.rstrip()))
                     if mes != "error" and mes != -1:
                         self.sendmsg(mes)
                 if message[:5].find('.tell') != -1:
                     target = message.split(' ', 1)[1]
                     if target.find(' ') != -1:
                         message = target.split(' ', 1)[1]
                         target = target.split(' ')[0]
                     else:
                         target = name
                         message = "Could not parse. The message should be in the format of ‘.tell [target] [message]’ to work properly."
                         self.sendmsg(message, target)
示例#2
0
def run_server(config, port=3000):
    """ """
    message_router = main(config)

    def switchboard_app(environ, start_response):
        request = Request(environ)
        if request.path == '/in':
            resp = do_incoming_message(request, message_router)
        else:
            resp = Response('Not found')
        return resp(environ, start_response)

    httpd = make_server('', port=port, app=switchboard_app)
    log.info('Starting server on port %s' % port)
    httpd.serve_forever()
示例#3
0
 def test_balance_french(self):
     msg = main('body=solde.1234')
     self.assertEqual(
         msg['classification']['name'], 'consummer-message-alphabetical')
     self.assertEqual(msg['route']['name'],
                      'check_circuit_balance')
示例#4
0
 def test_balance_numeric(self):
     msg = main('body=2.1234')
     self.assertEqual(
         msg['classification']['name'], 'consumer-message-numeric')
     self.assertEqual(
         msg['route']['name'], 'check_circuit_balance')
示例#5
0
 def test_run_main(self):
     msg = main(self.get_raw_message())
     self.assertIsInstance(msg, dict)