def testHandle(self): b = self.init([FooHandler(), BarHandler()]) b.handle(base.Message(self.conn, base.User('username'), '!foo')) self.reply.assert_called_with('foo!') self.reply.reset_mock() b.handle(base.Message(self.conn, base.User('username'), 'not !foo')) self.reply.assert_not_called()
def run(self, on_event: base.EventCallback) -> None: # Because of the way input() works, we only exit the loop after being canceled and then # getting another line from the user. while not self._canceled.is_set(): m = base.Message(self, base.User('stdin'), input('> ')) logging.info(m) on_event(m)
def test_no_event(self): self.handler.data.set_subkey('total_time', '1234', '360') self.handler.data.set_subkey('legacy_time', 'olduser', '420') self.assert_response('!time', "@username You've spent 6 minutes in the chat.") self.assert_response('!time username', "@username You've spent 6 minutes in the chat.") self.assert_response('!time username', 'Username has spent 6 minutes in the chat.', user=base.User('another_user')) self.assert_response('!time olduser', 'olduser spent 7 minutes in the chat.')
def _message(self, input: str, user: Optional[base.User] = None): if not user: user = base.User('username') return base.Message(self.reply_conn, user, input)
def testCompoundUserOnly(self): cds = cooldown.GlobalAndUserCooldowns(None, datetime.timedelta(minutes=5)) self.assertTrue(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.assertTrue(cds.fire(base.User('alice'))) self.assertFalse(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.time.tick(59) self.assertFalse(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.assertFalse(cds.fire(base.User('alice'))) self.assertFalse(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.time.tick(1) self.assertFalse(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.assertFalse(cds.fire(base.User('alice'))) self.assertFalse(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob'))) self.assertTrue(cds.fire(base.User('bob'))) self.assertFalse(cds.peek(base.User('alice'))) self.assertFalse(cds.peek(base.User('bob'))) self.time.tick(4 * 60) self.assertTrue(cds.peek(base.User('alice'))) self.assertFalse(cds.peek(base.User('bob'))) self.time.tick(60) self.assertTrue(cds.peek(base.User('alice'))) self.assertTrue(cds.peek(base.User('bob')))
def __init__(self, event: Union[str, base.Event]) -> None: if isinstance(event, str): event = base.Message(self, base.User('username'), event) self.event = event
def testMessage(self): message = base.Message( reply_connection=TestConnection(), user=base.User('Alicia'), text='hi there') self.observer.observe(message) self.assertEqual(self.buffer.getvalue(), '[Test] <Alicia> hi there\n')
def _message(self, event: client.Event) -> base.Message: user = base.User(event.source.nick) return base.Message(self, user, event.arguments[0])