Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add fake IRC class to help tracking leaks

  • Loading branch information...
commit 9b47d394ad13f169f9c165a355ab6d98bc187b0f 1 parent 826a478
@rmmh authored
Showing with 62 additions and 13 deletions.
  1. +1 −1  bot.py
  2. +2 −2 core/db.py
  3. +46 −2 core/irc.py
  4. +13 −8 plugins/sieve.py
View
2  bot.py
@@ -32,7 +32,7 @@ class Bot(object):
if name in bot.conns:
print 'ERROR: more than one connection named "%s"' % name
raise ValueError
- bot.conns[name] = irc(conf['server'], conf['nick'],
+ bot.conns[name] = IRC(conf['server'], conf['nick'],
port=conf.get('port', 6667), channels=conf['channels'], conf=conf)
except Exception, e:
print 'ERROR: malformed config file', Exception, e
View
4 core/db.py
@@ -4,6 +4,6 @@
def get_db_connection(server, name='skybot.%s.db'):
"returns an sqlite3 connection to a persistent database"
filename = os.path.join(bot.persist_dir, name % server)
- return sqlite3.connect(filename)
+ return sqlite3.connect(filename, timeout=10)
-bot.get_db_connection = get_db_connection
+bot.get_db_connection = get_db_connection
View
48 core/irc.py
@@ -52,7 +52,7 @@ def recv_loop(self):
self.socket.close()
return
continue
-
+
while '\r\n' in self.ibuffer:
line, self.ibuffer = self.ibuffer.split('\r\n', 1)
self.iqueue.put(decode(line))
@@ -72,7 +72,7 @@ def send_loop(self):
irc_param_ref = re.compile(r'(?:^|(?<= ))(:.*|[^ ]+)').findall
-class irc(object):
+class IRC(object):
"handles the IRC protocol"
#see the docs/ folder for more information on the protocol
def __init__(self, server, nick, port=6667, channels=[], conf={}):
@@ -136,3 +136,47 @@ def cmd(self, command, params=None):
def send(self, str):
self.conn.oqueue.put(str)
+
+class FakeIRC(IRC):
+ "handles the IRC protocol"
+ #see the docs/ folder for more information on the protocol
+ def __init__(self, server, nick, port=6667, channels=[], conf={}, fn=""):
+ self.channels = channels
+ self.conf = conf
+ self.server = server
+ self.port = port
+ self.nick = nick
+
+ self.out = Queue.Queue() #responses from the server are placed here
+ # format: [rawline, prefix, command, params,
+ # nick, user, host, paramlist, msg]
+
+ self.f = open(fn, 'rb')
+
+ thread.start_new_thread(self.parse_loop, ())
+
+ def parse_loop(self):
+ while True:
+ msg = decode(self.f.readline()[9:])
+
+ if msg == '':
+ print "!!!!DONE READING FILE!!!!"
+ return
+
+ if msg.startswith(":"): #has a prefix
+ prefix, command, params = irc_prefix_rem(msg).groups()
+ else:
+ prefix, command, params = irc_noprefix_rem(msg).groups()
+ nick, user, host = irc_netmask_rem(prefix).groups()
+ paramlist = irc_param_ref(params)
+ lastparam = ""
+ if paramlist and paramlist[-1].startswith(':'):
+ lastparam = paramlist[-1][1:]
+ self.out.put([msg, prefix, command, params, nick, user, host,
+ paramlist, lastparam])
+ while self.out.qsize() > 5: time.sleep(.1)
+ if command == "PING":
+ self.cmd("PONG", [params])
+
+ def cmd(self, command, params=None):
+ pass
View
21 plugins/sieve.py
@@ -14,16 +14,21 @@ def sieve_suite(bot, input, func, args):
if input.nick.lower()[-3:] == 'bot' and args.get('ignorebots', True):
return None
- hook = args.get('hook', r'(.*)')
+ regex = args.get('re')
+ if not regex:
+ hook = args.get('hook', r'(.*)')
- if args.get('prefix', True):
- if input.chan == input.nick: # private message, prefix not required
- prefix = r'^(?:[.!]?|'
- else:
- prefix = r'^(?:[.!]|'
- hook = prefix + input.conn.nick + r'[:,]*\s)' + hook
+ if args.get('prefix', True):
+ if input.chan == input.nick: # private message, prefix not required
+ prefix = r'^(?:[.!]?|'
+ else:
+ prefix = r'^(?:[.!]|'
+ hook = prefix + input.conn.nick + r'[:,]*\s)' + hook
- input.re = re.match(hook, input.msg, flags=re.I)
+ regex = re.compile(hook, flags=re.I)
+ args['re'] = regex
+
+ input.re = regex.match(input.msg)
if input.re is None:
return None
Please sign in to comment.
Something went wrong with that request. Please try again.