In private message and DCC chat, nemubot don't require nemubot:

This commit is contained in:
Némunaire 2012-07-23 03:11:24 +02:00
parent bc860ef837
commit 9a6c1fbb7c
3 changed files with 19 additions and 8 deletions

View file

@ -29,9 +29,10 @@ def save():
class Message:
def __init__ (self, srv, line):
def __init__ (self, srv, line, private = False):
self.srv = srv
self.time = datetime.now ()
self.channel = None
line = line.rstrip() #remove trailing 'rn'
words = line.split(b' ')
@ -89,11 +90,13 @@ class Message:
self.content = words[3]
if self.content[0] == ':':
self.content = ' '.join(words[3:])[1:]
self.private = private or (self.channel is not None and self.channel == self.srv.nick)
def decode(self):
try:
self.content = self.content.decode()
except UnicodeDecodeError:
#TODO: use encoding from config file
self.content = self.content.decode('utf-8', 'replace')
@property
@ -111,7 +114,7 @@ class Message:
def send_chn(self, msg):
"""Send msg on the same channel as receive message"""
if (self.srv.isDCC and self.channel == self.srv.nick) or CREDITS[self.realname].speak():
if (self.srv.isDCC() and self.channel == self.srv.nick) or CREDITS[self.realname].speak():
if self.channel == self.srv.nick:
self.send_snd (msg)
else:
@ -124,7 +127,7 @@ class Message:
def authorize(self):
if self.srv.isDCC:
if self.srv.isDCC():
return True
elif self.realname not in CREDITS:
CREDITS[self.realname] = Credits(self.realname)
@ -198,6 +201,7 @@ class Message:
def parsemsg (self, mods):
#Treat all messages starting with 'nemubot:' as distinct commands
if self.content.find("%s:"%self.srv.nick) == 0:
#Remove the bot name
self.content = self.content[len(self.srv.nick)+1:].strip()
messagel = self.content.lower()
@ -289,6 +293,12 @@ class Message:
for im in mods:
if im.has_access(self) and im.parselisten(self):
return
#Assume the message starts with nemubot:
if self.private:
print ("private")
for im in mods:
if im.has_access(self) and im.parseask(self):
return
# def parseOwnerCmd(self, cmd):