In private message and DCC chat, nemubot don't require nemubot:
This commit is contained in:
parent
bc860ef837
commit
9a6c1fbb7c
6
DCC.py
6
DCC.py
@ -1,8 +1,10 @@
|
|||||||
import imp
|
import imp
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
message = __import__("message")
|
message = __import__("message")
|
||||||
imp.reload(message)
|
imp.reload(message)
|
||||||
@ -80,7 +82,7 @@ class DCC(threading.Thread):
|
|||||||
self.conn = socket.socket()
|
self.conn = socket.socket()
|
||||||
try:
|
try:
|
||||||
self.conn.connect((host, port))
|
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.connected = True
|
||||||
self.stop = False
|
self.stop = False
|
||||||
except:
|
except:
|
||||||
@ -181,7 +183,7 @@ class DCC(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
self.send_dcc("The name you entered contain invalid char.")
|
self.send_dcc("The name you entered contain invalid char.")
|
||||||
else:
|
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:
|
if self.connected:
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
16
message.py
16
message.py
@ -29,9 +29,10 @@ def save():
|
|||||||
|
|
||||||
|
|
||||||
class Message:
|
class Message:
|
||||||
def __init__ (self, srv, line):
|
def __init__ (self, srv, line, private = False):
|
||||||
self.srv = srv
|
self.srv = srv
|
||||||
self.time = datetime.now ()
|
self.time = datetime.now ()
|
||||||
|
self.channel = None
|
||||||
line = line.rstrip() #remove trailing 'rn'
|
line = line.rstrip() #remove trailing 'rn'
|
||||||
|
|
||||||
words = line.split(b' ')
|
words = line.split(b' ')
|
||||||
@ -89,11 +90,13 @@ class Message:
|
|||||||
self.content = words[3]
|
self.content = words[3]
|
||||||
if self.content[0] == ':':
|
if self.content[0] == ':':
|
||||||
self.content = ' '.join(words[3:])[1:]
|
self.content = ' '.join(words[3:])[1:]
|
||||||
|
self.private = private or (self.channel is not None and self.channel == self.srv.nick)
|
||||||
|
|
||||||
def decode(self):
|
def decode(self):
|
||||||
try:
|
try:
|
||||||
self.content = self.content.decode()
|
self.content = self.content.decode()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
#TODO: use encoding from config file
|
||||||
self.content = self.content.decode('utf-8', 'replace')
|
self.content = self.content.decode('utf-8', 'replace')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -111,7 +114,7 @@ class Message:
|
|||||||
|
|
||||||
def send_chn(self, msg):
|
def send_chn(self, msg):
|
||||||
"""Send msg on the same channel as receive message"""
|
"""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:
|
if self.channel == self.srv.nick:
|
||||||
self.send_snd (msg)
|
self.send_snd (msg)
|
||||||
else:
|
else:
|
||||||
@ -124,7 +127,7 @@ class Message:
|
|||||||
|
|
||||||
|
|
||||||
def authorize(self):
|
def authorize(self):
|
||||||
if self.srv.isDCC:
|
if self.srv.isDCC():
|
||||||
return True
|
return True
|
||||||
elif self.realname not in CREDITS:
|
elif self.realname not in CREDITS:
|
||||||
CREDITS[self.realname] = Credits(self.realname)
|
CREDITS[self.realname] = Credits(self.realname)
|
||||||
@ -198,6 +201,7 @@ class Message:
|
|||||||
def parsemsg (self, mods):
|
def parsemsg (self, mods):
|
||||||
#Treat all messages starting with 'nemubot:' as distinct commands
|
#Treat all messages starting with 'nemubot:' as distinct commands
|
||||||
if self.content.find("%s:"%self.srv.nick) == 0:
|
if self.content.find("%s:"%self.srv.nick) == 0:
|
||||||
|
#Remove the bot name
|
||||||
self.content = self.content[len(self.srv.nick)+1:].strip()
|
self.content = self.content[len(self.srv.nick)+1:].strip()
|
||||||
messagel = self.content.lower()
|
messagel = self.content.lower()
|
||||||
|
|
||||||
@ -289,6 +293,12 @@ class Message:
|
|||||||
for im in mods:
|
for im in mods:
|
||||||
if im.has_access(self) and im.parselisten(self):
|
if im.has_access(self) and im.parselisten(self):
|
||||||
return
|
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):
|
# def parseOwnerCmd(self, cmd):
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ class Server(threading.Thread):
|
|||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
@property
|
|
||||||
def isDCC(self, to=None):
|
def isDCC(self, to=None):
|
||||||
return to is not None and to in self.dcc_clients
|
return to is not None and to in self.dcc_clients
|
||||||
|
|
||||||
@ -215,11 +214,11 @@ class Server(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
print (" Already connected.")
|
print (" Already connected.")
|
||||||
|
|
||||||
def treat_msg(self, line, srv = None):
|
def treat_msg(self, line, srv = None, private = False):
|
||||||
if srv is None:
|
if srv is None:
|
||||||
srv = self
|
srv = self
|
||||||
try:
|
try:
|
||||||
msg = message.Message (srv, line)
|
msg = message.Message (srv, line, private)
|
||||||
msg.treat (self.mods)
|
msg.treat (self.mods)
|
||||||
except:
|
except:
|
||||||
print ("\033[1;31mERROR:\033[0m occurred during the processing of the message: %s" % line)
|
print ("\033[1;31mERROR:\033[0m occurred during the processing of the message: %s" % line)
|
||||||
|
Loading…
Reference in New Issue
Block a user