예제 #1
0
파일: app.py 프로젝트: nanonyme/nanobot
def handleCommand(protocol, user, channel, message, max_line_length,
                  callback):
    command, _, suffix = message.partition(" ")
    with sqlite3.connect(config["core"]["db"]) as conn:
        cur = conn.cursor()
        res = cur.execute(user_query, (user,))
        roles = [role[0] for role in res.fetchmany()]
        if command == "reincarnate":
            if "superadmin" in roles:
                log.info("Restarting app")
                reactor.stop()
            else:
                log.info("User {user} tried to do code reload", user=user)
        elif command == "eval":
            truth, expr = suffix.split(":")
            truth = [s.strip() for s in truth.split(",")]
            try:
                ret = simple_eval.eval_bool(expr, truth)
            except simple_eval.EvalError as e:
                callback(str(e))
            else:
                callback("Result: %s" % ret)
        elif command == "join":
            channel, _, password = suffix.partition(" ")
            if not password:
                password = None
            if "superadmin" in roles:
                if password:
                    log.info("Joining {channel} ({password})",
                             channel=channel, password=password)
                else:
                    log.info("Joining {channel}", channel=channel)
                return protocol.callRemote("join", channel, password)
        elif command == "leave":
            channel, _, reason = suffix.partition(" ")
            if not reason:
                reason = None
            if "superadmin" in roles:
                if reason:
                    log.info("Leaving {channel} ({reason})",
                             channel=channel, reason=reason)
                else:
                    log.info("Leaving {channel}", channel=channel)
                return protocol.callRemote("leave", channel, reason)
        else:
            log.info("Unrecognized command {command}", command=command)
예제 #2
0
 def test_simple_false(self):
     self.assertFalse(simple_eval.eval_bool("foo", ("bar",)))
예제 #3
0
 def test_simple_true(self):
     self.assertTrue(simple_eval.eval_bool("foo", ("foo",)))
예제 #4
0
 def test_bad_legal(self):
     with self.assertRaisesRegex(ValueError,
                                 "Invalid token & at position 2"):
         simple_eval.eval_bool("a&&b", ())
예제 #5
0
 def test_bad_legal(self):
     with self.assertRaisesRegexp(ValueError, "Invalid token & at position 2"):
         simple_eval.eval_bool("a&&b", ())
예제 #6
0
 def test_demorgan(self):
     expr = "~(foo&bar)&~(~foo|~bar)"
     self.assertFalse(simple_eval.eval_bool(expr, 
                                            ("foo", "bar")
                                            )
                      )
예제 #7
0
 def test_true_or_true(self):
     self.assertTrue(simple_eval.eval_bool("foo|bar", ("foo", "bar")))
예제 #8
0
 def test_not_false(self):
     self.assertTrue(simple_eval.eval_bool("~foo", ()))
예제 #9
0
 def test_false_or_true(self):
     self.assertTrue(simple_eval.eval_bool("foo|bar", ("bar", )))
예제 #10
0
 def test_not_false(self):
     self.assertTrue(simple_eval.eval_bool("~foo", ()))
예제 #11
0
 def test_not_true(self):
     self.assertFalse(simple_eval.eval_bool("~foo", ("foo", )))
예제 #12
0
 def test_false_and_true(self):
     self.assertFalse(simple_eval.eval_bool("foo&bar", ("bar", )))
예제 #13
0
 def test_simple_false(self):
     self.assertFalse(simple_eval.eval_bool("foo", ("bar", )))
예제 #14
0
 def test_simple_true(self):
     self.assertTrue(simple_eval.eval_bool("foo", ("foo", )))
예제 #15
0
 def test_false_and_true(self):
     self.assertFalse(simple_eval.eval_bool("foo&bar", ("bar",)))
예제 #16
0
 def test_true_or_true(self):
     self.assertTrue(simple_eval.eval_bool("foo|bar", ("foo", "bar")))
예제 #17
0
 def test_not_true(self):
     self.assertFalse(simple_eval.eval_bool("~foo", ("foo", )))
예제 #18
0
 def test_false_or_false(self):
     self.assertFalse(simple_eval.eval_bool("foo|bar", ()))
예제 #19
0
 def test_false_or_true(self):
     self.assertTrue(simple_eval.eval_bool("foo|bar", ("bar", )))
예제 #20
0
 def test_demorgan(self):
     expr = "~(foo&bar)&~(~foo|~bar)"
     self.assertFalse(simple_eval.eval_bool(expr, ("foo", "bar")))
예제 #21
0
 def test_false_or_false(self):
     self.assertFalse(simple_eval.eval_bool("foo|bar", ()))
예제 #22
0
 def test_bad_input_illegal(self):
     with self.assertRaisesRegex(ValueError,
                                 "Invalid token / at position 4"):
         simple_eval.eval_bool("aef&//&||", ())
예제 #23
0
 def test_bad_input(self):
     with self.assertRaises(ValueError):
         simple_eval.eval_bool("aef&//&||", ())
예제 #24
0
 def test_bad_input_illegal(self):
     with self.assertRaisesRegexp(ValueError, "Invalid token / at position 4"):
         simple_eval.eval_bool("aef&//&||", ())