-
Notifications
You must be signed in to change notification settings - Fork 271
/
smsbot.py
107 lines (90 loc) · 3.51 KB
/
smsbot.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
#!/bin/env python3
# Modified by @AbirHasan2005
# Telegram Group: http://t.me/linux_repo
# Please give me credits if you use any codes from here.
from telethon.sync import TelegramClient
from telethon.tl.types import InputPeerUser
from telethon.errors.rpcerrorlist import PeerFloodError
import configparser
import os, sys
import csv
import random
import time
re="\033[1;31m"
gr="\033[1;32m"
cy="\033[1;36m"
yo="\033[1;33m"
SLEEP_TIME = 30
class main():
def banner():
print(f"""
{re}╔╦╗{cy}┌─┐┬ ┌─┐{re}╔═╗ ╔═╗{cy}┌─┐┬─┐┌─┐┌─┐┌─┐┬─┐
{re} ║ {cy}├┤ │ ├┤ {re}║ ╦ ╚═╗{cy}│ ├┬┘├─┤├─┘├┤ ├┬┘
{re} ╩ {cy}└─┘┴─┘└─┘{re}╚═╝ ╚═╝{cy}└─┘┴└─┴ ┴┴ └─┘┴└─
Version: 1.3
Modified by @AbirHasan2005
""")
def send_sms():
try:
cpass = configparser.RawConfigParser()
cpass.read('config.data')
api_id = cpass['cred']['id']
api_hash = cpass['cred']['hash']
phone = cpass['cred']['phone']
except KeyError:
os.system('clear')
main.banner()
print("\033[91m[!] Please run \033[92mpython3 setup.py\033[91m first !!!\033[0m\n")
sys.exit(1)
client = TelegramClient(phone, api_id, api_hash)
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
os.system('clear')
main.banner()
client.sign_in(phone, input(gr+'[+] Enter the sent code: '+re))
os.system('clear')
main.banner()
input_file = sys.argv[1]
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 = {
'username': row[0],
'id': int(row[1]),
'access_hash': int(row[2]),
'name': row[3],
}
users.append(user)
print(gr+"[1] Send SMS by user ID\n[2] Send SMS by username ")
mode = int(input(gr+"Input: "+re))
message = input(gr+"[+] Enter Your Message: "+yo)
for user in users:
if mode == 1:
receiver = InputPeerUser(user['id'],user['access_hash'])
elif mode == 2:
if user['username'] == "":
continue
receiver = client.get_input_entity(user['username'])
else:
print(re+"[!] Invalid Mode. Exiting ...")
client.disconnect()
sys.exit()
try:
print(gr+"[+] Sending Message to:", user['name'])
client.send_message(receiver, message.format(user['name']))
print(gr+"[+] Waiting {} seconds".format(SLEEP_TIME))
time.sleep(SLEEP_TIME)
except PeerFloodError:
print(re+"[!] Getting Flood Errors from Telegram. \n[!] Script is stopping for now. \n[!] Please try again after some time.")
client.disconnect()
sys.exit()
except Exception as e:
print(re+"[!] Error:", e)
print(re+"[!] Trying to continue ...")
continue
client.disconnect()
print("Done. Message sent to all users.")
main.send_sms()