def start(self): # Initialize data store DatastoreController().set_driver(self.config.get('datastore')) Logger.set_loglevel(self.config.get('log.level')) for plugin in self.config.get('coreplugins'): Logger.info("Loading core plugin '%s'" % plugin) self.plugincontroller.load_plugin(plugin, 'core') for plugin in self.config.get('plugins'): Logger.info("Loading plugin '%s'" % plugin) self.plugincontroller.load_plugin(plugin) if len(self.config.get('ircnets')) == 0: raise Exception("There has to be at least one ircnet to connect to") for net in self.config.get('ircnets'): irc = IRCController(self.eventcontroller) irc.set_configuration(net) Logger.info("Connecting to %s..." % irc.get_ircnet_name()) irc.connect() self.ircnetscontroller.add_ircnet(irc.get_ircnet_name(), irc)
def __init__(self): self.event = EventController() self.plugin = PluginController() # Make sure the simulated user have access to all commands ConfigController().get('masters').append('*!*@*') ConfigController().set('irc.rate_limit_wait_time', 0) # Configuration # This must match the values in SimulatedIRCNetworkClient simulated_ircnet = { "ircnet": "SimuNet", "nick": "NeuBot", "altnicks": [], "name": "Simulated Bot", "ident": "neubot", "servers": [ ("irc.example.org", 6667, False, False), ], "channels": [ ("#simulator", None), ] } # Initiate the IRCController and tell it to use our fake clientclass # so that it won't actually connect to a real server irc = IRCController(self.event, clientclass = SimulatedIRCNetworkClient) irc.set_configuration(simulated_ircnet) # Register server with ircnetscontroller IRCNetsController().add_ircnet(irc.get_ircnet_name(), irc) self._irc = irc # Initialize datastore DatastoreController().set_driver("data/simulator.db")
def setUp(self): self._event_controller = FakeEventController() self._irc = IRCController(self._event_controller, clientclass = IRCNetworkClientMock) # Setup IRCController fakeserver = Server("foo", 6667) self._irc.add_server(fakeserver) self._irc._ircnet = "FakeIRCNet" self._irc._nick = "Nick" self._irc._name = "Name" self._irc._ident = "Ident" # "connect" self._irc.connect() # Make sure the buffer is clear self._irc.flush_output() self._irc._connection.clear()
class TestIRCController(unittest.TestCase): def setUp(self): self._event_controller = FakeEventController() self._irc = IRCController(self._event_controller, clientclass = IRCNetworkClientMock) # Setup IRCController fakeserver = Server("foo", 6667) self._irc.add_server(fakeserver) self._irc._ircnet = "FakeIRCNet" self._irc._nick = "Nick" self._irc._name = "Name" self._irc._ident = "Ident" # "connect" self._irc.connect() # Make sure the buffer is clear self._irc.flush_output() self._irc._connection.clear() def tearDown(self): self._irc.disconnect() def testMessageOrdering(self): # Send some messages and wait for them to be sent to # our stubbed socket self._irc.privmsg("Foo", "C") self._irc.privmsg("Foo", "A") self._irc.privmsg("Foo", "B") self._irc.flush_output() expected = [ 'PRIVMSG Foo :C\r\n', 'PRIVMSG Foo :A\r\n', 'PRIVMSG Foo :B\r\n', ] self.assertEqual(self._irc._connection.get_data(), expected) def testMessagePriorities(self): self._irc.privmsg("Foo", "B") self._irc.quit("Quit now") self._irc.privmsg("Foo", "A") self._irc.flush_output() expected = [ 'QUIT :Quit now\r\n', 'PRIVMSG Foo :B\r\n', 'PRIVMSG Foo :A\r\n', ] self.assertEqual(self._irc._connection.get_data(), expected)