Telegram Code Script»,Telegram Bot Code
The script of the Telegram bot of the TRX exchanger
15-11-2023, 05:47
A simple spammer on Telegram chats
Written in Python
from pyrogram import Client
from pyrogram.errors import FloodWait, BadRequest, Flood, InternalServerError
from time import sleep
from sys import stderr, exit
from loguru import logger
from msvcrt import getch
from os import system
import time
import re
def clear(): return system('cls')
api = open('apis.txt').read().split(' ')
SESSION = input('Enter the phone number: ')
logger.remove()
logger.add(stderr,
format='<white>{time:HH:mm:ss}</white> | '
'<level>{level: <8}</level> | '
'<cyan>{line}</cyan> - '
'<white>{message}</white>')
app = Client(SESSION, int(api[0]), api[1])
with open('Чаты.txt ', 'r', encoding='utf-8') as file:
chat_list = [row.strip() for row in file]
message_text = open('Сообщение.txt ', 'r', encoding='utf-8').read()
def https_delete(listname):
for https in range(len(listname)):
listname[https] = re.sub('https://t.me/', '', listname[https])
def send_message(current_chat):
for _ in range(3):
try:
with app:
app.send_message(current_chat, message_text)
except FloodWait as error:
logger.info(f'{current_chat} | FloodWait: {error.x}')
sleep(error.x)
except Flood:
pass
except BadRequest as error:
logger.error(f'{current_chat} | {error}')
except InternalServerError as error:
logger.error(f'{current_chat} | {error}')
except Exception as error:
logger.error(f'{current_chat} | {error}')
else:
logger.success(f'{current_chat} | The message was successfully sent')
return
with open('errors_send_message.txt', 'a', encoding='utf-8') as file:
file.write(f'{current_chat}\n')
def join_chat(current_chat):
for _ in range(3):
try:
with app:
app.join_chat(current_chat)
except FloodWait as error:
logger.info(f'{current_chat} | FloodWait: {error.x}')
sleep(error.x)
except Flood:
pass
except BadRequest as error:
logger.error(f'{current_chat} | {error}')
except InternalServerError as error:
logger.error(f'{current_chat} | {error}')
except Exception as error:
logger.error(f'{current_chat} | {error}')
else:
logger.success(f'{current_chat} | Successfully logged into the chat')
return
with open('errors_join_chat.txt', 'a', encoding='utf-8') as file:
file.write(f'{current_chat}\n')
if __name__ == '__main__':
https_delete(chat_list)
print('Joining chats...')
for current_chat in chat_list:
join_chat(current_chat)
number_of_sends = int(input('How many times do you want to send a message to chats?: '))
sleep_time = int(input('Enter the delay between messages in seconds: '))
for current_chat in chat_list:
for sending_messages in range(number_of_sends):
send_message(current_chat)
time.sleep(sleep_time)
print('Work completed successfully!')
print('\n To exit, press any key.')
getch()
exit()
Installation:
1. Open the console and go to the folder with the script, write pip install -r requirements.txt
2. We are waiting for the installation of all necessary libraries
Instruction manual:
1. Write your message to a file Сообщение.txt
2. Insert links to the chats where you want to send this message
3. Enter the number of times to send, and the delay
Update: Fixed working code:
1. Create a send.py is in the archive and we throw the code below there:
from pyrogram import Client
from pyrogram.errors import FloodWait, BadRequest, Flood, InternalServerError
from time import sleep
from sys import stderr, exit
from loguru import logger
from dotenv import dotenv_values
from msvcrt import getch
from os import system
import time
def clear(): return system('cls')
config = dotenv_values()
SESSION_NAME = config['session_name']
API_ID = int(config['api_id'])
API_HASH = config['api_hash']
x = 1
logger.remove()
logger.add(stderr,
format='<white>{time:HH:mm:ss}</white> | '
'<level>{level: <8}</level> | '
'<cyan>{line}</cyan> - '
'<white>{message}</white>')
app = Client(SESSION_NAME, API_ID, API_HASH)
with open('otc.txt', 'r', encoding='utf-8') as file:
otc_list = [row.strip() for row in file]
msg_text = open('msg_text.txt', 'r', encoding='utf-8').read()
successful_messages = {}
def send_message_otc(current_otc):
global successful_messages
for _ in range(3):
try:
app.send_message(current_otc, msg_text)
except FloodWait as error:
sleep(1)
except Flood:
pass
except BadRequest as error:
logger.error(f'{current_otc} | {error}')
except InternalServerError as error:
logger.error(f'{current_otc} | {error}')
except Exception as error:
logger.error(f'{current_otc} | {error}')
else:
if current_otc in successful_messages:
successful_messages[current_otc] += 1
else:
successful_messages[current_otc] = 1
logger.success(f'{current_otc} | The message was successfully sent')
return
with open('errors_send_message.txt', 'a', encoding='utf-8') as file:
file.write(f'{current_otc}\n')
def join_chat_otc(current_otc):
for _ in range(3):
try:
app.join_chat(current_otc)
except FloodWait as error:
sleep(1)
except Flood:
pass
except BadRequest as error:
logger.error(f'{current_otc} | {error}')
except InternalServerError as error:
logger.error(f'{current_otc} | {error}')
except Exception as error:
logger.error(f'{current_otc} | {error}')
else:
logger.success(f'{current_otc} | Successfully logged into the chat')
return
with open('errors_join_chat.txt', 'a', encoding='utf-8') as file:
file.write(f'{current_otc}\n')
def write_successful_messages():
with open('successful_messages.txt', 'w', encoding='utf-8') as file:
for chat, count in successful_messages.items():
file.write(f'{chat}: {count}\n')
if __name__ == '__main__':
user_action = int(input('Enter your action '
'(1 - join chats from .txt; '
'2 - send message in chats from .txt): '))
interval = int(input('Enter the interval between repeated executions (in seconds): '))
clear()
while True:
with app:
for current_otc in otc_list:
if user_action == 1:
join_chat_otc(current_otc)
elif user_action == 2:
send_message_otc(current_otc)
logger.success('The work has been completed successfully!')
logger.success(f' Number of successfully sent messages: {sum(successful_messages.values())}')
write_successful_messages()
print(f'\nWaiting for {interval} seconds before the next execution...')
time.sleep(interval)
clear()
15-11-2023, 05:47
31-07-2024, 02:18
30-07-2024, 04:30
There are no comments
Information
Users of Visitor are not allowed to comment this publication.