-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
sendmessages.py
203 lines (185 loc) · 7.3 KB
/
sendmessages.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
#!/usr/bin/env python3
from telethon.sync import TelegramClient, connection
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty, InputPeerChannel, InputPeerUser
#from telethon.errors.rpcerrorlist import PeerFloodError, UserPrivacyRestrictedError
from telethon.errors.rpcerrorlist import (UserPrivacyRestrictedError,
UserNotMutualContactError,
FloodWaitError,
PeerFloodError,
UserChannelsTooMuchError,
UserDeactivatedBanError,
PhoneNumberBannedError,
UsernameInvalidError,
ChatWriteForbiddenError)
from telethon.tl.functions.channels import InviteToChannelRequest
import config
import configparser
import tqdm
import os, sys
import socks
import csv
import traceback
import datetime
import time
import random
import requests, socket
from sutils import *
from tgbot.services.api_sqlite_advert import *
print(type(datetime))
def get_time_str():
return datetime.now().strftime("%H:%M:%S")
cur_time = datetime.datetime.now()
re="\033[1;31m"
gr="\033[1;32m"
cy="\033[1;36m"
def banner():
print(f"""
´´´´¶¶¶¶¶¶´´´´´´¶¶¶¶¶¶
´´¶¶¶¶¶¶¶¶¶¶´´¶¶¶¶¶¶¶¶¶¶
´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´´´¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´´´¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶´´¶¶¶¶¶
¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶ ´¶¶¶¶¶´
´´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´´´¶¶¶¶¶¶¶¶¶¶¶¶¶
´´´´´´´´´¶¶¶¶¶¶¶¶
´´´´´´´´´´´¶¶¶¶
{re}
by rashidovich
""")
#check_phones()
cpass=get_all_avtgaccountsend()
#print(cpass)
for cp in cpass:
print(cp)
if cp[5] in ['wait2', 'banned', 'wait3']: continue
try:
account_id = cp[0]
api_id = cp[1]
api_hash = cp[2]
phone = cp[3]
waits24field = cp[9]
print(f"Работаем с аккаунтом:{phone} | ЕГО время старта: {waits24field}.")
if config.PROXY_ENABLED:
s = socks.socksocket()
rnd_proxy = random.choice(config.PROXY_IPS).split(":")
print(f"Подключение к Телеграмм с прокси {rnd_proxy}!")
client = TelegramClient(phone, api_id, api_hash, proxy=s.set_proxy(socks.HTTP, rnd_proxy[0], rnd_proxy[1]) )
else:
print("Подключение к Телеграмм без прокси!")
client = TelegramClient(phone, api_id, api_hash)
#client.start()
#print(f'[+] Успешная аутентификация - {phone}')
#client.disconnect()
client.connect()
if not client.is_user_authorized():
banner()
client.start()
print(f'[+] Успешная аутентификация - {phone}')
client.disconnect()
#client.connect()
except PhoneNumberBannedError:
print(f" | Ошибка: аккаунт {account_id} был удалён!")
update_tgaccounts(account_id, pole="banned")
continue
except FloodWaitError as e:
print(
f"{cur_time} | Ошибка: Таймаут на {e.seconds} секунд, это примерно {round(e.seconds / 60)} минут \n"
)
if config.CHECK_TIMEOUT:
for _ in range(e.seconds):
time.sleep(1)
else:
cur_sec = cur_time.second
sec = e.seconds + cur_sec
sec = sec % (24 * 3600)
hour = sec // 3600
sec %= 3600
min = sec // 60
sec %= 60
print(f"{str(cur_time.hour)}:{str(cur_time.minute)}")
utime = time.mktime(cur_time.timetuple())
print(f"{cur_time} | Аккаунт {account_id} уходит в режим ожидания на {hour} часов, {min} минут, {sec} секунд")
break
#os.system('clear')
banner()
state = "created"
#sended = 0
start = 0
count = 39
rows = firstgeo_tosend(state, start, count)
users = []
for row in rows:
user = {
'username': row[1],
'id': int(row[2]),
'access_hash': int(row[3]),
'name': row[4],
}
users.append(user)
print(gr+"[1] send sms by user ID\n[2] send sms by username ")
mode = int(input(f"{gr}Input : {re}"))
#message = input(gr+"[+] Enter Your Message : "+re)
message = "С наступающим Новым Годом друзья! Желаем счастья, радости, достатка и много-много интересного в Новом году! Команда @Goodsinbot"
n = 0
print(f"Выбрано ТГ аккаунтов для инвайта: {len(users)}")
cur_time = datetime.datetime.now()
print(f"{str(account_id)}|{str(cur_time)}")
h = get_tgaccounts_statecounts(account_id)
print(h)
sended = h[0]
sended_cs = 0
f = 0
not_sended= 0
#users = ['raclear', 'Oleg2023long', 'OlegDJI']
blockedu = ['Admin', 'Bot', 'bot']
for user in users:
n += 1
time.sleep(2)
try:
print(
n,
f"Пробуем отправить сообщение пользователю с аккаунтом ID {user['id']}",
)
if mode == 1:
receiver = InputPeerUser(user['id'],user['access_hash'])
elif mode == 2:
if user['username'] == "" or user['username'] in blockedu or user['access_hash'] < 0: # or user['username'].startswith('bot'):
continue
receiver = client.get_input_entity(user['username'])
else:
print(f"{re}[!] Invalid Mode. Exiting.")
client.disconnect()
sys.exit()
print(f"{gr}[+] Waiting 90 seconds.")
time.sleep(90)
print(f"{gr}[+] Sending Message to:", user['username'])
client.send_message(receiver, message.format(user['name']))
print(cp[0])
print(user)
update_tgparsex(cp[0], statesend='sended')
update_tgaccounts(cp[0], pole='sended24')
sended += 1
sended_cs += 1
print(
f"{gr}+ С:{sended}/СК:{sended_cs} | Отправили пользователю: {user['username']}"
)
#sended += 1
#sended_cs += 1
print(f"{gr}[+] Waiting 90 seconds.")
time.sleep(90)
continue
except PeerFloodError:
print(re+"[!] Getting Flood Error from telegram. \n[!] Script is stopping now. \n[!] Please try again after some time.")
client.disconnect()
update_tgaccounts(cp[0], pole='waifors24')
break
#sys.exit()
except Exception as e:
print(f"{re}[!] Error:", e)
print(f"{re}[!] Trying to continue...")
continue
client.disconnect()
print("Done. Message sent to all users.")