Can pass data from message reception to message response

This commit is contained in:
Némunaire 2012-08-31 03:52:49 +02:00
parent e881fc8ba5
commit 30da270557
3 changed files with 6 additions and 6 deletions

4
bot.py
View File

@ -158,9 +158,9 @@ class Bot(BotCaps):
return False return False
def receive_message(self, srv, raw_msg, private = False): def receive_message(self, srv, raw_msg, private=False, data=None):
"""Queued the message for treatment""" """Queued the message for treatment"""
self.msg_queue.put_nowait((srv, raw_msg, datetime.now(), private)) self.msg_queue.put_nowait((srv, raw_msg, datetime.now(), private, data))
# Launch a new thread if necessary # Launch a new thread if necessary
if self.msg_queue.qsize() > self.msg_thrd_size: if self.msg_queue.qsize() > self.msg_thrd_size:

View File

@ -33,7 +33,7 @@ class Consumer(threading.Thread):
def run(self): def run(self):
try: try:
while not self.stop: while not self.stop:
(srv, raw, time, prvt) = self.context.msg_queue.get(True, 20) (srv, raw, time, prvt, data) = self.context.msg_queue.get(True, 20)
# Create, parse and treat the message # Create, parse and treat the message
try: try:
@ -52,9 +52,9 @@ class Consumer(threading.Thread):
if isinstance(res, list): if isinstance(res, list):
for r in res: for r in res:
if isinstance(r, Response): if isinstance(r, Response):
srv.send_response(r) srv.send_response(r, data)
elif isinstance(res, Response): elif isinstance(res, Response):
srv.send_response(res) srv.send_response(res, data)
except queue.Empty: except queue.Empty:
pass pass

View File

@ -110,7 +110,7 @@ class Server(threading.Thread):
def send_pong(self, cnt): def send_pong(self, cnt):
self.s.send(("PONG %s\r\n" % cnt).encode ()) self.s.send(("PONG %s\r\n" % cnt).encode ())
def send_response(self, res): def send_response(self, res, origin):
if res.channel is not None and res.channel != self.nick: if res.channel is not None and res.channel != self.nick:
self.send_msg(res.channel, res.get_message()) self.send_msg(res.channel, res.get_message())