-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathvodkabot.py
259 lines (234 loc) · 10.4 KB
/
vodkabot.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# -*- coding: utf-8 -*-
from LineAlpha import LineClient
from LineAlpha.LineApi import LineTracer
from LineAlpha.LineThrift.ttypes import Message
from LineAlpha.LineThrift.TalkService import Client
import time, datetime, random ,sys, re, string, os, json
reload(sys)
sys.setdefaultencoding('utf-8')
client = LineClient()
client._qrLogin("line://au/q/")
profile, setting, tracer = client.getProfile(), client.getSettings(), LineTracer(client)
offbot, messageReq, wordsArray, waitingAnswer = [], {}, {}, {}
print client._loginresult()
wait = {
'readPoint':{},
'readMember':{},
'setTime':{},
'ROM':{}
}
setTime = {}
setTime = wait["setTime"]
def sendMessage(to, text, contentMetadata={}, contentType=0):
mes = Message()
mes.to, mes.from_ = to, profile.mid
mes.text = text
mes.contentType, mes.contentMetadata = contentType, contentMetadata
if to not in messageReq:
messageReq[to] = -1
messageReq[to] += 1
client._client.sendMessage(messageReq[to], mes)
def NOTIFIED_ADD_CONTACT(op):
try:
sendMessage(op.param1, client.getContact(op.param1).displayName + "Thanks for add")
except Exception as e:
print e
print ("\n\nNOTIFIED_ADD_CONTACT\n\n")
return
tracer.addOpInterrupt(5,NOTIFIED_ADD_CONTACT)
def NOTIFIED_ACCEPT_GROUP_INVITATION(op):
#print op
try:
sendMessage(op.param1, client.getContact(op.param2).displayName + "WELCOME to " + group.name)
except Exception as e:
print e
print ("\n\nNOTIFIED_ACCEPT_GROUP_INVITATION\n\n")
return
tracer.addOpInterrupt(17,NOTIFIED_ACCEPT_GROUP_INVITATION)
def NOTIFIED_KICKOUT_FROM_GROUP(op):
try:
sendMessage(op.param1, client.getContact(op.param3).displayName + " Good Bye\n(*´・ω・*)")
except Exception as e:
print e
print ("\n\nNOTIFIED_KICKOUT_FROM_GROUP\n\n")
return
tracer.addOpInterrupt(19,NOTIFIED_KICKOUT_FROM_GROUP)
def NOTIFIED_LEAVE_GROUP(op):
try:
sendMessage(op.param1, client.getContact(op.param2).displayName + " Good Bye\n(*´・ω・*)")
except Exception as e:
print e
print ("\n\nNOTIFIED_LEAVE_GROUP\n\n")
return
tracer.addOpInterrupt(15,NOTIFIED_LEAVE_GROUP)
def NOTIFIED_READ_MESSAGE(op):
#print op
try:
if op.param1 in wait['readPoint']:
Name = client.getContact(op.param2).displayName
if Name in wait['readMember'][op.param1]:
pass
else:
wait['readMember'][op.param1] += "\n・" + Name
wait['ROM'][op.param1][op.param2] = "・" + Name
else:
pass
except:
pass
tracer.addOpInterrupt(55, NOTIFIED_READ_MESSAGE)
def RECEIVE_MESSAGE(op):
msg = op.message
try:
if msg.contentType == 0:
try:
if msg.to in wait['readPoint']:
if msg.from_ in wait["ROM"][msg.to]:
del wait["ROM"][msg.to][msg.from_]
else:
pass
except:
pass
else:
pass
except KeyboardInterrupt:
sys.exit(0)
except Exception as error:
print error
print ("\n\nRECEIVE_MESSAGE\n\n")
return
tracer.addOpInterrupt(26, RECEIVE_MESSAGE)
def SEND_MESSAGE(op):
msg = op.message
try:
if msg.toType == 0:
if msg.contentType == 0:
if msg.text == "mid":
sendMessage(msg.to, msg.to)
if msg.text == "me":
sendMessage(msg.to, text=None, contentMetadata={'mid': msg.from_}, contentType=13)
if msg.text == "gift":
sendMessage(msg.to, text="gift sent", contentMetadata=None, contentType=9)
else:
pass
else:
pass
if msg.toType == 2:
if msg.contentType == 0:
if msg.text == "mid":
sendMessage(msg.to, msg.from_)
if msg.text == "gid":
sendMessage(msg.to, msg.to)
if msg.text == "ginfo":
group = client.getGroup(msg.to)
md = "[Group Name]\n" + group.name + "\n\n[gid]\n" + group.id + "\n\n[Group Picture]\nhttp://dl.profile.line-cdn.net/" + group.pictureStatus
if group.preventJoinByTicket is False: md += "\n\nInvitationURL: Permitted\n"
else: md += "\n\nInvitationURL: Refusing\n"
if group.invitee is None: md += "\nMembers: " + str(len(group.members)) + "人\n\nInviting: 0People"
else: md += "\nMembers: " + str(len(group.members)) + "People\nInvited: " + str(len(group.invitee)) + "People"
sendMessage(msg.to,md)
if "gname:" in msg.text:
key = msg.text[22:]
group = client.getGroup(msg.to)
group.name = key
client.updateGroup(group)
sendMessage(msg.to,"Group Name"+key+"Canged to")
if msg.text == "url":
sendMessage(msg.to,"line://ti/g/" + client._client.reissueGroupTicket(msg.to))
if msg.text == "open":
group = client.getGroup(msg.to)
if group.preventJoinByTicket == False:
sendMessage(msg.to, "already open")
else:
group.preventJoinByTicket = False
client.updateGroup(group)
sendMessage(msg.to, "URL Open")
if msg.text == "close":
group = client.getGroup(msg.to)
if group.preventJoinByTicket == True:
sendMessage(msg.to, "already close")
else:
group.preventJoinByTicket = True
client.updateGroup(group)
sendMessage(msg.to, "URL close")
if "kick:" in msg.text:
key = msg.text[5:]
client.kickoutFromGroup(msg.to, [key])
contact = client.getContact(key)
sendMessage(msg.to, ""+contact.displayName+"sorry")
if "nk:" in msg.text:
key = msg.text[3:]
group = client.getGroup(msg.to)
Names = [contact.displayName for contact in group.members]
Mids = [contact.mid for contact in group.members]
if key in Names:
kazu = Names.index(key)
sendMessage(msg.to, "Bye")
client.kickoutFromGroup(msg.to, [""+Mids[kazu]+""])
contact = client.getContact(Mids[kazu])
sendMessage(msg.to, ""+contact.displayName+" Sorry")
else:
sendMessage(msg.to, "wtf?")
if msg.text == "cancel":
group = client.getGroup(msg.to)
if group.invitee is None:
sendMessage(op.message.to, "No one is inviting.")
else:
gInviMids = [contact.mid for contact in group.invitee]
client.cancelGroupInvitation(msg.to, gInviMids)
sendMessage(msg.to, str(len(group.invitee)) + " Done")
if "invite:" in msg.text:
key = msg.text[-33:]
client.findAndAddContactsByMid(key)
client.inviteIntoGroup(msg.to, [key])
contact = client.getContact(key)
sendMessage(msg.to, ""+contact.displayName+" I invited you")
if msg.text == "me":
M = Message()
M.to = msg.to
M.contentType = 13
M.contentMetadata = {'mid': msg.from_}
client.sendMessage(M)
if "show:" in msg.text:
key = msg.text[-33:]
sendMessage(msg.to, text=None, contentMetadata={'mid': key}, contentType=13)
contact = client.getContact(key)
sendMessage(msg.to, ""+contact.displayName+"'s contact")
if msg.text == "time":
sendMessage(msg.to, "Current time is" + datetime.datetime.today().strftime('%Y年%m月%d日 %H:%M:%S') + "is")
if msg.text == "gift":
sendMessage(msg.to, text="gift sent", contentMetadata=None, contentType=9)
if msg.text == "set":
sendMessage(msg.to, "I have set a read point ♪\n「tes」I will show you who I have read ♪")
try:
del wait['readPoint'][msg.to]
del wait['readMember'][msg.to]
except:
pass
wait['readPoint'][msg.to] = msg.id
wait['readMember'][msg.to] = ""
wait['setTime'][msg.to] = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
wait['ROM'][msg.to] = {}
print wait
if msg.text == "tes":
if msg.to in wait['readPoint']:
if wait["ROM"][msg.to].items() == []:
chiya = ""
else:
chiya = ""
for rom in wait["ROM"][msg.to].items():
print rom
chiya += rom[1] + "\n"
sendMessage(msg.to, "People who readed %s\nthat's it\n\nPeople who have ignored reads\n%sIt is abnormal ♪\n\nReading point creation date n time:\n[%s]" % (wait['readMember'][msg.to],chiya,setTime[msg.to]))
else:
sendMessage(msg.to, "An already read point has not been set.\n「set」you can send ♪ read point will be created ♪")
else:
pass
else:
pass
except Exception as e:
print e
print ("\n\nSEND_MESSAGE\n\n")
return
tracer.addOpInterrupt(25,SEND_MESSAGE)
while True:
tracer.execute()