pngbot.py:IrcMiRCARTBot.clientChannelOps: added to track nicks authorised to use `!pngbot'.

pngbot.py:IrcMiRCARTBot.dispatch(): sync clientChannelOps w/ 353 (RPL_NAMREPLY) and (channel) MODE messages.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-02 23:12:26 +01:00
parent 75e8e5fdf0
commit 993e986ec0

View File

@ -86,7 +86,7 @@ class IrcBot:
class IrcMiRCARTBot(IrcBot):
"""IRC<->MiRCART bot"""
clientLastMessage = clientChannel = None
clientChannelLastMessage = clientChannelOps = clientChannel = None
# {{{ connect(): Connect to server and (re)initialise
def connect(self):
@ -94,7 +94,7 @@ class IrcMiRCARTBot(IrcBot):
super().connect()
print("Connected to {}:{}.".format(self.serverHname, self.serverPort))
print("Registering on {}:{} as {}, {}, {}...".format(self.serverHname, self.serverPort, self.clientNick, self.clientIdent, self.clientGecos))
self.clientLastMessage = 0
self.clientLastMessage = 0; self.clientChannelOps = [];
# }}}
# {{{ dispatch(): Read, parse, and dispatch single line from server
def dispatch(self):
@ -107,6 +107,37 @@ class IrcMiRCARTBot(IrcBot):
print("Registered on {}:{} as {}, {}, {}.".format(self.serverHname, self.serverPort, self.clientNick, self.clientIdent, self.clientGecos))
print("Joining {} on {}:{}...".format(self.clientChannel, self.serverHname, self.serverPort))
self.sendline("JOIN", self.clientChannel)
elif serverMessage[1] == "353" \
and serverMessage[4].lower() == self.clientChannel.lower():
for channelNickSpec in serverMessage[5].split(" "):
if channelNickSpec[0] == "@" \
and len(channelNickSpec[1:]):
self.clientChannelOps.append(channelNickSpec[1:])
print("Authorising {} on {}".format(channelNickSpec[1:], serverMessage[2]))
elif serverMessage[1] == "MODE" \
and serverMessage[2].lower() == self.clientChannel.lower():
channelModeType = "+"; channelModeArg = 4;
channelAuthAdd = ""; channelAuthDel = "";
for channelModeChar in serverMessage[3]:
if channelModeChar[0] == "-":
channelModeType = "-"
elif channelModeChar[0] == "+":
channelModeType = "+"
elif channelModeChar[0].isalpha():
if channelModeChar[0] == "o":
if channelModeType == "+":
channelAuthAdd = serverMessage[channelModeArg]; channelAuthDel = "";
elif channelModeType == "-":
channelAuthAdd = ""; channelAuthDel = serverMessage[channelModeArg];
channelModeArg += 1
if len(channelAuthAdd) \
and channelAuthAdd not in self.clientChannelOps:
print("Authorising {} on {}".format(channelAuthAdd, serverMessage[2]))
self.clientChannelOps.append(channelAuthAdd)
elif len(channelAuthDel) \
and channelAuthDel in self.clientChannelOps:
print("Deauthorising {} on {}".format(channelAuthDel, serverMessage[2]))
self.clientChannelOps.remove(channelAuthDel)
elif serverMessage[1] == "PING":
self.sendline("PONG", serverMessage[2])
elif serverMessage[1] == "PRIVMSG" \