nemubot/channel.py

72 lines
1.8 KiB
Python
Raw Normal View History

2012-06-23 13:14:36 +00:00
# coding=utf-8
class Channel:
2012-07-23 17:20:46 +00:00
def __init__(self, node, srv):
2012-06-23 13:14:36 +00:00
self.node = node
self.name = node["name"]
self.password = node["password"]
self.people = dict()
2012-07-23 17:20:46 +00:00
self.srv = srv
2012-06-23 13:14:36 +00:00
self.topic = ""
2012-07-20 15:11:21 +00:00
def join(self, nick, level = 0):
#print ("%s arrive sur %s" % (nick, self.name))
self.people[nick] = level
2012-07-20 17:15:01 +00:00
def chtopic(self, newtopic):
2012-07-23 17:20:46 +00:00
"""Send command to change the topic"""
self.srv.send_msg(self.name, newtopic, "TOPIC")
2012-07-20 17:15:01 +00:00
self.topic = newtopic
2012-07-20 15:11:21 +00:00
def nick(self, oldnick, newnick):
2012-07-23 16:08:11 +00:00
#print ("%s change de nom pour %s" % (oldnick, newnick))
2012-07-20 15:11:21 +00:00
if oldnick in self.people:
lvl = self.people[oldnick]
del self.people[oldnick]
else:
lvl = 0
2012-07-20 15:11:21 +00:00
self.people[newnick] = lvl
2012-07-20 15:11:21 +00:00
def part(self, nick):
#print ("%s vient de quitter %s" % (self.sender, self.channel))
2012-07-20 15:11:21 +00:00
if nick in self.people:
del self.people[nick]
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":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] |= 4
elif msg.content[0] == "-o":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] &= ~4
elif msg.content[0] == "+h":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] |= 2
elif msg.content[0] == "-h":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] &= ~2
elif msg.content[0] == "+v":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] |= 1
elif msg.content[0] == "-v":
2012-07-23 16:08:11 +00:00
self.people[msg.nick] &= ~1
def parse332(self, msg):
self.topic = msg.content
def parse353(self, msg):
for p in msg.content:
2012-07-23 16:08:11 +00:00
p = p.decode()
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