From 9a6c1fbb7c154c2c980e2dcfcbac9ace7821b46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Mon, 23 Jul 2012 03:11:24 +0200 Subject: [PATCH] In private message and DCC chat, nemubot don't require nemubot: --- DCC.py | 6 ++++-- message.py | 16 +++++++++++++--- server.py | 5 ++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/DCC.py b/DCC.py index 234f09c..ed5cbdf 100644 --- a/DCC.py +++ b/DCC.py @@ -1,8 +1,10 @@ import imp import re import socket +import sys import threading import time +import traceback message = __import__("message") imp.reload(message) @@ -80,7 +82,7 @@ class DCC(threading.Thread): self.conn = socket.socket() try: self.conn.connect((host, port)) - print ('Accepted user from', host, port, "for", self.named) + print ('Accepted user from', host, port, "for", self.sender) self.connected = True self.stop = False except: @@ -181,7 +183,7 @@ class DCC(threading.Thread): else: self.send_dcc("The name you entered contain invalid char.") else: - self.srv.treat_msg((":%s PRIVMSG %s :" % (self.sender, self.srv.nick)).encode() + line, self.srv) + self.srv.treat_msg((":%s PRIVMSG %s :" % (self.sender, self.srv.nick)).encode() + line, self.srv, True) if self.connected: self.conn.close() diff --git a/message.py b/message.py index 08dafbc..d2ffe7d 100644 --- a/message.py +++ b/message.py @@ -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): diff --git a/server.py b/server.py index 341f636..66d553c 100644 --- a/server.py +++ b/server.py @@ -34,7 +34,6 @@ class Server(threading.Thread): threading.Thread.__init__(self) - @property def isDCC(self, to=None): return to is not None and to in self.dcc_clients @@ -215,11 +214,11 @@ class Server(threading.Thread): else: print (" Already connected.") - def treat_msg(self, line, srv = None): + def treat_msg(self, line, srv = None, private = False): if srv is None: srv = self try: - msg = message.Message (srv, line) + msg = message.Message (srv, line, private) msg.treat (self.mods) except: print ("\033[1;31mERROR:\033[0m occurred during the processing of the message: %s" % line)