/
runbot.py
374 lines (344 loc) · 18.4 KB
/
runbot.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
from mydewsbotslib.linepy import *
from mydewsbotslib.akad.ttypes import *
from multiprocessing import Pool, Process
from datetime import datetime
from time import sleep
from bs4 import BeautifulSoup
from humanfriendly import format_timespan, format_size, format_number, format_length
import time, random, sys, json, codecs, threading, glob, re, string, os, requests, subprocess, six, ast, pytz, urllib, urllib.request, urllib.parse, urllib.error, urllib.parse,subprocess,unicodedata, timeit, atexit, traceback
_session = requests.session()
from gtts import gTTS
from firebase import firebase
firebase = firebase.FirebaseApplication("firebase", None)
line = LINE("@com","password")
print ("login success")
lineMID = line.profile.mid
lineProfile = line.getProfile()
lineSettings = line.getSettings()
oepoll = OEPoll(line)
Rfu = [line]
Exc = [line]
lineMID = line.getProfile().mid
RfuProtect = {
"autoAdd": {},
"protect": {},
"cancelprotect": {},
"inviteprotect": {},
"linkprotect": {},
"Protectjoin": {},
"Wc": {}
}
def sendMessageWithMention(to, lineMID):
try:
aa = '{"S":"0","E":"3","M":'+json.dumps(lineMID)+'}'
text_ = '@x '
line.sendMessage(to, text_, contentMetadata={'MENTION':'{"MENTIONEES":['+aa+']}'}, contentType=0)
except Exception as error:
logError(error)
def logError(text):
line.log("[ แจ้งเตือน ] " + str(text))
time_ = datetime.now()
with open("errorLog.txt","a") as error:
error.write("\n[%s] %s" % (str(time), text))
def myhelp():
myHelp = """>คำสั่งทั่วไป<
เช็ค =[เช็คว่าเราเปิดคำสั่งอะไรอยู่]
คำสั่ง =[คำสั่งทัวไป]
คำสั่ง1 =[โหมดบอทป้องกันกลุ่ม]
คำสั่ง2 =[โหมดในกลุ่ม]"""
return myHelp
def listgrup():
listGrup = """>โหมดในกลุ่ม<
ยัดดำ @ =[แบนไม่ให้เข้ากลุ่ม]
บัญชีดำ =[เช็คบัญชีดำ]
ล้างดำ =[ล้างบช.ดำ]"""
return listGrup
def helpset():
helpSet = """>โหมดป้องกันกลุ่ม<
>คำสั่งเปิดป้องกันทั้งหมด<
เปิดระบบป้องกัน/ปิดระบบป้องกัน
เปิดป้องกันลิ้ง/ปิดป้องกันลิ้ง
เปิดกันเข้า/ปิดกันเข้า
เปิดกันเชิญ/ปิดกันเชิญ
>ตั้งต้อนรับเปิดปิด<
ข้อความต้อนรับ: ข้อความ
เปิดข้อความ
ปิดข้อความ"""
return helpSet
def lineBot(op):
try:
if op.type == 0:
return
if op.type == 5:
RfuProtect = firebase.get("/setting",'')
if RfuProtect["autoAdd"] == True:
line.blockContact(op.param1)
if op.type in [25,26]:
msg = op.message
text = msg.text
msg_id = msg.id
receiver = msg.to
sender = msg._from
if msg.toType == 0 or msg.toType == 1 or msg.toType == 2:
if msg.toType == 0:
if sender != line.profile.mid:
to = sender
else:
to = receiver
elif msg.toType == 1:
to = receiver
elif msg.toType == 2:
to = receiver
if msg.contentType == 0:
RfuProtect = firebase.get("/setting",'')
if text is None:
return
elif msg.text in ["เช็ค"]:
try:
ret_ = "สถานะที่เปิดอยู่"
if RfuProtect["autoAdd"] == True: ret_ += "\nออโต้บล็อค✔"
else: ret_ += "\nออโต้บล็อค ✘ "
if RfuProtect["Wc"] == True: ret_ += "\nเปิดข้อความต้อนรับสมาชิก ✔"
else: ret_ += "\nเปิดข้อความต้อนรับสมาชิก ✘ "
if RfuProtect["inviteprotect"] == True: ret_ += "\nป้องกันเชิญเข้ากลุ่ม ✔"
else: ret_ += "\nป้องกันเชิญเข้ากลุ่ม ✘ "
if RfuProtect["cancelprotect"] == True: ret_ += "\nป้องกันยกเลิกค้างเชิญ ✔"
else: ret_ += "\nป้องกันยกเลิกค้างเชิญ ✘ "
if RfuProtect["protect"] == True: ret_ += "\nป้องกันลบสมาชิก ✔"
else: ret_ += "\nป้องกันลบสมาชิก ✘ "
if RfuProtect["linkprotect"] == True: ret_ += "\nป้องกันเปิดลิ้ง ✔"
else: ret_ += "\nป้องกันเปิดลิ้ง ✘ "
if RfuProtect["Protectjoin"] == True: ret_ += "\nป้องกันเข้ากลุ่ม ✔"
else: ret_ += "\nป้องกันเข้ากลุ่ม ✘ "
line.sendMessage(to, str(ret_))
sendMessageWithMention(to, lineMID)
line.sendMessage(to, "" +datetime.today().strftime('%H:%M:%S'))
except Exception as e:
line.sendMessage(msg.to, str(e))
elif msg.text in ["คำสั่ง","help"]:
myHelp = myhelp()
line.sendMessage(to, str(myHelp))
sendMessageWithMention(to, lineMID)
line.sendMessage(to, "" +datetime.today().strftime('%H:%M:%S')+ "")
elif msg.text in ["คำสั่ง1","help1"]:
helpSet = helpset()
line.sendMessage(to, str(helpSet))
sendMessageWithMention(to, lineMID)
line.sendMessage(to, "" +datetime.today().strftime('%H:%M:%S')+ "")
elif msg.text in ["คำสั่ง2","help2"]:
listGrup = listgrup()
line.sendMessage(to, str(listGrup))
sendMessageWithMention(to, lineMID)
line.sendMessage(to, "" +datetime.today().strftime('%H:%M:%S')+ "")
elif msg.text.lower().startswith("ไอดี "):
if 'MENTION' in list(msg.contentMetadata.keys())!= None:
names = re.findall(r'@(\w+)', text)
mention = ast.literal_eval(msg.contentMetadata['MENTION'])
mentionees = mention['MENTIONEES']
lists = []
for mention in mentionees:
if mention["M"] not in lists:
lists.append(mention["M"])
ret_ = ""
for ls in lists:
ret_ += "" + ls
line.sendMessage(msg.to, str(ret_))
elif msg.text.lower() == "เปิดระบบป้องกัน":
RfuProtect = firebase.get("/setting",'')
RfuProtect["protect"] = True
RfuProtect["cancelprotect"] = True
RfuProtect["inviteprotect"] = True
RfuProtect["linkprotect"] = True
RfuProtect["Protectjoin"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(to,"_เปิดระบบป้องกันทั้งหมด\n" +datetime.today().strftime('%H:%M:%S'))
elif msg.text in ["ปิดระบบป้องกัน"]:
RfuProtect = firebase.get("/setting",'')
RfuProtect["protect"] = False
RfuProtect["cancelprotect"] = False
RfuProtect["inviteprotect"] = False
RfuProtect["linkprotect"] = False
RfuProtect["Protectjoin"] = False
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(to,"_ปิดระบบป้องกันทั้งหมด\n" +datetime.today().strftime('%H:%M:%S'))
elif msg.text.lower() in ['เปิดป้องกันลิ้ง','เปิดป้องกันลิงค์']:
RfuProtect = firebase.get("/setting",'')
RfuProtect["linkprotect"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_เปิดป้องกันลิ้งแล้ว")
elif msg.text.lower() in ['ปิดป้องกันลิ้ง','ปิดป้องกันลิงค์']:
RfuProtect = firebase.get("/setting",'')
RfuProtect["linkprotect"] = False
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_ปิดป้องกันลิ้งแล้ว")
elif msg.text.lower() == 'เปิดกันเข้า':
RfuProtect = firebase.get("/setting",'')
RfuProtect["Protectjoin"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_เปิดกันเข้ากลุ่ม")
elif msg.text.lower() == 'ปิดกันเข้า':
RfuProtect = firebase.get("/setting",'')
RfuProtect["Protectjoin"] = False
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_ปิดกันเข้ากลุ่ม")
elif msg.text.lower() == 'เปิดกันเชิญ':
RfuProtect = firebase.get("/setting",'')
RfuProtect["inviteprotect"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_เปิดป้องกันเชิญเข้ากลุ่ม")
elif msg.text.lower() == 'ปิดกันเชิญ':
RfuProtect = firebase.get("/setting",'')
RfuProtect["inviteprotect"] = False
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_ปิดป้องกันเชิญเข้ากลุ่ม")
elif msg.text.lower() == 'เปิดกันยกเลิกเชิญ':
RfuProtect = firebase.get("/setting",'')
RfuProtect["cancelprotect"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_เปิดป้องกันยกเลิกเชิญ")
elif msg.text.lower() == 'ปิดกันยกเลิกเชิญ':
RfuProtect = firebase.get("/setting",'')
RfuProtect["cancelprotect"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(msg.to,"_เปิดป้องกันยกเลิกเชิญ")
elif msg.text in ["เปิดข้อความ"]:
RfuProtect = firebase.get("/setting",'')
RfuProtect["Wc"] = True
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(to,"_เปิดข้อความตอนรับ")
elif msg.text in ["ปิดข้อความ"]:
RfuProtect = firebase.get("/setting",'')
RfuProtect["Wc"] = False
result = firebase.put('',"/setting",RfuProtect)
line.sendMessage(to,"_ปิดข้อความตอนรับ")
elif msg.text in ["ล้างดำ"]:
try:
result = firebase.delete("/banlist",'')
datapass = { 'id' : 'dummy'}
result = firebase.post("/banlist",datapass)
except:
pass
line.sendMessage(msg.to,"_ล้างบัญชีดำเรียบร้อย")
print ("Clear Ban")
elif msg.text in ["เช็คดำ","บัญชีดำ"]:
result = firebase.get("/banlist",'')
banlist = {'id': {}}
try:
for data in result:
banlist["id"][result[data]["id"]] = True
except:
pass
if banlist["id"] == {}:
line.sendMessage(msg.to,"ไม่มีลิสในบัญชีดำ")
else:
line.sendMessage(msg.to,"รายชื่อบัญชีดำ " +datetime.today().strftime('%H:%M:%S'))
mc = "<Blacklist>\n"
for mi_d in banlist["id"]:
mc += "[" + line.getContact(mi_d).displayName + "] \n"
line.sendMessage(msg.to, mc + "")
elif 'ยัดดำ' in text.lower():
targets = []
key = eval(msg.contentMetadata["MENTION"])
key["MENTIONEES"] [0] ["M"]
for x in key["MENTIONEES"]:
targets.append(x["M"])
for target in targets:
try:
datapass = {
'id' : str(target)
}
result = firebase.post("/banlist",datapass)
line.sendMessage(msg.to,"ยัดดำเรียบร้อยแล้ว")
print ("Banned User")
except:
line.sendMessage(msg.to,"ไม่สามารถยัดดำได้")
if op.type == 19:
adminlist = {'id':{}}
result = firebase.get("/adminlist",'')
for data in result:
adminlist["id"][result[data]["id"]] = True
if op.param3 in adminlist["id"]:
random.choice(Rfu).inviteIntoGroup(op.param1,[op.param3])
print("adminkick")
if op.param2 in adminlist["id"]:
pass
elif RfuProtect["protect"] == True:
datapost = {
'id': str(op.param2)
}
result = firebase.post("/banlist",datapost)
random.choice(Rfu).kickoutFromGroup(op.param1,[op.param2])
random.choice(Rfu).inviteIntoGroup(op.param1,[op.param3])
if op.type == 11:
adminlist = {'id':{}}
result = firebase.get("/adminlist",'')
for data in result:
adminlist["id"][result[data]["id"]] = True
if RfuProtect["linkprotect"] == True:
if op.param2 in adminlist["id"]:
pass
print("admin open link")
else:
datapost = {'id': str(op.param2)}
try:
result = firebase.post("/banlist",datapost)
except Exception as error:
logError(error)
G = line.getGroup(op.param1)
G.preventedJoinByTicket = True
random.choice(Rfu).updateGroup(G)
random.choice(Rfu).kickoutFromGroup(op.param1,[op.param2])
if op.type == 17:
RfuProtect = firebase.get("/setting",'')
if RfuProtect["Wc"] == True:
if op.param2 in lineMID:
return
dan = line.getContact(op.param2)
tgb = line.getGroup(op.param1)
line.sendMessage(op.param1, "ยินดีต้อนรับ" + "\n"+"\n{}\n{}".format(str(dan.displayName),str(tgb.name)))
if op.type == 13:
adminlist = {'id':{}}
result = firebase.get("/adminlist",'')
for data in result:
adminlist["id"][result[data]["id"]] = True
if op.param2 in adminlist["id"]:
group = line.getGroup(op.param1)
line.acceptGroupInvitation(op.param1)
if op.type == 17:
adminlist = {'id':{}}
result = firebase.get("/adminlist",'')
for data in result:
adminlist["id"][result[data]["id"]] = True
if op.param2 in adminlist["id"]:
pass
if RfuProtect["protect"] == True:
if settings["blacklist"][op.param2] == True:
try:
line.kickoutFromGroup(op.param1,[op.param2])
G = line.getGroup(op.param1)
G.preventedJoinByTicket = True
line.updateGroup(G)
except:
try:
line.kickoutFromGroup(op.param1,[op.param2])
G = line.getGroup(op.param1)
G.preventedJoinByTicket = True
line.updateGroup(G)
except:
pass
except Exception as error:
logError(error)
def restartBot():
print ("RESTART BOT")
time.sleep(3)
python = sys.executable
os.execl(python, python, *sys.argv)
while True:
try:
ops = oepoll.singleTrace(count=5)
if ops is not None:
for op in ops:
lineBot(op)
oepoll.setRevision(op.revision)
except Exception as e:
logError(e)