Implement support for modes and get WHO data on a loop

This commit is contained in:
Mark Veidemanis 2018-07-28 21:30:50 +01:00
parent bc87ffddf7
commit edea19222d
2 changed files with 14 additions and 5 deletions

View File

@ -1 +0,0 @@
{}

View File

@ -1,6 +1,7 @@
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.words.protocols.irc import IRCClient
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
import modules.keyword as keyword
import modules.userinfo as userinfo
@ -139,6 +140,7 @@ class IRCBot(IRCClient):
n = self._who[channel][1]
n[nick] = [nick, user, host, server, status, realname]
count.event(self.name, "whoreply")
monitor.event(self.name, channel, {"type": "who", "exact": nick+"!"+user+"@"+host, "nick": nick, "ident": user, "host": host, "realname": realname, "server": server, "status": status})
def irc_RPL_ENDOFWHO(self, prefix, params):
channel = params[1]
@ -152,7 +154,6 @@ class IRCBot(IRCClient):
def got_who(self, whoinfo):
userinfo.setWho(self.name, whoinfo[1])
#twisted sucks so i have to do this to actually get the user info
def irc_JOIN(self, prefix, params):
"""
@ -232,6 +233,9 @@ class IRCBot(IRCClient):
self.join(i)
count.event(self.name, "signedon")
def getWho(self, channel):
self.who(channel).addCallback(self.got_who)
def joined(self, channel):
if not channel in self.channels:
self.channels.append(channel)
@ -241,6 +245,9 @@ class IRCBot(IRCClient):
for i in range(len(main.masterbuf)):
self.msg(channel, main.masterbuf.pop(0))
main.saveConf("masterbuf")
lc = LoopingCall(self.getWho, channel)
self._getWho[channel] = lc
lc.start(60)
def left(self, channel, message):
if channel in self.channels:
@ -248,10 +255,11 @@ class IRCBot(IRCClient):
keyword.actKeyword(self.nickname, channel, message, self.nickname, "SELFPART", self.name)
count.event(self.name, "selfpart")
monitor.event(self.name, channel, {"type": "part", "message": message})
lc = self._getWho[channel]
lc.stop()
def kickedFrom(self, channel, kicker, message):
nick, ident, host = self.parsen(kicker)
print(kicker)
userinfo.setWhoSingle(self.name, nick, ident, host)
if channel in self.channels:
self.channels.remove(channel)
@ -307,8 +315,10 @@ class IRCBot(IRCClient):
nick, ident, host = self.parsen(user)
userinfo.setWhoSingle(self.name, nick, ident, host)
count.event(self.name, "mode")
print("%s // %s // %s" % (toset, modes, args))
#monitor.event(self.name, channel, {"type": "topic", "exact": user, "nick": nick, "ident": ident, "host": host, "message": newTopic})
argList = list(args)
modeList = [i for i in modes]
for a, m in zip(argList, modeList):
monitor.event(self.name, channel, {"type": "mode", "exact": user, "nick": nick, "ident": ident, "host": host, "modes": m, "modeargs": a})
class IRCBotFactory(ReconnectingClientFactory):
def __init__(self, name):