Implement Ctrl-C handling and fix a large number of small bugs

This commit is contained in:
2019-09-28 19:46:10 +01:00
parent 006f8db6f6
commit 15ca45e5df
12 changed files with 88 additions and 61 deletions

View File

@@ -72,7 +72,6 @@ class IRCRelay(IRCClient):
sendAll("[%s] %s -> %s" % (self.num, nick, msg))
def irc_ERR_PASSWDMISMATCH(self, prefix, params):
print(', '.join("%s: %s" % item for item in vars(self).items()))
log("%s: relay password mismatch" % self.num)
sendAll("%s: relay password mismatch" % self.num)
@@ -113,7 +112,7 @@ class IRCBot(IRCClient):
self.versionEnv = None
self.sourceURL = None
self._who = {}
self._tempWho = {}
self._getWho = {}
self._names = {}
@@ -227,14 +226,17 @@ class IRCBot(IRCClient):
log("%s: password mismatch" % self.name)
sendAll("%s: password mismatch" % self.name)
def who(self, channel):
def _who(self, channel):
d = Deferred()
if channel not in self._who:
self._who[channel] = ([], [])
self._who[channel][0].append(d)
if channel not in self._tempWho:
self._tempWho[channel] = ([], [])
self._tempWho[channel][0].append(d)
self.sendLine("WHO %s" % channel)
return d
def who(self, channel):
self._who(channel).addCallback(self.got_who)
def irc_RPL_WHOREPLY(self, prefix, params):
channel = params[1]
ident = params[2]
@@ -243,20 +245,20 @@ class IRCBot(IRCClient):
nick = params[5]
status = params[6]
realname = params[7]
if channel not in self._who:
if channel not in self._tempWho:
return
n = self._who[channel][1]
n = self._tempWho[channel][1]
n.append([nick, nick, host, server, status, realname])
self.event(type="who", nick=nick, ident=ident, host=host, realname=realname, target=channel, server=server, status=status)
def irc_RPL_ENDOFWHO(self, prefix, params):
channel = params[1]
if channel not in self._who:
if channel not in self._tempWho:
return
callbacks, info = self._who[channel]
callbacks, info = self._tempWho[channel]
for cb in callbacks:
cb.callback((channel, info))
del self._who[channel]
del self._tempWho[channel]
def got_who(self, whoinfo):
userinfo.initialUsers(self.net, whoinfo[0], whoinfo[1])
@@ -382,7 +384,8 @@ class IRCBot(IRCClient):
self.channels.append(channel)
self.names(channel).addCallback(self.got_names)
if main.config["Toggles"]["Who"]:
self.who(channel).addCallback(self.got_who)
#self.who(channel).addCallback(self.got_who)
#self.who(channel)
lc = LoopingCall(self.who, channel)
self._getWho[channel] = lc
intrange = main.config["Tweaks"]["Delays"]["WhoRange"]
@@ -466,7 +469,7 @@ class IRCBotFactory(ReconnectingClientFactory):
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
def buildProtocol(self, addr):
if self.net == None:
if self.relay == None:
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
else:
entry = IRCBot(self.net, self.num)