import asyncio
import random
import time
from threading import Thread
from telethon import TelegramClient, events, errors, functions, types
from telethon.tl.functions.messages import GetHistoryRequest
from telethon.tl.types import InputChannel, InputPeerChannel
import spintax
import colorama
# Load configuration
try:
from config import api_id, api_hash, sendMethod, mamontUsername,
deleteMessages, sleepConnectTime, minTime, maxTime, threadTime, spinMsg
except ImportError:
print("Error: config.py file not found or missing required variables.")
exit(1)
# Global counter for messages sent
allcounter = 0
# Initialize colorama for colored console output
colors = list(vars(colorama.Fore).values())
async def spamer(sesname, message):
global allcounter
color = random.choice(colors)
try:
# Initialize Telegram client
client = TelegramClient(f'./sessions/{sesname}', api_id, api_hash)
await client.start()
print(f'- Starting session: {sesname}')
if sleepConnectTime > 0:
print(f'Waiting {sleepConnectTime} seconds before starting...')
time.sleep(sleepConnectTime)
# Send messages based on the method
if sendMethod == 1:
await client.send_message(mamontUsername, message)
print(f'- Sent message to {mamontUsername}')
else:
dialogs = await client.get_dialogs()
contacts = await client(functions.contacts.GetContactsRequest(hash=0))
counter = 0
for dialog in dialogs:
try:
await client.send_message(dialog.entity, message)
if deleteMessages:
await client.delete_messages(dialog.entity, [message])
counter += 1
allcounter += 1
print(f'{color}- Session {sesname}: Sent message to dialog.
Total sent: {counter}')
time.sleep(random.randint(minTime, maxTime))
except Exception as e:
print(f'- Error sending message to dialog: {e}')
for contact in contacts.users:
try:
await client.send_message(contact, message)
if deleteMessages:
await client.delete_messages(contact, [message])
counter += 1
allcounter += 1
print(f'{color}- Session {sesname}: Sent message to contact.
Total sent: {counter}')
time.sleep(random.randint(minTime, maxTime))
except Exception as e:
print(f'- Error sending message to contact: {e}')
await client.disconnect()
except errors.UnauthorizedError:
print(f'- Session {sesname} is unauthorized.')
except errors.PeerFloodError:
print(f'- Session {sesname} hit a flood limit.')
except errors.FloodWaitError as e:
print(f'- Session {sesname} needs to wait {e.seconds} seconds due to flood
limit.')
except Exception as e:
print(f'- Error in session {sesname}: {e}')
def sessions():
print(f'Message deletion is {"enabled" if deleteMessages else "disabled"}!')
threads = []
message = spintax.spin(spinMsg)
# Start a new thread for each session
th = Thread(target=asyncio.run, args=(spamer("session_name", message),))
threads.append(th)
th.start()
time.sleep(threadTime)
for thread in threads:
thread.join()
print(f'Spam completed.\nTotal messages sent: {allcounter}')
if __name__ == "__main__":
print('Telegram Spammer 2.0')
print('Channel: @orehsoft')
print('Dev: @iihush @e1111r')
sessions()