This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
/
InterChatDispatcher.py
67 lines (64 loc) · 2.87 KB
/
InterChatDispatcher.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from ConfigProvider import ConfigProvider
from GatesProvider import GatesProvider
from ChatManager import ChatManager
from IRCThread import IRCThread
from InterChatSkypeThread import InterChatSkypeThread
class InterChatDispatcher():
__state = {}
def __init__(self):
if(self.__state):
self.__dict__ = self.__state
else:
self.configProvider = ConfigProvider()
self.gatesProvider = GatesProvider()
self.chatMgr = ChatManager()
def launch(self):
#launch irc
irc_config = self.configProvider.getConfigSection('irc');
self.irc_thread = IRCThread( irc_config['host'], irc_config['port'], irc_config['nick'], irc_config['channels'], self)
self.connexion = self.irc_thread.getConnexion()
self.irc_thread.start()
self.skype_thread = InterChatSkypeThread(self)
self.skype_thread.start()
def dispatchIRCCommand(self, nick, message, channel):
print "Message: "+message+" From " + channel
return "oui"
def dispatchMessageToChannel(self, channel, message):
channelTo = self.chatMgr.getChanelByAlias(channel)
if(channelTo['type'] == 'irc'):
self.irc_thread.writeToChannel(message, channelTo['channel'])
if(channelTo['type'] == 'skype'):
self.skype_thread.writeToChannel(message, channelTo['channel'])
def messageToChannel(self, channel, message, nick=""):
parts = message.split(" ")
if(len(parts) > 1 and self.chatMgr.getChanelByAlias(parts[1])):
channelTo = self.chatMgr.getChanelByAlias(parts[1])
body = message.replace("!tele "+parts[1],"")
rmessage = "tele from {0}@{1}: {2}".format(nick, channel, body)
if(channelTo['type'] == 'irc'):
self.irc_thread.writeToChannel(rmessage, channelTo['channel'])
elif(channelTo['type'] == 'skype'):
self.skype_thread.writeToChannel(rmessage, channelTo['channel'])
def helpToChannel(self, channel, message):
with open('config/help.txt','r') as f:
for i,l in enumerate(f):
self.dispatchMessageToChannel(channel, l)
def getChannelList(self):
return self.chatMgr.getAliases()
def dispatchMessage(self, chatname, sendername, body):
# print body
channel = self.chatMgr.getChanelById(chatname)
if( sendername in ['pdobot', 'ictelecom'] ):
return False;
for channelTo in self.chatMgr.getAliases():
channelToFull = self.chatMgr.getChanelByAlias(channelTo)
if(self.chatMgr.isListening(channelTo, channel['alias'])):
print "BINGO"
if (channelToFull['type'] == 'irc'):
message = "{0}{1}: {2}".format(sendername, channel['alias'], body)
self.irc_thread.writeToChannel(message, channelTo)
return False
def listenChatOn(self, channel1, channel2):
return self.chatMgr.turnListenOn(channel1, channel2)
def listenChatOff(self, channel1, channel2):
return self.chatMgr.turnListenOff(channel1, channel2)