forked from tanim0la/telegramAdder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tele_adder.py
220 lines (202 loc) · 6.83 KB
/
tele_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
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
from telethon import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
from telethon.errors.rpcerrorlist import (PeerFloodError, UserNotMutualContactError ,
UserPrivacyRestrictedError, UserChannelsTooMuchError,
UserBotError, InputUserDeactivatedError)
from telethon.tl.functions.channels import InviteToChannelRequest
import time, os, sys, json
wt = (
'''
[[ye]]* ) (
[[re]]` ) /( ) ( ) )\ )
[[ye]]( )(_))( /( ( )\ ( ( ((_)( /(
[[re]](_(_()) )(_)) )\ )((_) )\ ' )\ _ )(_))
[[gr]]|_ _|((_)_ _(_/( (_) _((_)) ((_)| |((_)_
[[gr]]| | / _` || ' \))| || ' \()/ _ \| |/ _` |
|_| \__,_||_||_| |_||_|_|_| \___/|_|\__,_|
version : 1.0
github.com/Ayscoopy [[re]][DOnt forget to leave a star]
'''
)
COLORS = {
"re": "\u001b[31;1m",
"gr": "\u001b[32m",
"ye": "\u001b[33;1m",
}
re = "\u001b[31;1m"
gr = "\u001b[32m"
ye = "\u001b[33;1m"
def colorText(text):
for color in COLORS:
text = text.replace("[[" + color + "]]", COLORS[color])
return text
clearType = input('terminal or cmd. (t/c): ').lower()
if clearType == 't':
clear = lambda:os.system('clear')
elif clearType == 'c':
clear = lambda:os.system('cls')
else:
print('Invalid input!!!')
sys.exit()
if sys.version_info[0] < 3:
telet = lambda :os.system('pip install -U telethon')
elif sys.version_info[0] >= 3:
telet = lambda :os.system('pip3 install -U telethon')
telet()
time.sleep(1)
clear()
if os.path.isfile('getmem_log.txt'):
with open('getmem_log.txt', 'r') as r:
data = r.readlines()
api_id = data[0]
api_hash = data[1]
else:
api_id = input('Enter api_id: ')
api_hash = input('Enter api_hash: ')
with open('getmem_log.txt', 'w') as a:
a.write(api_id + '\n' + api_hash)
client = TelegramClient('anon', api_id, api_hash)
async def main():
# To Add Members.......
async def getmem():
clear()
print(colorText(wt))
print('')
print('')
print(ye+'[+] Choose your channel to Add members.')
a=0
for i in channel:
print(gr+'['+str(a)+']', i.title)
a += 1
opt1 = int(input(ye+'Enter a number: '))
my_participants = await client.get_participants(channel[opt1])
target_group_entity = InputPeerChannel(channel[opt1].id, channel[opt1].access_hash)
my_participants_id = []
for my_participant in my_participants:
my_participants_id.append(my_participant.id)
with open('members.txt', 'r') as r:
users = json.load(r)
count = 1
i = 0
for user in users:
if count%50 == 0:
clear()
print(colorText(wt))
print('')
print('')
print(ye+"please wait for 1 minute...")
time.sleep(60)
elif count >= 300:
await client.disconnect()
break
elif i >= 8:
await client.disconnect()
break
count+=1
time.sleep(1)
if user['uid'] in my_participants_id:
print(gr+'User present. Skipping.')
continue
else:
try:
user_to_add = InputPeerUser(user['uid'], user['access_hash'])
add = await client(InviteToChannelRequest(target_group_entity,[user_to_add]))
print(gr+'Added ', str(user['uid']))
except PeerFloodError:
print(re+"Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
i += 1
except UserPrivacyRestrictedError:
print(re+"The user's privacy settings do not allow you to do this. Skipping.")
i = 0
except UserBotError:
print(re+"Can't add Bot. Skipping.")
i = 0
except InputUserDeactivatedError:
print(re+"The specified user was deleted. Skipping.")
i = 0
except UserChannelsTooMuchError:
print(re+"User in too much channel. Skipping.")
except UserNotMutualContactError:
print(re+'Mutual No. Skipped.')
i = 0
except Exception as e:
print(re+"Error:", e)
print("Trying to continue...")
i += 1
continue
#end
print(colorText(wt))
chats = []
channel = []
result = await client(GetDialogsRequest(
offset_date=None,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=200,
hash=0
))
chats.extend(result.chats)
for a in chats:
try:
if True:
channel.append(a)
except:
continue
a = 0
print('')
print('')
print(ye+'Choose a group to scrape.')
for i in channel:
print(gr+'['+str(a)+']', i.title)
a += 1
op = input(ye+'Enter a number (or press ENTER to skip): ')
if op == '':
print(ye+'Ok. skipping...')
time.sleep(1)
await getmem()
sys.exit()
else:
pass
opt = int(op)
print('')
print(ye+'[+] Fetching Members...')
time.sleep(1)
target_group = channel[opt]
all_participants = []
mem_details = []
all_participants = await client.get_participants(target_group)
for user in all_participants:
try:
if user.username:
username = user.username
else:
username = ""
if user.first_name:
firstname = user.first_name
else:
firstname = ""
if user.last_name:
lastname = user.last_name
else:
lastname = ""
new_mem = {
'uid': user.id,
'username': username,
'firstname': firstname,
'lastname': lastname,
'access_hash': user.access_hash
}
mem_details.append(new_mem)
except ValueError:
continue
with open('members.txt', 'w') as w:
json.dump(mem_details, w)
time.sleep(1)
print(ye+'Please wait.....')
time.sleep(3)
done = input(gr+'[+] Members scraped successfully. (Press enter to Add members)')
await getmem()
await client.disconnect()
with client:
client.loop.run_until_complete(main())