diff --git a/piebot/__init__.py b/piebot/__init__.py new file mode 100644 index 0000000..7aa4c7b --- /dev/null +++ b/piebot/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .bot import ConnectionManager diff --git a/piebot/bot.py b/piebot/bot.py index 69644ad..176225b 100644 --- a/piebot/bot.py +++ b/piebot/bot.py @@ -4,7 +4,7 @@ import asyncio import inspect import logging -import irc +from . import irc logging.basicConfig(format="[%(asctime)s] [%(levelname)s] %(message)s", level=logging.DEBUG, datefmt="%d.%m.%Y %H:%M:%S") logger = logging.getLogger(__name__) @@ -176,30 +176,3 @@ class ConnectionManager(object): self.remove_endpoint((host, port)) else: loop.call_exception_handler(context) - - -if __name__ == "__main__": - loop = asyncio.get_event_loop() - - connection_manager = ConnectionManager(loop) - connection_manager.add_endpoint(("irc.euirc.net", 6667), { - "encoding": "utf-8", - "nick": "Pb42", - "ident": "foobar2000", - "realname": "Baz McBatzen", - "channels": ["#botted"] - }) - connection_manager.add_endpoint(("irc.freenode.net", 6667), { - "encoding": "utf-8", - "nick": "Pb42", - "ident": "foobar2000", - "realname": "Baz McBatzen", - "channels": ["#botted"] - }) - - try: - loop.run_forever() - except KeyboardInterrupt: - pass - finally: - loop.close() diff --git a/piebot/irc.py b/piebot/irc.py index c8ae878..37ed260 100644 --- a/piebot/irc.py +++ b/piebot/irc.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- def parse(line): + """ This is the basic irc line parser function. + """ prefix = "" subject = "" trailing = "" @@ -309,4 +311,4 @@ class Numeric005(Message, metaclass=register_derivative): super().__init__(*args, **kwargs) def parse(self): - pass \ No newline at end of file + pass diff --git a/run.py b/run.py new file mode 100644 index 0000000..4121574 --- /dev/null +++ b/run.py @@ -0,0 +1,29 @@ +import asyncio +from piebot import ConnectionManager + +loop = asyncio.get_event_loop() + +# TODO: Move configuration into a config file! +connection_manager = ConnectionManager(loop) +connection_manager.add_endpoint(("irc.euirc.net", 6667), { + "encoding": "utf-8", + "nick": "Pb42", + "ident": "foobar2000", + "realname": "Baz McBatzen", + "channels": ["#botted"] +}) +connection_manager.add_endpoint(("irc.freenode.net", 6667), { + "encoding": "utf-8", + "nick": "Pb42", + "ident": "foobar2000", + "realname": "Baz McBatzen", + "channels": ["#botted"] +}) + +try: + loop.run_forever() +except KeyboardInterrupt: + pass +finally: + loop.close() +