Merge branch 'master' of /home/neale/public_html/repos/firebot

This commit is contained in:
Neale Pickett 2007-10-04 16:09:40 -06:00
commit 1fab271cf9
6 changed files with 88 additions and 51 deletions

4
README
View File

@ -20,9 +20,9 @@ FireBot's name. Example:
Downloading Downloading
----------- -----------
You can download a [tarball snapshot of the latest release](http://woozle.org/~neale/projects/?p=firebot;a=snapshot;h=HEAD), or use cogito: You can download a [tarball snapshot of the latest release](http://woozle.org/~neale/repos/?p=firebot;a=snapshot;h=HEAD), or use cogito:
cg-clone http://woozle.org/~neale/projects/firebot git clone http://woozle.org/~neale/repos/firebot
LinkBot Features LinkBot Features

View File

@ -11,19 +11,37 @@ import os
import time import time
import socket import socket
def esc(arg):
return "'" + arg.replace("'", r"'\''") + "'"
def lesc(args):
return [esc(arg) for arg in args]
class Arsenic(firebot.FireBot, ProcBot): class Arsenic(firebot.FireBot, ProcBot):
debug = True debug = False
bindings = [] bindings = []
ping_interval = 120 ping_interval = 120
chatty = False # #x can't play nice
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
firebot.FireBot.__init__(self, *args, **kwargs) firebot.FireBot.__init__(self, *args, **kwargs)
self.seen = {} self.seen = {}
self.lusers = {} self.lusers = {}
self.heartbeat_interval=3 self.heartbeat_interval=0.01
self.lag = 0 self.lag = 0
self.whinecount = 0 self.whinecount = 0
def runcmd(self, sender, forum, addl, match):
command = match.group('command')
args = lesc(match.group('args').split(' '))
argstr = ' '.join(args)
Runner('%s %s' % (command, argstr),
lambda l,r: self.proc_cb('%s: ' % command, sender, forum, l, r))
bindings.append((re.compile(r"^(?P<command>whois) +(?P<args>.*)$"),
runcmd))
bindings.append((re.compile(r"^(?P<command>host) +(?P<args>.*)$"),
runcmd))
def rp(self, sender, forum, addl, match): def rp(self, sender, forum, addl, match):
command = 'rp' command = 'rp'
argstr = match.group('args') argstr = match.group('args')
@ -52,7 +70,6 @@ class Arsenic(firebot.FireBot, ProcBot):
what = match.group('what') what = match.group('what')
when = time.time() when = time.time()
key = '\013notes:%s' % whom key = '\013notes:%s' % whom
print key
note = (when, sender.name(), what) note = (when, sender.name(), what)
try: try:
n = self.db[key] n = self.db[key]
@ -78,17 +95,17 @@ class Arsenic(firebot.FireBot, ProcBot):
# get back into invite-only channels after a disconnect. # get back into invite-only channels after a disconnect.
who = luser.name() who = luser.name()
self.lusers[channel.name()][who] = luser self.lusers[channel.name()][who] = luser
for chan in self.lusers.keys(): for chan, l in self.lusers.iteritems():
if chan == channel.name(): if chan == channel.name():
continue continue
t = self.lusers[chan].get(who) t = l.get(who)
if t and t.host == luser.host: if t and t.host == luser.host:
self.write('INVITE %s %s' % (who, chan)) self.write(['INVITE', who, chan])
def cmd_join(self, sender, forum, addl): def cmd_join(self, sender, forum, addl):
if sender.name() == self.nick: if sender.name() == self.nick:
# If it was me, get a channel listing and beg for ops # If it was me, get a channel listing and beg for ops
self.write('WHO %s' % (forum.name())) self.write(['WHO', forum.name()])
forum.notice('If you op me, I will op everyone who joins this channel.') forum.notice('If you op me, I will op everyone who joins this channel.')
self.lusers[forum.name()] = {} self.lusers[forum.name()] = {}
else: else:
@ -108,10 +125,10 @@ class Arsenic(firebot.FireBot, ProcBot):
def cmd_pong(self, sender, forum, addl): def cmd_pong(self, sender, forum, addl):
now = time.time() now = time.time()
print now
self.lag = now - float(addl[0]) self.lag = now - float(addl[0])
def cmd_482(self, sender, forum, addl): def cmd_482(self, sender, forum, addl):
forum = self.recipient(addl[0])
self.whinecount += 1 self.whinecount += 1
if (self.whinecount == 2 or if (self.whinecount == 2 or
self.whinecount == 4 or self.whinecount == 4 or
@ -123,6 +140,15 @@ class Arsenic(firebot.FireBot, ProcBot):
if __name__ == '__main__': if __name__ == '__main__':
import daemon
debug = False
if not debug:
# Become a daemon
log = file('arsenic.log', 'a')
daemon.daemon('arsenic.pid', log, log)
# Short URL server # Short URL server
us = shorturl.start(('', 0)) us = shorturl.start(('', 0))
firebot.URLSERVER = (socket.gethostbyaddr(socket.gethostname())[0], firebot.URLSERVER = (socket.gethostbyaddr(socket.gethostname())[0],
@ -131,10 +157,11 @@ if __name__ == '__main__':
NICK = ['arsenic'] NICK = ['arsenic']
INFO = "I'm a little printf, short and stdout" INFO = "I'm a little printf, short and stdout"
l1 = Arsenic(('greywolf.lanl.gov', 6697), l1 = Arsenic(('irc.lanl.gov', 6667),
NICK, NICK,
INFO, INFO,
["#x"], ["#x"],
ssl=True) ssl=False)
l1.debug = debug
irc.run_forever() irc.run_forever(0.01)

View File

@ -48,7 +48,6 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
infobot.InfoBot.__init__(self, host, nicks, gecos, channels, infobot.InfoBot.__init__(self, host, nicks, gecos, channels,
dbname=dbname, **kwargs) dbname=dbname, **kwargs)
self.ssl = ssl self.ssl = ssl
self.nosy = True
self.seen = {} self.seen = {}
def handle_connect(self): def handle_connect(self):

View File

@ -12,6 +12,7 @@ class InfoBot(BindingsBot):
msg_cat = {} msg_cat = {}
msg_cat.update(BindingsBot.msg_cat) msg_cat.update(BindingsBot.msg_cat)
bindings = [] bindings = []
chatty = True
def __init__(self, host, nicks, gecos, channels, dbname='info.cdb'): def __init__(self, host, nicks, gecos, channels, dbname='info.cdb'):
BindingsBot.__init__(self, host, nicks, gecos, channels) BindingsBot.__init__(self, host, nicks, gecos, channels)
@ -186,6 +187,9 @@ class InfoBot(BindingsBot):
# Look something up in the DB # Look something up in the DB
def lookup(self, sender, forum, addl, match): def lookup(self, sender, forum, addl, match):
if not self.chatty:
if not match.group('me'):
return True
key = match.group('key') key = match.group('key')
# Try looking it up verbatim # Try looking it up verbatim
@ -218,6 +222,7 @@ class InfoBot(BindingsBot):
resp = False resp = False
old = self.getall(key) old = self.getall(key)
okay = self.gettext('okay', sender=sender.name()) okay = self.gettext('okay', sender=sender.name())
try:
if old: if old:
if val in old: if val in old:
if me: if me:
@ -246,6 +251,9 @@ class InfoBot(BindingsBot):
else: else:
self.set(key, (val,)) self.set(key, (val,))
resp = okay resp = okay
except seedyb.Locked:
resp = self.gettext('locked', key=key,
sender=sender.name())
if resp: if resp:
if me: if me:

23
irc.py
View File

@ -292,6 +292,9 @@ class SmartIRCHandler(IRCHandler):
""" """
def recipient(self, name):
return recipient(self, name)
def err(self, exception): def err(self, exception):
if self.debug: if self.debug:
traceback.print_exception(*exception) traceback.print_exception(*exception)
@ -349,14 +352,14 @@ class SmartIRCHandler(IRCHandler):
# PRIVMSG ['neale!~user@127.0.0.1', 'PRIVMSG', 'firebot'] firebot, foo # PRIVMSG ['neale!~user@127.0.0.1', 'PRIVMSG', 'firebot'] firebot, foo
try: try:
if args[2][0] in '#&': if args[2][0] in '#&':
forum = recipient(self, args[2]) forum = self.recipient(args[2])
else: else:
forum = sender forum = sender
addl = (text,) addl = (text,)
except IndexError: except IndexError:
addl = (text, args[1]) addl = (text, args[1])
elif op in ("CPRIVMSG", "CNOTICE"): elif op in ("CPRIVMSG", "CNOTICE"):
forum = recipient(self, args[2]) forum = self.recipient(args[2])
splits = text.split(" ") splits = text.split(" ")
if splits[0] == "DCC": if splits[0] == "DCC":
op = "DC" + op op = "DC" + op
@ -364,16 +367,16 @@ class SmartIRCHandler(IRCHandler):
else: else:
addl = (splits[0],) + tuple(splits[1:]) addl = (splits[0],) + tuple(splits[1:])
elif op in ("KICK",): elif op in ("KICK",):
forum = recipient(self, args[2]) forum = self.recipient(args[2])
addl = (recipient(self, args[3]), text) addl = (self.recipient(args[3]), text)
elif op in ("MODE",): elif op in ("MODE",):
forum = recipient(self, args[2]) forum = self.recipient(args[2])
addl = args[3:] addl = args[3:]
elif op in ("JOIN", "PART"): elif op in ("JOIN", "PART"):
try: try:
forum = recipient(self, args[2]) forum = self.recipient(args[2])
except IndexError: except IndexError:
forum = recipient(self, text) forum = self.recipient(text)
elif op in ("QUIT",): elif op in ("QUIT",):
addl = (text,) addl = (text,)
elif op in ("PING", "PONG"): elif op in ("PING", "PONG"):
@ -389,12 +392,12 @@ class SmartIRCHandler(IRCHandler):
# Apparently there are two different standards for this # Apparently there are two different standards for this
# command. # command.
if text: if text:
sender = recipient(self, text) sender = self.recipient(text)
else: else:
sender = recipient(self, args[2]) sender = self.recipient(args[2])
addl = (unpack_nuhost(args)[0],) addl = (unpack_nuhost(args)[0],)
elif op in ("INVITE",): elif op in ("INVITE",):
forum = recipient(self, text) forum = self.recipient(text)
else: else:
try: try:
int(op) int(op)

View File

@ -131,16 +131,16 @@ class SeedyB:
## ##
def lock(self, key): def lock(self, key):
self.set(key, [''], special='lock') self.set(key, ['locked'], special='lock')
def unlock(self, key): def unlock(self, key):
self.set(key, [], special='lock') self.set(key, [], special='lock')
def is_locked(self, key): def is_locked(self, key):
l = self.get(key, special='lock') l = self.get(key, special='lock')
if l: if l is None:
return True
return False return False
return True
open = SeedyB open = SeedyB