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
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"""
#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
self._launch_consumers()

View File

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

View File

@ -16,6 +16,9 @@
# 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/>.
from datetime import datetime
from message import Message
import server
from server.socket import SocketServer
@ -88,3 +91,7 @@ class IRCServer(SocketServer):
def _close(self):
if self.socket is not None: self.write("QUIT")
return SocketServer._close(self)
def read(self):
for line in SocketServer.read(self):
yield Message(line, datetime.now())