forked from Merubokkusu/Discord-S.C.U.M
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multibots.py
42 lines (34 loc) · 1.58 KB
/
multibots.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
#this first part is preparation. All we're doing is appending bot objects to a list so that we can access them from 1 spot later.
#we're also adding some functions to the gateway command list of each bot. Since each bot obj is different,
#we can pass in the bot object into the closeAfterReadySupp gateway function.
import discum
with open("tokenlist.txt") as f:
tokenlist = f.read().splitlines()
def closeAfterReadySupp(resp, bot):
if resp.event.ready_supplemental:
bot.gateway.close()
clients = []
for i in range(len(tokenlist)):
if i==0:
clients.append(discum.Client(token=tokenlist[0]))
build_num = clients[0]._Client__super_properties['client_build_number']
else:
newBot = discum.Client(token=tokenlist[i], build_num=build_num)
newBot.s.cookies.update(clients[0].s.cookies)
clients.append(newBot)
clients[i].gateway.command({"function":closeAfterReadySupp, "params":{"bot":clients[i]}}) #add closeAfterReadySupp to each bot
#now for the fun part
#we use threading to make it run fast. You can use multiprocessing or subprocess if you'd like to instead. This is just one implementation.
import threading
def gatewayRunner(bot, result, index):
bot.gateway.run()
result[index] = bot.gateway.session.user
num_clients = len(clients)
threads = [None] * num_clients
results = [None] * num_clients
for i in range(num_clients):
threads[i] = threading.Thread(target=gatewayRunner, args=(clients[i] , results, i)) #https://stackoverflow.com/a/6894023/14776493
threads[i].start()
#results is a list containing all the client data (bot.gateway.session.user stuff)
for i in results:
print(i)