class TestTricks(unittest.TestCase): def setUp(self): self.bot = Bot("test", Inventory(), get_commands()) def test_yoda(self): self.assertIn(self.bot.parse_message("test yoda Justin is lame")[0], ["Lame, justin is", "Sorry I can only translate 5 times per hour"]) def test_pick(self): result = self.bot.parse_message("test pick jason justin mat") self.assertIn(result[0], ["jason", "justin", "mat"]) def test_hello(self): result = self.bot.parse_message("test hello") self.assertEqual(result[0], "Wazzup") def test_the_rules(self): result = self.bot.parse_message("test the_rules") self.assertEqual("""The rules are: 1. A robot may not injure a human being or, through inaction, allow a human being to come to harm. 2. A robot must obey orders given it by human beings except where such orders would conflict with the First Law. 3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.""", result[0])
def run(name, connector): """Run the bot. By default will run with the first available connector. """ conn = None available = get_connectors() for c in available: if c.name == connector: conn = c.load() commands = get_commands() print('comm', commands) bot = Bot(name, conn, commands) bot.run()
def run(name, connector, inventory): """Run the bot. By default will run with the first available connector. """ connectors = get_connectors() if len(connectors) == 0: print("ERROR: No available connectors!") os.exit(1) conn_pkg = None for c in connectors: if c.name == connector: conn_pkg = c.load() if conn_pkg is None: conn_pkg = connectors[0].load() inventories = get_inventories() if len(inventories) == 0: print("ERROR: No available inventories!") os.exit(1) for i in inventories: if i.name == inventory: inventory_pkg = i.load() commands = get_commands() inventory = inventory_pkg.Inventory() bot = Bot(name, inventory, commands) connector = conn_pkg.Connector(bot) print("Listening for messages...") connector.listen()
def commands(): """Show all installed commands.""" import chattie.connectors.term as term bot = Bot('Chattie', term, get_commands()) print(helpcmd(bot, ''))
def setUp(self): self.bot = Bot("test", Inventory(), get_commands())