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

6
DCC.py
View File

@ -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()

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):

View File

@ -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)