forked from termuxprofessor/Telegram-Scraper-Adder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadder.py
163 lines (146 loc) · 6.02 KB
/
adder.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
from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError
from telethon.tl.functions.channels import InviteToChannelRequest
import configparser
import os
import sys
import csv
import traceback
import time
import random
from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError,UserNotMutualContactError,UserKickedError,FloodWaitError,UserChannelsTooMuchError,UserBannedInChannelError
from telethon.errors.rpcbaseerrors import UnauthorizedError
re="\033[1;31m"
gr="\033[1;32m"
cy="\033[1;36m"
print (re+" __ __ .______ _______ .______ __ ______ ____ ____ _______ _______. ______ ______ .___ ___. ")
print (gr+"| | | | | _ \ | ____|| _ \ | | / __ \ \ \ / / | ____| / | / | / __ \ | \/ | ")
print (re+"| | | | | |_) | | |__ | |_) | | | | | | | \ \/ / | |__ | (----` | ,----'| | | | | \ / | ")
print (re+"| | | | | _ < | __| | / | | | | | | \ / | __| \ \ | | | | | | | |\/| | ")
print (re+"| `--' | | |_) | | |____ | |\ \----.| `----.| `--' | \ / | |____.----) | __| `----.| `--' | | | | | ")
print (re+" \______/ |______/ |_______|| _| `._____||_______| \______/ \__/ |_______|_______/ (__)\______| \______/ |__| |__| ")
print (cy+"version : 1.01")
print (cy+"Make sure you Subscribed Uber LoverS")
print (cy+"https://t.me/ubo520")
print (re+"NOTE :")
print ("1. Telegram only allow to add 200 members in group by one user.")
print ("2. You can Use multiple Telegram accounts for add more members.")
print ("3. Add only 50 members in group each time otherwise you will get flood error.")
print ("4. Then wait for 15-30 miniute then add members again.")
print ("5. Make sure you enable Add User Permission in your group")
cpass = configparser.RawConfigParser()
cpass.read('config.data')
try:
api_id = cpass['cred']['id']
api_hash = cpass['cred']['hash']
phone = cpass['cred']['phone']
client = TelegramClient(phone, api_id, api_hash)
except KeyError:
os.system('clear')
banner()
print(re+"[!] run python setup.py first !!\n")
sys.exit(1)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
os.system('clear')
banner()
client.sign_in(phone, input(gr+'[+] Enter the code: '+re))
users = []
with open(r"members.csv", encoding='UTF-8') as f: #Enter your file name
rows = csv.reader(f,delimiter=",",lineterminator="\n")
next(rows, None)
for row in rows:
user = {}
user['username'] = row[0]
user['id'] = int(row[1])
user['access_hash'] = int(row[2])
user['name'] = row[3]
users.append(user)
chats = []
last_date = None
chunk_size = 200
groups = []
result = client(GetDialogsRequest(
offset_date=last_date,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=chunk_size,
hash=0
))
chats.extend(result.chats)
for chat in chats:
try:
if chat.megagroup == True:
groups.append(chat)
except:
continue
print(gr+'Choose a group to add members:'+cy)
i = 0
for group in groups:
print(str(i) + '- ' + group.title)
i += 1
g_index = input(gr+"Enter a Number: "+re)
target_group = groups[int(g_index)]
target_group_entity = InputPeerChannel(target_group.id, target_group.access_hash)
mode = int(input(gr+"Enter 1 to add by username or 2 to add by ID: "+cy))
n = 0
with open(r"members2dead.csv", "a", encoding='UTF-8') as f:
writer = csv.writer(f, delimiter=",", lineterminator="\n")
for user in users:
n += 1
if n % 50 == 0:
print("Waiting for 180 - 600 Seconds...")
time.sleep(random.randrange(900, 1800))
try:
print("Adding {}".format(user['id']))
if mode == 1:
if user['username'] == "":
continue
user_to_add = client.get_input_entity(user['username'])
elif mode == 2:
user_to_add = InputPeerUser(user['id'], user['access_hash'])
else:
sys.exit("Invalid Mode Selected. Please Try Again.")
client(InviteToChannelRequest(target_group_entity, [user_to_add]))
print("Waiting for 180 - 600 Seconds...")
time.sleep(random.randrange(180, 600))
except PeerFloodError as e:
print("Waiting for 43200 seconds for PeerFloodError")
time.sleep(random.randrange(43100, 43200))
continue
except UserPrivacyRestrictedError:
print("User settings {} do not allow to be added.".format(user['username']))
writer.writerow([user['username']])
continue
except UserNotMutualContactError:
print("The user {} is not a mutual contact.".format(user['username']))
writer.writerow([user['username']])
continue
except UserKickedError:
writer.writerow([user['username']])
print("user already {} was kikado of the group.".format(user['username']))
continue
except FloodWaitError as e:
print('limit reached, use another line')
print('Have to sleep', e.seconds, 'seconds')
time.sleep(e.seconds)
break
except UnauthorizedError:
print("ACCOUNT WAS BANIDA!")
break
except UserChannelsTooMuchError:
writer.writerow([user['username']])
print('userbe many groups.')
continue
except ValueError:
writer.writerow([user['username']])
continue
except UserBannedInChannelError:
print('banned from sending messages')
except Exception as e:
traceback.print_exc()
print("Unexpected Error" + e.message)
continue