-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
121 lines (93 loc) · 4.44 KB
/
bot.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
#!/usr/bin/env python3
# Simple Discord SelfBot
# Created By Viloid ( github.com/vsec7 )
# Use At Your Own Risk
import requests, random, sys, yaml, time
class Discord:
def __init__(self, t):
self.base = "https://discord.com/api/v9"
self.auth = { 'authorization': t }
def getMe(self):
u = requests.get(self.base + "/users/@me", headers=self.auth).json()
return u
def getMessage(self, cid, l):
u = requests.get(self.base + "/channels/" + str(cid) + "/messages?limit=" + str(l), headers=self.auth).json()
return u
def sendMessage(self, cid, txt):
u = requests.post(self.base + "/channels/" + str(cid) + "/messages", headers=self.auth, json={ 'content': txt }).json()
return u
def replyMessage(self, cid, mid, txt):
u = requests.post(self.base + "/channels/" + str(cid) + "/messages", headers=self.auth, json={ 'content': txt, 'message_reference': { 'message_id': str(mid) } }).json()
return u
def deleteMessage(self, cid, mid):
u = requests.delete(self.base + "/channels/" + str(cid) + "/messages/" + str(mid), headers=self.auth)
return u
def quote():
u = requests.get("https://raw.githubusercontent.com/JamesFT/Database-Quotes-JSON/master/quotes.json").json()
return random.choice(list(u))['quoteText']
def simsimi(lc, txt):
u = requests.post("https://api.simsimi.info/v1/simtalk", data={ 'lc': lc, 'text': txt}).json()
return u['message']
def main():
with open('config.yaml') as cfg:
conf = yaml.load(cfg, Loader=yaml.FullLoader)
if not conf['BOT_TOKEN']:
print("[!] Please provide discord token at config.yaml!")
sys.exit()
if not conf['CHANNEL_ID']:
print("[!] Please provide channel id at config.yaml!")
sys.exit()
mode = conf['MODE']
simi_lc = conf['SIMSIMI_LANG']
delay = conf['DELAY']
del_after = conf['DEL_AFTER']
repost_last = conf['REPOST_LAST_CHAT']
if not mode:
mode = "quote"
if not simi_lc:
simi_lc = "id"
if not repost_last:
repost_last = "100"
while True:
for token in conf['BOT_TOKEN']:
try:
for chan in conf['CHANNEL_ID']:
Bot = Discord(token)
me = Bot.getMe()['username'] + "#" + Bot.getMe()['discriminator']
if mode == "quote":
q = quote()
send = Bot.sendMessage(chan, q)
print("[{}][{}][QUOTE] {}".format(me, chan, q))
if del_after:
Bot.deleteMessage(chan, send['id'])
print("[{}][DELETE] {}".format(me, send['id']))
elif mode == "repost":
res = Bot.getMessage(chan, repost_last)
getlast = list(reversed(res))[0]
send = Bot.sendMessage(chan, getlast['content'])
print("[{}][{}][REPOST] {}".format(me, chan, getlast['content']))
if del_after:
Bot.deleteMessage(chan, send['id'])
print("[{}][DELETE] {}".format(me, send['id']))
elif mode == "simsimi":
res = Bot.getMessage(chan, "1")
getlast = list(reversed(res))[0]
simi = simsimi(simi_lc, getlast['content'])
if conf['REPLY']:
send = Bot.replyMessage(chan, getlast['id'], simi)
print("[{}][{}][SIMSIMI] {}".format(me, chan, simi))
else:
send = Bot.sendMessage(chan, simi)
print("[{}][{}][SIMSIMI] {}".format(me, chan, simi))
if del_after:
Bot.deleteMessage(chan, send['id'])
print("[{}][DELETE] {}".format(me, send['id']))
except:
print(f"[Error] {token} : INVALID TOKEN / KICKED FROM GUILD!")
print("-------[ Delay for {} seconds ]-------".format(delay))
time.sleep(delay)
if __name__ == '__main__':
try:
main()
except Exception as err:
print(f"{type(err).__name__} : {err}")