-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
149 lines (126 loc) · 3.25 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
import thread
import time
import server
import irc
import nick
import follow
import sys
import cosRes
import emoticons
reload(sys)
sys.setdefaultencoding("utf-8")
inroom = False
# Define a function for the thread
pre_user = ""
pre_pass = ""
pre_room = ""
stop = False
def command(x):
if x == "stop":
stop = True
server.stop_server()
IRC.stop()
sys.exit()
elif x == "nick load":
Nick.load()
elif x == "follow load":
Follow.get_follow()
elif x == "setting load":
cos.load()
elif x == "ping":
print 'ping call'
r = IRC.send('PING :103\n')
if not r:
print 'limit'
else:
r = IRC.send(x + '\n')
if not r:
print 'limit'
def server_go(threadName):
server.start_server(10000,command,pre_room)
def irc_connect(threadName):
global Nick,IRC
global Follow
global pre_user,pre_room,pre_pass
global cos,emo
cos = cosRes.cosRes(IRC,pre_room,server)
emo = emoticons.emotion()
cos.load()
Nick.load()
Follow.get_follow()
emo.load()
while server.wss == []:
time.sleep(1)
server.send('1Connecting Twitch server')
while not IRC.connect():
time.sleep(5)
server.send('1Server Connected')
IRC.send('PASS ' + pre_pass + '\n')
IRC.send('NICK ' + pre_user + '\n')
IRC.send('JOIN #'+ pre_room + '\n')
tmp = ""
while IRC.timed:
s = IRC.recv()
tmp += s
#print tmp
if tmp.find('\n') != -1:
ss = tmp.split('\n')
for ns in range(len(ss)-1):
msgoab(ss[ns][0:len(ss[ns])-1])
tmp = ss[len(ss)-1]
def msgoab(msg):
global IRC
#print msg
if msg == "PING :tmi.twitch.tv":
IRC.send("PONG :tmi.twitch.tv\n")
#print 'ping call'
elif msg == ":tmi.twitch.tv PONG tmi.twitch.tv :103":
print 'ping recall'
else:
global inroom
if inroom:
ss = msg.split(':')[1]
user = ss.split('!')[0]
st = msg.split(':')
text = st[2]
if len(st) > 3:
for tm in range(3,len(st)):
text += ":" + st[tm]
global pre_user
global Nick
if user == pre_room:
server.send("2<img src='setting/owner.png'/><span class='text3'>" + Nick.change(user) + ": " + emo.change(text).encode('utf-8').strip() + "</span>")
elif Follow.check(user):
server.send("2<img src='setting/follow.png'/><span class='text3'>" + Nick.change(user) + ": " + emo.change(text).encode('utf-8').strip() + "</span>")
else:
server.send("2" + Nick.change(user) + ": " + text)
#response for text
cos.cos_input(text,user,Nick.change(user))
#server.send(msg)
else:
try:
if msg.split(':')[2] == "End of /NAMES list":
inroom = True
server.send("1JOIN")
elif msg.split(':')[2] == "Error logging in":
server.send('0Loggin error, please check your password.')
except:
pass
if len(sys.argv) >= 4:
pre_user = sys.argv[1]
pre_pass = sys.argv[2]
pre_room = sys.argv[3]
try:
thread.start_new_thread( server_go, ("Thread-1",))
thread.start_new_thread( irc_connect, ("Thread-2",))
except:
print "Error: unable to start thread"
IRC = irc.IRC()
Nick = nick.Nick()
Follow = follow.follow(pre_room)
while True:
x = raw_input("")
command(x)
else:
print 'not enough args'