Implement requesting a LIST and parsing the output
This commit is contained in:
parent
aa54759337
commit
15b394bd79
53
core/bot.py
53
core/bot.py
|
@ -112,10 +112,12 @@ class IRCBot(IRCClient):
|
||||||
self.versionEnv = None
|
self.versionEnv = None
|
||||||
self.sourceURL = None
|
self.sourceURL = None
|
||||||
|
|
||||||
self._tempWho = {}
|
self._getWho = {} # LoopingCall objects -- needed to be able to stop them
|
||||||
self._getWho = {}
|
|
||||||
|
|
||||||
self._names = {}
|
self._tempWho = {} # Temporary storage for gathering WHO info
|
||||||
|
self._tempNames = {} # Temporary storage for gathering NAMES info
|
||||||
|
self._tempList = ([], []) # Temporary storage for gathering LIST info
|
||||||
|
self.listOngoing = False
|
||||||
|
|
||||||
def parsen(self, user):
|
def parsen(self, user):
|
||||||
step = user.split("!")
|
step = user.split("!")
|
||||||
|
@ -276,28 +278,28 @@ class IRCBot(IRCClient):
|
||||||
|
|
||||||
def names(self, channel):
|
def names(self, channel):
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
if channel not in self._names:
|
if channel not in self._tempNames:
|
||||||
self._names[channel] = ([], [])
|
self._tempNames[channel] = ([], [])
|
||||||
self._names[channel][0].append(d)
|
self._tempNames[channel][0].append(d)
|
||||||
self.sendLine("NAMES %s" % channel)
|
self.sendLine("NAMES %s" % channel)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def irc_RPL_NAMREPLY(self, prefix, params):
|
def irc_RPL_NAMREPLY(self, prefix, params):
|
||||||
channel = params[2]
|
channel = params[2]
|
||||||
nicklist = params[3].split(' ')
|
nicklist = params[3].split(' ')
|
||||||
if channel not in self._names:
|
if channel not in self._tempNames:
|
||||||
return
|
return
|
||||||
n = self._names[channel][1]
|
n = self._tempNames[channel][1]
|
||||||
n.append(nicklist)
|
n.append(nicklist)
|
||||||
|
|
||||||
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
def irc_RPL_ENDOFNAMES(self, prefix, params):
|
||||||
channel = params[1]
|
channel = params[1]
|
||||||
if channel not in self._names:
|
if channel not in self._tempNames:
|
||||||
return
|
return
|
||||||
callbacks, namelist = self._names[channel]
|
callbacks, namelist = self._tempNames[channel]
|
||||||
for cb in callbacks:
|
for cb in callbacks:
|
||||||
cb.callback((channel, namelist))
|
cb.callback((channel, namelist))
|
||||||
del self._names[channel]
|
del self._tempNames[channel]
|
||||||
|
|
||||||
def got_names(self, nicklist):
|
def got_names(self, nicklist):
|
||||||
newNicklist = []
|
newNicklist = []
|
||||||
|
@ -308,6 +310,35 @@ class IRCBot(IRCClient):
|
||||||
newNicklist.append(f)
|
newNicklist.append(f)
|
||||||
userinfo.initialNames(self.net, nicklist[0], newNicklist)
|
userinfo.initialNames(self.net, nicklist[0], newNicklist)
|
||||||
|
|
||||||
|
def _list(self):
|
||||||
|
d = Deferred()
|
||||||
|
self._tempList = ([], [])
|
||||||
|
self._tempList[0].append(d)
|
||||||
|
self.sendLine("LIST")
|
||||||
|
return d
|
||||||
|
|
||||||
|
def list(self):
|
||||||
|
if not self.listOngoing:
|
||||||
|
self._list().addCallback(self.got_list)
|
||||||
|
self.listOngoing = True
|
||||||
|
|
||||||
|
def irc_RPL_LIST(self, prefix, params):
|
||||||
|
channel = params[1]
|
||||||
|
users = params[2]
|
||||||
|
topic = params[3]
|
||||||
|
self._tempList[1].append([channel, users, topic])
|
||||||
|
|
||||||
|
def irc_RPL_LISTEND(self, prefix, params):
|
||||||
|
callbacks, info = self._tempList
|
||||||
|
for cb in callbacks:
|
||||||
|
cb.callback((info))
|
||||||
|
self.listOngoing = False
|
||||||
|
self._tempList[0].clear()
|
||||||
|
self._tempList[1].clear()
|
||||||
|
|
||||||
|
def got_list(self, listinfo):
|
||||||
|
print("have list", listinfo)
|
||||||
|
|
||||||
#twisted sucks so i have to do this to actually get the user info
|
#twisted sucks so i have to do this to actually get the user info
|
||||||
def irc_JOIN(self, prefix, params):
|
def irc_JOIN(self, prefix, params):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
import main
|
Loading…
Reference in New Issue