diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-06-16 00:56:55 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-06-16 00:56:55 +0100 |
commit | d30ffb7b1490eb12feb6041be84c44d115f22b0c (patch) | |
tree | 2a038cd7555684af7afa4bfeeff06b8fff3cbdce /columbo/__init__.py | |
download | columbo-master.tar.gz columbo-master.tar.xz columbo-master.zip |
Diffstat (limited to 'columbo/__init__.py')
-rw-r--r-- | columbo/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/columbo/__init__.py b/columbo/__init__.py new file mode 100644 index 0000000..6318e6d --- /dev/null +++ b/columbo/__init__.py @@ -0,0 +1,24 @@ +from . import irc_client +from dataclasses import dataclass +import irctokens +import trio + +@dataclass +class Config: + clients: list[irc_client.Config] + +async def start(config): + async with trio.open_nursery() as nursery: + channel, inbox = trio.open_memory_channel(0) + for client in config.clients: + nursery.start_soon(irc_client.connect, client, channel) + async for source, line in inbox: + outbox, client = source + print(f'Got line: {line.format()}') + reply_target = None + if line.params[0] == client.current_nick: + reply_target = line.hostmask.nickname + elif line.params[1].startswith(','): + reply_target = line.params[0] + if reply_target: + await outbox.send(irctokens.build('PRIVMSG', [reply_target, f'Hi {line.hostmask.nickname}'])) |