Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create adder2 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions adder2
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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

re="\033[1;31m"
gr="\033[1;32m"
cy="\033[1;36m"

print (re+"╔╦╗┌─┐┬ ┌─┐╔═╗ ╔═╗┌┬┐┌┬┐┌─┐┬─┐")
print (gr+" ║ ├┤ │ ├┤ ║ ╦ ╠═╣ ││ ││├┤ ├┬┘")
print (re+" ╩ └─┘┴─┘└─┘╚═╝ ╩ ╩─┴┘─┴┘└─┘┴└─")

print (cy+"version : 1.01")
print (cy+"Make sure you Subscribed Termux Professor On Youtube")
print (cy+"www.youtube.com/c/TermuxProfessor")

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

for user in users:
n += 1
if n % 80 == 0:
sleep(60)
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 60-180 Seconds...")
time.sleep(random.randrange(15, 50))
except PeerFloodError:
print("Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
print("Waiting {} seconds".format(SLEEP_TIME_2))
time.sleep(SLEEP_TIME_2)
except UserPrivacyRestrictedError:
print("The user's privacy settings do not allow you to do this. Skipping.")
print("Waiting for 15 Seconds...")
time.sleep(random.randrange(15, 50))
except:
traceback.print_exc()
print("Unexpected Error")
continue