Message parsing is now a server part

This commit is contained in:
nemunaire 2014-09-11 17:23:07 +02:00
parent d83b0d1b81
commit 877041bb12
3 changed files with 14 additions and 13 deletions

4
bot.py
View File

@ -394,10 +394,10 @@ class Bot(threading.Thread):
return False return False
def receive_message(self, srv, raw_msg, private=False, data=None): def receive_message(self, srv, msg, private=False, data=None):
"""Queued the message for treatment""" """Queued the message for treatment"""
#print("READ", raw_msg) #print("READ", raw_msg)
self.cnsr_queue.put_nowait(MessageConsumer(srv, raw_msg, datetime.now(), private, data)) self.cnsr_queue.put_nowait(MessageConsumer(srv, msg))
# Launch a new thread if necessary # Launch a new thread if necessary
self._launch_consumers() self._launch_consumers()

View File

@ -35,14 +35,10 @@ class MessageConsumer:
"""Store a message before treating""" """Store a message before treating"""
def __init__(self, srv, raw, time, prvt, data): def __init__(self, srv, msg):
self.srv = srv self.srv = srv
self.raw = raw
self.time = time
self.prvt = prvt
self.data = data
self.msgs = list() self.msgs = [ msg ]
self.responses = None self.responses = None
@ -181,10 +177,8 @@ class MessageConsumer:
def run(self, context): def run(self, context):
"""Create, parse and treat the message""" """Create, parse and treat the message"""
try: try:
# Parse and create the original message for msg in self.msgs:
msg = Message(self.raw, self.time, self.prvt) self.first_treat(msg)
self.first_treat(msg)
self.msgs.append(msg)
# Run pre-treatment: from Message to [ Message ] # Run pre-treatment: from Message to [ Message ]
self.pre_treat(context.hooks) self.pre_treat(context.hooks)
@ -197,7 +191,7 @@ class MessageConsumer:
if self.responses is not None and len(self.responses) > 0: if self.responses is not None and len(self.responses) > 0:
self.post_treat(context.hooks) self.post_treat(context.hooks)
except: except:
logger.exception("Error occurred during the processing of the message: %s", self.raw) logger.exception("Error occurred during the processing of the message: %s", self.msgs[0].raw)
return return
#return self.responses #return self.responses

View File

@ -16,6 +16,9 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime
from message import Message
import server import server
from server.socket import SocketServer from server.socket import SocketServer
@ -88,3 +91,7 @@ class IRCServer(SocketServer):
def _close(self): def _close(self):
if self.socket is not None: self.write("QUIT") if self.socket is not None: self.write("QUIT")
return SocketServer._close(self) return SocketServer._close(self)
def read(self):
for line in SocketServer.read(self):
yield Message(line, datetime.now())