Parse new commands: 332, 353, JOIN, MODE, NICK, PART, QUIT
This commit is contained in:
parent
f32e819242
commit
1f5127e921
2 changed files with 87 additions and 9 deletions
57
channel.py
57
channel.py
|
@ -5,5 +5,60 @@ class Channel:
|
|||
self.node = node
|
||||
self.name = node["name"]
|
||||
self.password = node["password"]
|
||||
self.people = list()
|
||||
self.people = dict()
|
||||
self.topic = ""
|
||||
|
||||
def join(self, msg):
|
||||
#print ("%s arrive sur %s" % (self.sender, self.channel))
|
||||
self.people[msg.sender] = 0
|
||||
|
||||
def nick(self, msg):
|
||||
#print ("%s change de nom pour %s" % (self.sender, self.content))
|
||||
if msg.sender in self.people:
|
||||
lvl = self.people[msg.sender]
|
||||
del self.people[msg.sender]
|
||||
else:
|
||||
lvl = 0
|
||||
self.people[msg.content] = lvl
|
||||
|
||||
def part(self, msg):
|
||||
#print ("%s vient de quitter %s" % (self.sender, self.channel))
|
||||
if msg.sender in self.people:
|
||||
del self.people[msg.sender]
|
||||
|
||||
def mode(self, msg):
|
||||
if msg.content[0] == "-k":
|
||||
self.password = ""
|
||||
elif msg.content[0] == "+k":
|
||||
if len(msg.content) > 1:
|
||||
self.password = ' '.join(msg.content[1:])[1:]
|
||||
else:
|
||||
self.password = msg.content[1]
|
||||
elif msg.content[0] == "+o":
|
||||
self.people[msg.sender] |= 4
|
||||
elif msg.content[0] == "-o":
|
||||
self.people[msg.sender] &= ~4
|
||||
elif msg.content[0] == "+h":
|
||||
self.people[msg.sender] |= 2
|
||||
elif msg.content[0] == "-h":
|
||||
self.people[msg.sender] &= ~2
|
||||
elif msg.content[0] == "+v":
|
||||
self.people[msg.sender] |= 1
|
||||
elif msg.content[0] == "-v":
|
||||
self.people[msg.sender] &= ~1
|
||||
|
||||
def parse332(self, msg):
|
||||
self.topic = msg.content
|
||||
|
||||
def parse353(self, msg):
|
||||
for p in msg.content:
|
||||
if p[0] == "@":
|
||||
level = 4
|
||||
elif p[0] == "%":
|
||||
level = 2
|
||||
elif p[0] == "+":
|
||||
level = 1
|
||||
else:
|
||||
self.people[p] = 0
|
||||
continue
|
||||
self.people[p[1:]] = level
|
||||
|
|
39
message.py
39
message.py
|
@ -56,8 +56,21 @@ class Message:
|
|||
self.content = words[3]
|
||||
if self.content[0] == ':':
|
||||
self.content = ' '.join(words[3:])[1:]
|
||||
else:
|
||||
print (line)
|
||||
elif self.cmd == '353' and len(words) > 3:
|
||||
for i in range(2, len(words)):
|
||||
if words[i][0] == ":":
|
||||
self.content = words[i:]
|
||||
#Remove the first :
|
||||
self.content[0] = self.content[0][1:]
|
||||
self.channel = words[i-1]
|
||||
break
|
||||
elif self.cmd == 'MODE':
|
||||
self.content = words[3:]
|
||||
elif self.cmd == '332':
|
||||
self.channel = words[3]
|
||||
self.content = ' '.join(words[4:])[1:]
|
||||
# else:
|
||||
# print (line)
|
||||
else:
|
||||
print (line)
|
||||
if self.cmd == 'PRIVMSG':
|
||||
|
@ -110,12 +123,22 @@ class Message:
|
|||
self.parsectcp ()
|
||||
elif self.cmd == "PRIVMSG" and self.authorize():
|
||||
self.parsemsg (mods)
|
||||
# elif self.cmd == "NICK":
|
||||
# print ("%s change de nom pour %s" % (self.sender, self.content))
|
||||
# elif self.cmd == "PART":
|
||||
# print ("%s vient de quitter %s" % (self.sender, self.channel))
|
||||
# elif self.cmd == "JOIN":
|
||||
# print ("%s arrive sur %s" % (self.sender, self.channel))
|
||||
elif self.channel in self.srv.channels:
|
||||
if self.cmd == "353":
|
||||
self.srv.channels[self.channel].parse353(self)
|
||||
elif self.cmd == "332":
|
||||
self.srv.channels[self.channel].parse332(self)
|
||||
elif self.cmd == "MODE":
|
||||
self.srv.channels[self.channel].mode(self)
|
||||
elif self.cmd == "NICK":
|
||||
self.srv.channels[self.channel].nick(self)
|
||||
elif self.cmd == "JOIN":
|
||||
self.srv.channels[self.channel].join(self)
|
||||
elif self.cmd == "PART":
|
||||
self.srv.channels[self.channel].part(self)
|
||||
elif self.cmd == "QUIT":
|
||||
for chn in self.srv.channels.keys():
|
||||
self.srv.channels[chn].part(self)
|
||||
|
||||
|
||||
def pong (self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue