summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Sherson <caretaker82@euclid.shersonb.net>2014-02-09 13:24:29 -0800
committerBrian Sherson <caretaker82@euclid.shersonb.net>2014-02-09 13:24:29 -0800
commit0796b792efad1d9ec86f53a0a3988c29d6d6683b (patch)
tree8114dca92448d46f593676b8cfb2b945f2746cf5
parent235f8e0964503bbb71a1a9fba17b9c9b7aa791e9 (diff)
Merged NickServ functionality into Autoexec, added autorejoin on reconnect functionality for when connections are lost unexpectedly
-rw-r--r--autoexec.py141
1 files changed, 78 insertions, 63 deletions
diff --git a/autoexec.py b/autoexec.py
index 978501e..a699099 100644
--- a/autoexec.py
+++ b/autoexec.py
@@ -1,82 +1,97 @@
#!/usr/bin/python
import re
import irc
+import fnmatch
+
+
+def AutoexecReload(old_ax):
+ ax = Autoexec()
+ for (context, conf) in old_ax.networks.items():
+ context.rmAddon(old_ax)
+ context.addAddon(ax, **conf.__dict__)
+ return ax
class Autoexec(object):
+
def __init__(self):
self.networks = {}
+ self._rejoinchannels = {}
+ # Saved channels for when a connection is lost
- def onAddonAdd(self, IRC, label, onconnect=None, onregister=None, autojoin=None, usermodes=None, wallet=None, opername=None, opermodes=None, snomasks=None, operexec=None, operjoin=None):
- labels = [v[0] for v in self.networks.values()]
+ def onAddonAdd(self, context, label, onconnect=None, onregister=None, autojoin=None, usermodes=None, nsautojoin=None, nsmatch=None, wallet=None, opername=None, opermodes=None, snomasks=None, operexec=None, operjoin=None, autorejoin=True):
+ labels = [v.label for v in self.networks.values()]
if label in labels:
- raise BaseException("Label already exists")
- if IRC in self.networks.keys():
- raise BaseException("Network already exists")
- self.networks[IRC] = (label, onconnect, onregister, autojoin, usermodes, wallet, opername, opermodes, snomasks, operexec, operjoin)
-
- def onAddonRem(self, IRC):
- del self.networks[IRC]
-
- def onConnect(self, IRC):
- (label, onconnect, onregister, autojoin, usermodes, wallet, opername, opermodes, snomasks, operexec, operjoin) = self.networks[IRC]
- if onconnect:
- for line in onconnect:
- IRC.raw(line, origin=self)
+ raise BaseException, "Label already exists"
+ if context in self.networks.keys():
+ raise BaseException, "Network already exists"
+ self.networks[context] = irc.Config(
+ label=label, onconnect=onconnect, onregister=onregister, autojoin=irc.ChanList(
+ autojoin, context=context),
+ usermodes=usermodes, nsautojoin=irc.ChanList(nsautojoin, context=context), nsmatch=nsmatch, wallet=wallet,
+ opername=opername, opermodes=opermodes, snomasks=snomasks, operexec=operexec, operjoin=irc.ChanList(operjoin, context=context), autorejoin=autorejoin)
+ self._rejoinchannels[context] = None
- def onRegistered(self, IRC):
- (label, onconnect, onregister, autojoin, usermodes, wallet, opername, opermodes, snomasks, operexec, operjoin) = self.networks[IRC]
- if onregister:
- for line in onregister:
- IRC.raw(line, origin=self)
- if usermodes:
- IRC.raw("MODE %s %s"%(IRC.identity.nick, usermodes), origin=self)
- if opername and wallet and "%s/opers/%s"%(label, opername) in wallet.keys():
- IRC.raw("OPER %s %s"%(opername, wallet[
- "%s/opers/%s"%(label, opername)]), origin=self)
- if autojoin:
- IRC.raw("JOIN %s"%(",".join(autojoin)), origin=self)
+ def onDisconnect(self, context, expected):
+ conf = self.networks[context]
+ if conf.autorejoin and not expected and context.identity:
+ self._rejoinchannels[context] = irc.ChanList(
+ context.identity.channels, context=context) # Store a *copy* of the list of channels
- def on381(self, IRC, line, origin, target, params, extinfo):
- (label, onconnect, onregister, autojoin, usermodes, wallet, opername, opermodes, snomasks, operexec, operjoin) = self.networks[IRC]
- if operexec:
- for line in operexec:
- IRC.raw(line, origin=self)
- if opermodes:
- IRC.raw("MODE %s %s"%(IRC.identity.nick, opermodes), origin=self)
- if snomasks:
- IRC.raw("MODE %s +s %s"%(IRC.identity.nick, snomasks), origin=self)
- if operjoin:
- IRC.raw("JOIN %s"%(",".join(operjoin)), origin=self)
+ def onAddonRem(self, context):
+ del self.networks[context], self._rejoinchannels[context]
+ def onConnect(self, context):
+ conf = self.networks[context]
+ if conf.onconnect:
+ for line in conf.onconnect:
+ context.raw(line, origin=self)
-class NickServ(object):
- def __init__(self):
- self.networks = {}
-
- def onAddonAdd(self, IRC, label, wallet=None, autojoin=None):
- labels = [v[0] for v in self.networks.values()]
- #print labels
- if label in labels:
- raise BaseException("Label already exists")
- if IRC in self.networks.keys():
- raise BaseException("Network already exists")
- self.networks[IRC] = (label, wallet, autojoin)
+ def onRegistered(self, context):
+ conf = self.networks[context]
+ if conf.onregister:
+ for line in conf.onregister:
+ context.raw(line, origin=self)
+ if conf.usermodes:
+ context.raw("MODE %s %s" %
+ (context.identity.nick, conf.usermodes), origin=self)
+ if conf.opername and conf.wallet and "%s/opers/%s" % (conf.label, conf.opername) in conf.wallet.keys():
+ context.raw("OPER %s %s" %
+ (conf.opername, conf.wallet["%s/opers/%s" % (conf.label, conf.opername)]), origin=self)
+ if conf.autojoin:
+ conf.autojoin.join(origin=self)
+ if conf.autorejoin and self._rejoinchannels[context]:
+ rejoin = irc.ChanList([channel for channel in self._rejoinchannels[
+ context] if channel not in conf.autojoin + conf.nsautojoin + conf.operjoin], context=context)
+ if len(rejoin):
+ rejoin.join(origin=self)
+ self._rejoinchannels[context] = None
- def onAddonRem(self, IRC):
- del self.networks[IRC]
+ def on381(self, context, line, origin, target, params, extinfo):
+ conf = self.networks[context]
+ if conf.operexec:
+ for line in conf.operexec:
+ context.raw(line, origin=self)
+ if conf.opermodes:
+ context.raw("MODE %s %s" %
+ (context.identity.nick, conf.opermodes), origin=self)
+ if conf.snomasks:
+ context.raw("MODE %s +s %s" %
+ (context.identity.nick, conf.snomasks), origin=self)
+ if conf.operjoin:
+ conf.operjoin.join(origin=self)
- def onPrivNotice(self, IRC, origin, msg):
- label, wallet, autojoin = self.networks[IRC]
+ def onPrivNotice(self, context, origin, msg):
+ conf = self.networks[context]
if type(origin) == irc.User and origin.nick.lower() == "nickserv":
- if re.match("This nickname is registered( and protected)?", msg) and wallet and "%s/NickServ/%s"%(label, IRC.identity.nick.lower()) in wallet.keys():
- origin.msg("identify %s" % wallet["%s/NickServ/%s" %
- (label, IRC.identity.nick.lower())])
+ if re.match("This nickname is registered( and protected)?", msg) and (not conf.nsmatch or fnmatch.fnmatch("%s!%s@%s" % (origin.nick, origin.username, origin.host), conf.nsmatch)) and conf.wallet and "%s/NickServ/%s" % (conf.label, context.identity.nick.lower()) in conf.wallet.keys():
+ origin.msg("identify %s" %
+ conf.wallet["%s/NickServ/%s" % (conf.label, context.identity.nick.lower())])
if re.match("You are now identified", msg):
- if autojoin:
- IRC.raw("JOIN %s"%(",".join(autojoin)), origin=self)
+ if conf.nsautojoin:
+ conf.nsautojoin.join(origin=self)
- def on900(self, IRC, line, origin, target, params, extinfo):
- label, wallet, autojoin = self.networks[IRC]
- if autojoin:
- IRC.raw("JOIN %s"%(",".join(autojoin)), origin=self)
+ def on900(self, context, line, origin, target, params, extinfo):
+ conf = self.networks[context]
+ if conf.nsautojoin:
+ conf.nsautojoin.join(origin=self)