-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplyer.py
51 lines (44 loc) · 1.65 KB
/
replyer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# coding: utf8
from __future__ import unicode_literals
import IRC
import message_parsing
import mythread
from utils import print_message
class Replyer(mythread.Thread):
"""
class designed to search for the good socket and then reply with it
"""
def __init__(self):
mythread.Thread.__init__(self)
self.socks = []
def add_sock(self, sock):
"""
add a new IRC socket to pool
:param sock: the socket to add (IRC sock)
:return: Nothing what did you expect
"""
if not isinstance(sock, IRC.Socket):
raise TypeError
self.socks.append(sock)
print_message("[!] adding sock {} to replyer".format(sock))
def main(self):
"""
main loop, search for the right socket and send Message through it
:return: Nothing what did you expect
"""
reply = self.queue.get()
print ("[D] replyer message {}".format(reply))
print ("[D] replyer message {}".format(reply.construct_message()))
if isinstance(reply, message_parsing.Message):
for sock in self.socks:
if reply.pseudo == sock.username:
if reply.server == sock.server:
if not reply.target.startswith("#"):
sock.send(reply.construct_message())
return
elif reply.target == sock.channel:
sock.send(reply.construct_message())
return
print ("NO MATCH for {}!!!\nSock available:\n".format(reply))
for sock in self.socks:
print (sock)