2018-02-23 22:05:40 +00:00
|
|
|
from twisted.internet.protocol import ReconnectingClientFactory
|
|
|
|
from twisted.words.protocols.irc import IRCClient
|
|
|
|
from twisted.internet.defer import Deferred
|
2019-01-26 01:57:24 +00:00
|
|
|
from twisted.internet.task import LoopingCall, deferLater
|
|
|
|
from twisted.internet import reactor
|
2018-08-27 19:42:49 +00:00
|
|
|
|
2018-08-26 18:08:27 +00:00
|
|
|
from string import digits
|
2018-07-29 12:04:47 +00:00
|
|
|
from random import randint
|
|
|
|
|
2019-08-05 21:51:16 +00:00
|
|
|
from modules import userinfo
|
|
|
|
from modules import counters as count
|
|
|
|
from modules import monitor
|
|
|
|
|
|
|
|
from core.relay import sendRelayNotification
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
import main
|
2018-02-23 22:05:40 +00:00
|
|
|
from utils.logging.log import *
|
|
|
|
from utils.logging.send import *
|
|
|
|
|
2019-01-26 01:57:24 +00:00
|
|
|
from twisted.internet.ssl import DefaultOpenSSLContextFactory
|
|
|
|
|
|
|
|
def deliverRelayCommands(relay, relayCommands, user=None, stage2=None):
|
2019-08-11 20:58:14 +00:00
|
|
|
# where relay is a dictionary extracted from the Network object
|
2019-01-26 01:57:24 +00:00
|
|
|
keyFN = main.certPath+main.config["Key"]
|
|
|
|
certFN = main.certPath+main.config["Certificate"]
|
|
|
|
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"),
|
|
|
|
certFN.encode("utf-8", "replace"))
|
|
|
|
bot = IRCBotFactory(None, relay, relayCommands, user, stage2)
|
2019-08-11 20:58:14 +00:00
|
|
|
rct = reactor.connectSSL(relay["host"],
|
|
|
|
int(relay["port"]),
|
2019-01-26 01:57:24 +00:00
|
|
|
bot, contextFactory)
|
|
|
|
|
|
|
|
class IRCRelay(IRCClient):
|
|
|
|
def __init__(self, relay, relayCommands, user, stage2):
|
|
|
|
self.connected = False
|
|
|
|
self.buffer = ""
|
|
|
|
if user == None:
|
2019-08-11 20:58:14 +00:00
|
|
|
self.user = relay["user"]
|
2019-01-26 01:57:24 +00:00
|
|
|
else:
|
|
|
|
self.user = user
|
2019-08-11 20:58:14 +00:00
|
|
|
password = relay["password"]
|
2019-01-26 01:57:24 +00:00
|
|
|
self.nickname = self.user
|
|
|
|
self.realname = self.user
|
|
|
|
self.username = self.user
|
|
|
|
self.password = self.user+":"+password
|
|
|
|
|
|
|
|
self.relayCommands = relayCommands
|
|
|
|
self.relay = relay
|
|
|
|
self.stage2 = stage2
|
|
|
|
|
|
|
|
def parsen(self, user):
|
|
|
|
step = user.split("!")
|
|
|
|
nick = step[0]
|
|
|
|
if len(step) == 2:
|
|
|
|
step2 = step[1].split("@")
|
|
|
|
ident, host = step2
|
|
|
|
else:
|
|
|
|
ident = nick
|
|
|
|
host = nick
|
|
|
|
|
|
|
|
return [nick, ident, host]
|
|
|
|
|
|
|
|
def privmsg(self, user, channel, msg):
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
if nick[0] == main.config["Tweaks"]["ZNC"]["Prefix"]:
|
|
|
|
nick = nick[1:]
|
|
|
|
if nick in self.relayCommands.keys():
|
|
|
|
sendAll("[%s] %s -> %s" % (self.relay, nick, msg))
|
|
|
|
|
|
|
|
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
|
|
|
log("%s: relay password mismatch" % self.relay)
|
|
|
|
sendAll("%s: relay password mismatch" % self.relay)
|
|
|
|
|
|
|
|
def signedOn(self):
|
|
|
|
self.connected = True
|
|
|
|
log("signed on as a relay: %s" % self.relay)
|
|
|
|
if main.config["Notifications"]["Connection"]:
|
2019-08-05 21:51:16 +00:00
|
|
|
sendRelayNotification("Relay", {"type": "conn", "status": "connected"})
|
2019-01-26 01:57:24 +00:00
|
|
|
for i in self.relayCommands.keys():
|
|
|
|
for x in self.relayCommands[i]:
|
|
|
|
self.msg(main.config["Tweaks"]["ZNC"]["Prefix"]+i, x)
|
|
|
|
if not self.stage2 == None: # [["user", {"sasl": ["message1", "message2"]}], []]
|
|
|
|
if not len(self.stage2) == 0:
|
|
|
|
user = self.stage2[0].pop(0)
|
|
|
|
commands = self.stage2[0].pop(0)
|
|
|
|
del self.stage2[0]
|
|
|
|
deliverRelayCommands(self.relay, commands, user, self.stage2)
|
|
|
|
deferLater(reactor, 1, self.transport.loseConnection)
|
|
|
|
return
|
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
class IRCBot(IRCClient):
|
2019-08-11 20:58:14 +00:00
|
|
|
def __init__(self, name, relay):
|
2018-02-23 22:05:40 +00:00
|
|
|
self.connected = False
|
|
|
|
self.channels = []
|
2018-08-26 18:08:27 +00:00
|
|
|
self.net = "".join([x for x in name if not x in digits])
|
2018-08-27 19:42:49 +00:00
|
|
|
if self.net == "":
|
|
|
|
error("Network with all numbers: %s" % name)
|
2018-03-14 20:13:40 +00:00
|
|
|
self.buffer = ""
|
2018-02-23 22:05:40 +00:00
|
|
|
self.name = name
|
2019-08-11 20:58:14 +00:00
|
|
|
alias = relay["alias"]
|
2019-01-26 18:58:21 +00:00
|
|
|
|
|
|
|
self.nickname = alias["nick"]
|
|
|
|
self.realname = alias["realname"]
|
2019-08-11 20:58:14 +00:00
|
|
|
self.username = alias["nick"]+"/"+relay["net"]
|
2019-01-26 18:58:21 +00:00
|
|
|
self.password = relay["password"]
|
|
|
|
self.userinfo = None
|
|
|
|
self.fingerReply = None
|
|
|
|
self.versionName = None
|
2018-02-23 22:05:40 +00:00
|
|
|
self.versionNum = None
|
|
|
|
self.versionEnv = None
|
2019-01-26 18:58:21 +00:00
|
|
|
self.sourceURL = None
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
self._who = {}
|
|
|
|
self._getWho = {}
|
|
|
|
|
2018-08-27 19:42:49 +00:00
|
|
|
self._names = {}
|
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
def parsen(self, user):
|
|
|
|
step = user.split("!")
|
|
|
|
nick = step[0]
|
|
|
|
if len(step) == 2:
|
|
|
|
step2 = step[1].split("@")
|
2019-02-01 23:26:01 +00:00
|
|
|
if len(step2) == 2:
|
|
|
|
ident, host = step2
|
|
|
|
else:
|
|
|
|
ident = nick
|
|
|
|
host = nick
|
2018-02-23 22:05:40 +00:00
|
|
|
else:
|
|
|
|
ident = nick
|
|
|
|
host = nick
|
|
|
|
|
|
|
|
return [nick, ident, host]
|
|
|
|
|
|
|
|
def privmsg(self, user, channel, msg):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2019-08-05 21:51:16 +00:00
|
|
|
# ZNC adds messages when no users are in the channel, messing up tracking
|
2018-10-21 16:14:50 +00:00
|
|
|
#userinfo.editUser(self.net, channel, nick, user)
|
2019-08-05 21:51:16 +00:00
|
|
|
count.event(self.net, "msg")
|
|
|
|
#event = None
|
|
|
|
#if self.nickname.lower() in msg.lower():
|
|
|
|
# event = "highlight"
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "msg", "nick": nick, "ident": ident, "host": host, "target": channel, "message": msg})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def noticed(self, user, channel, msg):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-10-21 18:21:53 +00:00
|
|
|
#userinfo.editUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "notice")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "notice", "nick": nick, "ident": ident, "host": host, "target": channel, "message": msg})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def action(self, user, channel, msg):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-10-21 18:21:53 +00:00
|
|
|
#userinfo.editUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "action")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "action", "nick": nick, "ident": ident, "host": host, "target": channel, "message": msg})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def get(self, var):
|
|
|
|
try:
|
|
|
|
result = getattr(self, var)
|
|
|
|
except AttributeError:
|
|
|
|
result = None
|
|
|
|
return result
|
|
|
|
|
|
|
|
def setNick(self, nickname):
|
|
|
|
self._attemptedNick = nickname
|
|
|
|
self.sendLine("NICK %s" % nickname)
|
|
|
|
self.nickname = nickname
|
|
|
|
|
|
|
|
def alterCollidedNick(self, nickname):
|
|
|
|
newnick = nickname + "_"
|
|
|
|
return newnick
|
|
|
|
|
2018-08-27 19:42:49 +00:00
|
|
|
def nickChanged(self, olduser, newnick):
|
|
|
|
oldnick, ident, host = self.parsen(olduser)
|
|
|
|
userinfo.renameUser(self.net, oldnick, olduser, newnick, newnick+"!"+ident+"@"+host)
|
|
|
|
self.nickname = newnick
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "selfnick")
|
2018-03-10 14:01:43 +00:00
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
def irc_ERR_NICKNAMEINUSE(self, prefix, params):
|
|
|
|
self._attemptedNick = self.alterCollidedNick(self._attemptedNick)
|
|
|
|
self.setNick(self._attemptedNick)
|
|
|
|
|
|
|
|
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
|
|
|
|
log("%s: password mismatch" % self.name)
|
|
|
|
sendAll("%s: password mismatch" % self.name)
|
|
|
|
|
|
|
|
def who(self, channel):
|
|
|
|
d = Deferred()
|
|
|
|
if channel not in self._who:
|
2018-08-27 19:42:49 +00:00
|
|
|
self._who[channel] = ([], [])
|
2018-02-23 22:05:40 +00:00
|
|
|
self._who[channel][0].append(d)
|
|
|
|
self.sendLine("WHO %s" % channel)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def irc_RPL_WHOREPLY(self, prefix, params):
|
|
|
|
channel = params[1]
|
|
|
|
user = params[2]
|
|
|
|
host = params[3]
|
|
|
|
server = params[4]
|
|
|
|
nick = params[5]
|
|
|
|
status = params[6]
|
|
|
|
realname = params[7]
|
|
|
|
if channel not in self._who:
|
|
|
|
return
|
|
|
|
n = self._who[channel][1]
|
2018-08-27 19:42:49 +00:00
|
|
|
n.append([nick, user, host, server, status, realname])
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "whoreply")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "who", "nick": nick, "ident": user, "host": host, "realname": realname, "target": channel, "server": server, "status": status})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def irc_RPL_ENDOFWHO(self, prefix, params):
|
|
|
|
channel = params[1]
|
|
|
|
if channel not in self._who:
|
|
|
|
return
|
|
|
|
callbacks, info = self._who[channel]
|
|
|
|
for cb in callbacks:
|
|
|
|
cb.callback((channel, info))
|
|
|
|
del self._who[channel]
|
|
|
|
|
|
|
|
def got_who(self, whoinfo):
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.initialUsers(self.net, whoinfo[0], whoinfo[1])
|
|
|
|
|
|
|
|
def sanit(self, data):
|
|
|
|
if len(data) >= 1:
|
|
|
|
if data[0] in ["!", "~", "&", "@", "%", "+"]:
|
|
|
|
data = data[1:]
|
|
|
|
return data
|
|
|
|
return data
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def names(self, channel):
|
|
|
|
d = Deferred()
|
|
|
|
if channel not in self._names:
|
|
|
|
self._names[channel] = ([], [])
|
|
|
|
self._names[channel][0].append(d)
|
|
|
|
self.sendLine("NAMES %s" % channel)
|
|
|
|
return d
|
|
|
|
|
|
|
|
def irc_RPL_NAMREPLY(self, prefix, params):
|
|
|
|
channel = params[2]
|
|
|
|
nicklist = params[3].split(' ')
|
|
|
|
if channel not in self._names:
|
|
|
|
return
|
|
|
|
n = self._names[channel][1]
|
|
|
|
n.append(nicklist)
|
|
|
|
|
|
|
|
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
|
|
|
channel = params[1]
|
|
|
|
if channel not in self._names:
|
|
|
|
return
|
|
|
|
callbacks, namelist = self._names[channel]
|
|
|
|
for cb in callbacks:
|
|
|
|
cb.callback((channel, namelist))
|
|
|
|
del self._names[channel]
|
|
|
|
|
|
|
|
def got_names(self, nicklist):
|
|
|
|
newNicklist = []
|
|
|
|
for i in nicklist[1]:
|
|
|
|
for x in i:
|
|
|
|
f = self.sanit(x)
|
|
|
|
if f:
|
|
|
|
newNicklist.append(f)
|
|
|
|
userinfo.initialNames(self.net, nicklist[0], newNicklist)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
#twisted sucks so i have to do this to actually get the user info
|
|
|
|
def irc_JOIN(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Called when a user joins a channel.
|
|
|
|
"""
|
|
|
|
nick = prefix.split('!')[0]
|
|
|
|
channel = params[-1]
|
|
|
|
if nick == self.nickname:
|
|
|
|
self.joined(channel)
|
|
|
|
else:
|
|
|
|
self.userJoined(prefix, channel)
|
|
|
|
|
|
|
|
def irc_PART(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Called when a user leaves a channel.
|
|
|
|
"""
|
|
|
|
nick = prefix.split('!')[0]
|
|
|
|
channel = params[0]
|
|
|
|
if len(params) >= 2:
|
|
|
|
message = params[1]
|
|
|
|
else:
|
|
|
|
message = None
|
|
|
|
if nick == self.nickname:
|
2019-08-05 21:51:16 +00:00
|
|
|
self.left(prefix, channel, message)
|
2018-03-14 20:13:40 +00:00
|
|
|
else:
|
|
|
|
self.userLeft(prefix, channel, message)
|
|
|
|
|
|
|
|
def irc_QUIT(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Called when a user has quit.
|
|
|
|
"""
|
2019-08-05 21:51:16 +00:00
|
|
|
nick = prefix.split('!')[0]
|
|
|
|
if nick == self.nickname:
|
|
|
|
self.botQuit(prefix, params[0])
|
|
|
|
else:
|
|
|
|
self.userQuit(prefix, params[0])
|
2018-03-14 20:13:40 +00:00
|
|
|
|
|
|
|
def irc_NICK(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Called when a user changes their nickname.
|
|
|
|
"""
|
|
|
|
nick = prefix.split('!', 1)[0]
|
|
|
|
if nick == self.nickname:
|
2018-08-27 19:42:49 +00:00
|
|
|
self.nickChanged(prefix, params[0])
|
2018-03-14 20:13:40 +00:00
|
|
|
else:
|
|
|
|
self.userRenamed(prefix, params[0])
|
|
|
|
|
|
|
|
def irc_KICK(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Called when a user is kicked from a channel.
|
|
|
|
"""
|
|
|
|
#kicker = prefix.split('!')[0]
|
|
|
|
channel = params[0]
|
|
|
|
kicked = params[1]
|
|
|
|
message = params[-1]
|
|
|
|
if kicked.lower() == self.nickname.lower():
|
|
|
|
# Yikes!
|
|
|
|
self.kickedFrom(channel, prefix, message)
|
|
|
|
else:
|
|
|
|
self.userKicked(kicked, channel, prefix, message)
|
|
|
|
|
|
|
|
def irc_TOPIC(self, prefix, params):
|
|
|
|
"""
|
|
|
|
Someone in the channel set the topic.
|
|
|
|
"""
|
|
|
|
#user = prefix.split('!')[0]
|
|
|
|
channel = params[0]
|
|
|
|
newtopic = params[1]
|
|
|
|
self.topicUpdated(prefix, channel, newtopic)
|
|
|
|
#END hacks
|
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
def signedOn(self):
|
|
|
|
self.connected = True
|
|
|
|
log("signed on: %s" % self.name)
|
2018-05-07 18:58:19 +00:00
|
|
|
if main.config["Notifications"]["Connection"]:
|
2019-08-05 21:51:16 +00:00
|
|
|
sendRelayNotification(self.name, {"type": "conn", "status": "connected"})
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "signedon")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def joined(self, channel):
|
|
|
|
if not channel in self.channels:
|
|
|
|
self.channels.append(channel)
|
2018-08-27 19:42:49 +00:00
|
|
|
self.names(channel).addCallback(self.got_names)
|
2018-02-23 22:05:40 +00:00
|
|
|
self.who(channel).addCallback(self.got_who)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "selfjoin")
|
2018-03-14 20:13:40 +00:00
|
|
|
if self.name == main.config["Master"][0] and channel == main.config["Master"][1]:
|
|
|
|
for i in range(len(main.masterbuf)):
|
|
|
|
self.msg(channel, main.masterbuf.pop(0))
|
|
|
|
main.saveConf("masterbuf")
|
2018-08-27 19:42:49 +00:00
|
|
|
lc = LoopingCall(self.who, channel)
|
2018-07-28 20:30:50 +00:00
|
|
|
self._getWho[channel] = lc
|
2018-07-29 12:04:47 +00:00
|
|
|
intrange = main.config["Tweaks"]["Delays"]["WhoRange"]
|
|
|
|
minint = main.config["Tweaks"]["Delays"]["WhoLoop"]
|
|
|
|
interval = randint(minint, minint+intrange)
|
|
|
|
lc.start(interval)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-08-27 19:42:49 +00:00
|
|
|
def botLeft(self, channel):
|
2018-02-23 22:05:40 +00:00
|
|
|
if channel in self.channels:
|
|
|
|
self.channels.remove(channel)
|
2018-08-27 19:42:49 +00:00
|
|
|
if channel in self._getWho.keys():
|
|
|
|
lc = self._getWho[channel]
|
|
|
|
lc.stop()
|
|
|
|
del self._getWho[channel]
|
|
|
|
userinfo.delChannel(self.net, channel)
|
|
|
|
|
2019-08-05 21:51:16 +00:00
|
|
|
def left(self, user, channel, message):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "selfpart")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "part", "target": channel, "message": message})
|
|
|
|
monitor.event(self.net, self.name, {"type": "part", "self": True, "target": channel, "message": message})
|
2018-08-27 19:42:49 +00:00
|
|
|
self.botLeft(channel)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def kickedFrom(self, channel, kicker, message):
|
2018-07-27 21:58:37 +00:00
|
|
|
nick, ident, host = self.parsen(kicker)
|
2018-02-23 22:05:40 +00:00
|
|
|
if channel in self.channels:
|
|
|
|
self.channels.remove(channel)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "selfkick")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "kick", "nick": nick, "ident": ident, "host": host, "target": channel, "message": message})
|
|
|
|
monitor.event(self.net, self.name, {"type": "kick", "self": True, "nick": nick, "ident": ident, "host": host, "target": channel, "message": message})
|
2018-08-27 19:42:49 +00:00
|
|
|
self.botLeft(channel)
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def userJoined(self, user, channel):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.addUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "join")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "join", "nick": nick, "ident": ident, "host": host, "target": channel})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2018-03-14 20:13:40 +00:00
|
|
|
def userLeft(self, user, channel, message):
|
2018-02-23 22:05:40 +00:00
|
|
|
nick, ident, host = self.parsen(user)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.delUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "part")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "part", "nick": nick, "ident": ident, "host": host, "target": channel, "message": message})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def userQuit(self, user, quitMessage):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.delUserByNetwork(self.net, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "quit")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "quit", "nick": nick, "ident": ident, "host": host, "message": quitMessage})
|
2019-08-05 21:51:16 +00:00
|
|
|
|
|
|
|
def botQuit(self, user, quitMessage):
|
|
|
|
nick, ident, host = self.parsen(user)
|
|
|
|
userinfo.delUserByNetwork(self.net, nick, user)
|
|
|
|
count.event(self.net, "selfquit")
|
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "quit", "nick": nick, "ident": ident, "host": host, "message": quitMessage})
|
|
|
|
monitor.event(self.net, self.name, {"type": "quit", "self": True, "nick": nick, "ident": ident, "host": host, "message": quitMessage})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def userKicked(self, kickee, channel, kicker, message):
|
|
|
|
nick, ident, host = self.parsen(kicker)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.editUser(self.net, channel, nick, kicker)
|
|
|
|
userinfo.delUserByNick(self.net, channel, kickee)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "kick")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "kick", "nick": nick, "ident": ident, "host": host, "target": channel, "message": message, "user": kickee})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def userRenamed(self, oldname, newname):
|
|
|
|
nick, ident, host = self.parsen(oldname)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.renameUser(self.net, nick, oldname, newname, newname+"!"+ident+"@"+host)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "nick")
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "nick", "nick": nick, "ident": ident, "host": host, "user": newname})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def topicUpdated(self, user, channel, newTopic):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.editUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "topic")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "topic", "nick": nick, "ident": ident, "host": host, "target": channel, "message": newTopic})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def modeChanged(self, user, channel, toset, modes, args):
|
|
|
|
nick, ident, host = self.parsen(user)
|
2018-08-27 19:42:49 +00:00
|
|
|
userinfo.editUser(self.net, channel, nick, user)
|
2018-10-14 19:16:41 +00:00
|
|
|
count.event(self.net, "mode")
|
2018-07-28 20:30:50 +00:00
|
|
|
argList = list(args)
|
|
|
|
modeList = [i for i in modes]
|
|
|
|
for a, m in zip(argList, modeList):
|
2019-08-06 11:49:29 +00:00
|
|
|
monitor.event(self.net, self.name, {"type": "mode", "nick": nick, "ident": ident, "host": host, "target": channel, "modes": m, "modeargs": a})
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
class IRCBotFactory(ReconnectingClientFactory):
|
2019-01-26 01:57:24 +00:00
|
|
|
def __init__(self, name, relay=None, relayCommands=None, user=None, stage2=None):
|
|
|
|
if not name == None:
|
|
|
|
self.name = name
|
|
|
|
self.net = "".join([x for x in self.name if not x in digits])
|
|
|
|
else:
|
2019-08-11 20:58:14 +00:00
|
|
|
self.name = "Relay to "+relay["net"]+relay["id"]
|
2018-02-23 22:05:40 +00:00
|
|
|
self.client = None
|
2019-01-26 01:57:24 +00:00
|
|
|
self.maxDelay = main.config["Tweaks"]["Delays"]["MaxDelay"]
|
|
|
|
self.initialDelay = main.config["Tweaks"]["Delays"]["InitialDelay"]
|
|
|
|
self.factor = main.config["Tweaks"]["Delays"]["Factor"]
|
|
|
|
self.jitter = main.config["Tweaks"]["Delays"]["Jitter"]
|
|
|
|
|
|
|
|
self.relay, self.relayCommands, self.user, self.stage2 = relay, relayCommands, user, stage2
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def buildProtocol(self, addr):
|
2019-01-26 01:57:24 +00:00
|
|
|
if self.relay == None:
|
2019-08-11 20:58:14 +00:00
|
|
|
entry = IRCBot(self.name, self.relay)
|
2019-01-26 01:57:24 +00:00
|
|
|
main.IRCPool[self.name] = entry
|
|
|
|
else:
|
|
|
|
entry = IRCRelay(self.relay, self.relayCommands, self.user, self.stage2)
|
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
self.client = entry
|
|
|
|
return entry
|
|
|
|
|
|
|
|
def clientConnectionLost(self, connector, reason):
|
2019-01-26 01:57:24 +00:00
|
|
|
if not self.relay:
|
|
|
|
userinfo.delNetwork(self.net, self.client.channels)
|
2018-02-23 22:05:40 +00:00
|
|
|
if not self.client == None:
|
|
|
|
self.client.connected = False
|
|
|
|
self.client.channels = []
|
|
|
|
error = reason.getErrorMessage()
|
|
|
|
log("%s: connection lost: %s" % (self.name, error))
|
2019-01-26 01:57:24 +00:00
|
|
|
if not self.relay:
|
|
|
|
sendAll("%s: connection lost: %s" % (self.name, error))
|
2018-05-07 18:58:19 +00:00
|
|
|
if main.config["Notifications"]["Connection"]:
|
2019-08-05 21:51:16 +00:00
|
|
|
sendRelayNotification(self.name, {"type": "conn", "status": "lost", "reason": error})
|
2019-01-26 01:57:24 +00:00
|
|
|
if not self.relay:
|
|
|
|
self.retry(connector)
|
2018-02-23 22:05:40 +00:00
|
|
|
#ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
|
|
|
|
|
|
|
def clientConnectionFailed(self, connector, reason):
|
|
|
|
if not self.client == None:
|
|
|
|
self.client.connected = False
|
|
|
|
self.client.channels = []
|
|
|
|
error = reason.getErrorMessage()
|
|
|
|
log("%s: connection failed: %s" % (self.name, error))
|
2019-08-05 21:51:16 +00:00
|
|
|
if not self.relay:
|
|
|
|
sendAll("%s: connection failed: %s" % (self.name, error))
|
2018-05-07 18:58:19 +00:00
|
|
|
if main.config["Notifications"]["Connection"]:
|
2019-08-05 21:51:16 +00:00
|
|
|
sendRelayNotification(self.name, {"type": "conn", "status": "failed", "reason": error})
|
2019-01-26 01:57:24 +00:00
|
|
|
if not self.relay:
|
|
|
|
self.retry(connector)
|
2018-02-23 22:05:40 +00:00
|
|
|
#ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
|
|
|
|