|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- coding: utf-8 -*-
-
- ## Imports
- from config.irc import *
- from config.watcher import *
-
- from irc.connection import Connection
- from irc.rc import RC
-
- global frontend_conn
-
- def get_connection():
- connection = Connection(WATCHER_HOST, WATCHER_PORT, NICK, IDENT, REALNAME)
- return connection
-
- def main(connection, f_conn):
- global frontend_conn
- frontend_conn = f_conn
- connection.connect()
- read_buffer = str()
-
- while 1:
- try:
- read_buffer = read_buffer + connection.get()
- except RuntimeError: # socket broke
- return
-
- lines = read_buffer.split("\n")
- read_buffer = lines.pop()
-
- for line in lines:
- line = line.strip().split()
-
- if line[1] == "PRIVMSG":
- chan = line[2]
- if chan != WATCHER_CHAN: # if we're getting a msg from another channel, ignore it
- continue
-
- msg = ' '.join(line[3:])[1:]
- rc = RC(msg) # create a new RC object to store this change's data
- rc.parse()
- check(rc)
-
- if line[0] == "PING": # If we are pinged, pong back to the server
- connection.send("PONG %s" % line[1])
-
- if line[1] == "376": # Join the recent changes channel when we've finished starting up
- connection.join(WATCHER_CHAN)
-
- def check(rc):
- """check if we're supposed to report this message anywhere"""
- results = process(rc) # process the message in config/watcher.py, and get a list of channels to send it to
- if not results:
- return
- pretty = rc.get_pretty()
- for chan in results:
- frontend_conn.say(chan, pretty)
|