|
|
|
@ -9,10 +9,11 @@ from random import randint
|
|
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
|
|
from modules import userinfo
|
|
|
|
|
from modules import counters as count
|
|
|
|
|
from modules import counters
|
|
|
|
|
from modules import monitor
|
|
|
|
|
|
|
|
|
|
from core.relay import sendRelayNotification
|
|
|
|
|
from utils.dedup import dedup
|
|
|
|
|
|
|
|
|
|
import main
|
|
|
|
|
from utils.logging.log import *
|
|
|
|
@ -137,7 +138,8 @@ class IRCBot(IRCClient):
|
|
|
|
|
del cast[i]
|
|
|
|
|
if "muser" in cast.keys():
|
|
|
|
|
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
|
|
|
|
|
del cast["muser"]
|
|
|
|
|
#if not cast["type"] in ["nick", "kick", "quit", "part", "join"]:
|
|
|
|
|
# del cast["muser"]
|
|
|
|
|
if set(["nick", "ident", "host", "message"]).issubset(set(cast)):
|
|
|
|
|
if "message" in cast.keys():
|
|
|
|
|
if cast["ident"] == "znc" and cast["host"] == "znc.in":
|
|
|
|
@ -148,9 +150,9 @@ class IRCBot(IRCClient):
|
|
|
|
|
del cast["host"]
|
|
|
|
|
del cast["target"]
|
|
|
|
|
if not cast["type"] in ["query", "self", "highlight", "znc", "who"]:
|
|
|
|
|
if "target" in cast.keys():
|
|
|
|
|
if cast["target"].lower() == self.nickname.lower():
|
|
|
|
|
#castDup = deepcopy(cast)
|
|
|
|
|
if "target" in cast.keys() and not cast["type"] == "mode": # don't handle modes here
|
|
|
|
|
if cast["target"].lower() == self.nickname.lower(): # as they are target == nickname
|
|
|
|
|
#castDup = deepcopy(cast) # however modes are not queries!
|
|
|
|
|
cast["mtype"] = cast["type"]
|
|
|
|
|
cast["type"] = "query"
|
|
|
|
|
cast["name"] = self.name
|
|
|
|
@ -170,21 +172,21 @@ class IRCBot(IRCClient):
|
|
|
|
|
castDup["mtype"] = cast["type"]
|
|
|
|
|
castDup["type"] = "self"
|
|
|
|
|
castDup["name"] = self.name
|
|
|
|
|
self.event(**castDup)
|
|
|
|
|
if not cast["target"].lower() == self.nickname.lower(): # modes has been set on us directly
|
|
|
|
|
self.event(**castDup) # don't tell anyone else
|
|
|
|
|
if "message" in cast.keys() and not cast["type"] == "query": # Don't highlight queries
|
|
|
|
|
if self.nickname.lower() in cast["message"].lower():
|
|
|
|
|
castDup = deepcopy(cast)
|
|
|
|
|
castDup["mtype"] = cast["type"]
|
|
|
|
|
castDup["type"] = "highlight"
|
|
|
|
|
castDup["name"] = self.name
|
|
|
|
|
self.event(**castDup)
|
|
|
|
|
|
|
|
|
|
if "name" not in cast.keys():
|
|
|
|
|
if not cast["message"] == None:
|
|
|
|
|
if self.nickname.lower() in cast["message"].lower():
|
|
|
|
|
castDup = deepcopy(cast)
|
|
|
|
|
castDup["mtype"] = cast["type"]
|
|
|
|
|
castDup["type"] = "highlight"
|
|
|
|
|
castDup["name"] = self.name
|
|
|
|
|
self.event(**castDup)
|
|
|
|
|
|
|
|
|
|
if not "name" in cast.keys():
|
|
|
|
|
cast["name"] = self.net
|
|
|
|
|
if cast["type"] in ["msg", "notice", "action"]:
|
|
|
|
|
userinfo.editUser(self.net, cast["nick"]+"!"+cast["ident"]+"@"+cast["host"])
|
|
|
|
|
count.event(self.net, cast["type"])
|
|
|
|
|
monitor.event(self.net, self.name, cast)
|
|
|
|
|
counters.event(self.net, cast["type"])
|
|
|
|
|
monitor.event(self.name, cast)
|
|
|
|
|
|
|
|
|
|
def privmsg(self, user, channel, msg):
|
|
|
|
|
self.event(type="msg", muser=user, target=channel, message=msg)
|
|
|
|
@ -212,10 +214,8 @@ class IRCBot(IRCClient):
|
|
|
|
|
return newnick
|
|
|
|
|
|
|
|
|
|
def nickChanged(self, olduser, newnick):
|
|
|
|
|
oldnick, ident, host = self.parsen(olduser)
|
|
|
|
|
userinfo.renameUser(self.net, oldnick, olduser, newnick, newnick+"!"+ident+"@"+host)
|
|
|
|
|
self.nickname = newnick
|
|
|
|
|
self.event(type="self", mtype="nick", nick=oldnick, ident=ident, host=host, user=newnick)
|
|
|
|
|
self.event(type="self", mtype="nick", muser=olduser, user=newnick)
|
|
|
|
|
|
|
|
|
|
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
|
|
|
|
|
self._attemptedNick = self.alterCollidedNick(self._attemptedNick)
|
|
|
|
@ -379,8 +379,8 @@ class IRCBot(IRCClient):
|
|
|
|
|
if not channel in self.channels:
|
|
|
|
|
self.channels.append(channel)
|
|
|
|
|
self.names(channel).addCallback(self.got_names)
|
|
|
|
|
self.who(channel).addCallback(self.got_who)
|
|
|
|
|
if main.config["Toggles"]["Who"]:
|
|
|
|
|
self.who(channel).addCallback(self.got_who)
|
|
|
|
|
lc = LoopingCall(self.who, channel)
|
|
|
|
|
self._getWho[channel] = lc
|
|
|
|
|
intrange = main.config["Tweaks"]["Delays"]["WhoRange"]
|
|
|
|
@ -395,63 +395,54 @@ class IRCBot(IRCClient):
|
|
|
|
|
lc = self._getWho[channel]
|
|
|
|
|
lc.stop()
|
|
|
|
|
del self._getWho[channel]
|
|
|
|
|
userinfo.delChannel(self.net, channel)
|
|
|
|
|
log("Can no longer cover %s, removing records" % channel)
|
|
|
|
|
|
|
|
|
|
def left(self, user, channel, message):
|
|
|
|
|
userinfo.delChannel(self.net, channel) # < we do not need to deduplicate this
|
|
|
|
|
#log("Can no longer cover %s, removing records" % channel)# as it will only be matched once --
|
|
|
|
|
# other bots have different nicknames so
|
|
|
|
|
def left(self, user, channel, message): # even if they saw it, they wouldn't react
|
|
|
|
|
self.event(type="part", muser=user, target=channel, message=message)
|
|
|
|
|
self.botLeft(channel)
|
|
|
|
|
|
|
|
|
|
def userJoined(self, user, channel):
|
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
|
userinfo.addUser(self.net, channel, nick, user)
|
|
|
|
|
self.event(type="join", nick=nick, ident=ident, host=host, target=channel)
|
|
|
|
|
self.event(type="join", muser=user, target=channel)
|
|
|
|
|
|
|
|
|
|
def userLeft(self, user, channel, message):
|
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
|
userinfo.delUser(self.net, channel, nick, user)
|
|
|
|
|
self.event(type="part", nick=nick, ident=ident, host=host, target=channel, message=message)
|
|
|
|
|
self.event(type="part", muser=user, target=channel, message=message)
|
|
|
|
|
|
|
|
|
|
def userQuit(self, user, quitMessage):
|
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
|
self.chanlessEvent(type="quit", nick=nick, ident=ident, host=host, message=quitMessage)
|
|
|
|
|
userinfo.delUserByNetwork(self.net, nick, user)
|
|
|
|
|
self.chanlessEvent({"type": "quit", "muser": user, "message": quitMessage})
|
|
|
|
|
|
|
|
|
|
def userKicked(self, kickee, channel, kicker, message):
|
|
|
|
|
nick, ident, host = self.parsen(kicker)
|
|
|
|
|
userinfo.editUser(self.net, kicker)
|
|
|
|
|
userinfo.delUserByNick(self.net, channel, kickee)
|
|
|
|
|
if kickee.lower == self.nickname.lower:
|
|
|
|
|
if kickee.lower() == self.nickname.lower():
|
|
|
|
|
self.botLeft(channel)
|
|
|
|
|
self.event(type="kick", nick=nick, ident=ident, host=host, target=channel, message=message, user=kickee)
|
|
|
|
|
self.event(type="kick", muser=kicker, target=channel, message=message, user=kickee)
|
|
|
|
|
|
|
|
|
|
def chanlessEvent(self, **cast):
|
|
|
|
|
chans = userinfo.getChansSingle(self.net, cast["nick"])
|
|
|
|
|
def chanlessEvent(self, cast):
|
|
|
|
|
cast["nick"], cast["ident"], cast["host"] = self.parsen(cast["muser"])
|
|
|
|
|
if dedup(self.name, cast):
|
|
|
|
|
return # stop right there sir!
|
|
|
|
|
chans = userinfo.getChanList(self.net, cast["nick"])
|
|
|
|
|
if chans == None:
|
|
|
|
|
self.event(**cast)
|
|
|
|
|
error("No channels returned for chanless event: %s" % cast)
|
|
|
|
|
# self.event(**cast) -- no, should NEVER happen
|
|
|
|
|
return
|
|
|
|
|
for i in chans:
|
|
|
|
|
# getChansSingle returns all channels of the user, we only want to use
|
|
|
|
|
# ones we have common with them
|
|
|
|
|
realChans = set(chans).intersection(set(self.channels))
|
|
|
|
|
for i in realChans:
|
|
|
|
|
cast["target"] = i
|
|
|
|
|
self.event(**cast)
|
|
|
|
|
|
|
|
|
|
def userRenamed(self, oldname, newname):
|
|
|
|
|
nick, ident, host = self.parsen(oldname)
|
|
|
|
|
self.chanlessEvent(type="nick", nick=nick, ident=ident, host=host, user=newname)
|
|
|
|
|
userinfo.renameUser(self.net, nick, oldname, newname, newname+"!"+ident+"@"+host)
|
|
|
|
|
self.chanlessEvent({"type": "nick", "muser": oldname, "user": newname})
|
|
|
|
|
|
|
|
|
|
def topicUpdated(self, user, channel, newTopic):
|
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
|
userinfo.editUser(self.net, user)
|
|
|
|
|
|
|
|
|
|
self.event(type="topic", nick=nick, ident=ident, host=host, target=channel, message= newTopic)
|
|
|
|
|
self.event(type="topic", muser=user, target=channel, message= newTopic)
|
|
|
|
|
|
|
|
|
|
def modeChanged(self, user, channel, toset, modes, args):
|
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
|
userinfo.editUser(self.net, user)
|
|
|
|
|
argList = list(args)
|
|
|
|
|
modeList = [i for i in modes]
|
|
|
|
|
for a, m in zip(argList, modeList):
|
|
|
|
|
self.event(type="mode", nick=nick, ident=ident, host=host, target=channel, modes=m, status=toset, modeargs=a)
|
|
|
|
|
self.event(type="mode", muser=user, target=channel, modes=m, status=toset, modeargs=a)
|
|
|
|
|
|
|
|
|
|
class IRCBotFactory(ReconnectingClientFactory):
|
|
|
|
|
def __init__(self, name, relay=None, relayCommands=None, user=None, stage2=None):
|
|
|
|
@ -488,7 +479,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
|
|
|
|
log("%s: connection lost: %s" % (self.name, error))
|
|
|
|
|
if not self.relay:
|
|
|
|
|
sendAll("%s: connection lost: %s" % (self.name, error))
|
|
|
|
|
sendRelayNotification(self.name, {"type": "conn", "status": "lost", "message": error})
|
|
|
|
|
sendRelayNotification({"type": "conn", "name": self.name, "status": "lost", "message": error})
|
|
|
|
|
self.retry(connector)
|
|
|
|
|
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
|
|
|
|
|
|
|
|
@ -500,7 +491,7 @@ class IRCBotFactory(ReconnectingClientFactory):
|
|
|
|
|
log("%s: connection failed: %s" % (self.name, error))
|
|
|
|
|
if not self.relay:
|
|
|
|
|
sendAll("%s: connection failed: %s" % (self.name, error))
|
|
|
|
|
sendRelayNotification(self.name, {"type": "conn", "status": "failed", "message": error})
|
|
|
|
|
sendRelayNotification({"type": "conn", "name": self.name, "status": "failed", "message": error})
|
|
|
|
|
self.retry(connector)
|
|
|
|
|
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
|
|
|
|
|
|
|
|
|