-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflood.py
135 lines (122 loc) · 4.33 KB
/
flood.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
from telethon import TelegramClient, events #pip install telethon
from telethon.tl.functions.channels import JoinChannelRequest
import asyncio
import csv
from random import shuffle, randint
import sched
from datetime import datetime
import time as time_module
import socks #pip install pysocks
Shuffling = True ##### 0. True if shuffle; False if not shuffle #####
read_file = 'messages.csv' ##### 1. Adjust message file name #####
msg_list = []
with open(read_file, encoding='UTF-8') as f:
rows = csv.reader(f,delimiter="|",lineterminator="\n")
for row in rows:
msg_list.append(row[0])
if Shuffling == True: shuffle(msg_list)
print("msg_list:")
print(msg_list)
input_file = 'phones.csv' ##### 2. Adjust phone file name #####
users = []
with open(input_file, encoding='UTF-8') as f:
rows = csv.reader(f,delimiter=",",lineterminator="\n")
next(rows, None)
for row in rows:
user = {}
#user['channelName'] = row[0] ### Uncomment this line, & comment the below for actual work
user['channelName'] = 'testingChannel' ### debugging & testing channel
user['id'] = int(row[1])
user['phone'] = row[2]
user['msg_num'] = int(row[3])
users.append(user)
shuffle(users)
print("users:")
print(users)
proxy_file = 'proxy.csv' ##### proxy file #####
proxies = []
with open(proxy_file, encoding='UTF-8') as f:
rows = csv.reader(f,delimiter=",",lineterminator="\n")
next(rows, None)
for row in rows:
proxy = {}
proxy['proxy_type'] = row[0]
proxy['addr'] = row[1]
proxy['port'] = int(row[2])
proxy['username'] = row[3]
proxy['password'] = row[4]
proxies.append(proxy)
len_users = len(users)
bound = []
division = len_users // len(proxies)
print("division", division)
for x in range(len(proxies)):
pack_range = (x + 1) * division
bound.append(pack_range)
bound.pop()
bound.append(len_users)
def getProxy(user_idx):
if len_users < len(proxies): #proxy_no. > user_no.
return proxies[user_idx]
for i in bound:
if user_idx < i:
return proxies[bound.index(i)]
API_ID = ******** #E.g. 1234567
API_HASH = "********" #E.g. "string30624700string"
phones = []
itr = 0
for num in users:
phones.append(users[itr]['phone'])
itr+=1
print(phones)
clients = []
n = 0
for phone in phones:
try:
print(str(n+1) + ". Adding " + phone)
a = TelegramClient(phone, api_id=API_ID, api_hash=API_HASH) #, proxy=getProxy(n)) ##### Proxy feature temporarily disabled
a.start(phone)
clients.append(a)
print(phone + " has been added.")
except:
print(phone + " failed to be added. Probably got banned?")
n += 1
########### Important Shuffling block ###########
client_phone_msg_channel = []
i = 0
m = 0
for phone in phones:
try:
for x in range(users[i]['msg_num']):
everything = [clients[i],phone,msg_list[m],users[i]['channelName']]
client_phone_msg_channel.append(everything)
m+=1
i+=1
except:
print("Msg list & users out of range...")
break
if Shuffling == True: shuffle(client_phone_msg_channel)
###################### End ######################
########### Time block ###########
def myfunc(): print("Working at ", datetime.now())
scheduler = sched.scheduler(time_module.time, time_module.sleep)
t = time_module.strptime('2021-07-17 08:50:00', '%Y-%m-%d %H:%M:%S') ##### 3. Adjust when launch #####
t = time_module.mktime(t)
scheduler_e = scheduler.enterabs(t, 1, myfunc, ())
print("Waiting at ", datetime.now())
scheduler.run()
print("Move on to main()")
############## End ###############
async def main():
abc = input("Type anything to continue: ") # Comment if already scheduled.
for everything in client_phone_msg_channel:
try:
print(everything[1] + " is joining channel")
await everything[0](JoinChannelRequest(everything[3]))
print(everything[1] + " is sending" + '\"' + everything[2] + '\"')
await everything[0].send_message(everything[3], everything[2]) ##### Comment this line, to just join group
await asyncio.sleep(randint(1, 1)) ##### 4. Adjust random interval #####
except:
print(everything[1] + " cannot write message")
with clients[0]:
clients[0].loop.run_until_complete(main())