0% found this document useful (0 votes)
2 views2 pages

main.py

The document is a Python script for a Telegram spamming tool that sends messages to specified users or dialogs using the Telethon library. It includes configuration settings for message sending methods, deletion options, and timing controls, and handles various exceptions related to Telegram's API limits. The script utilizes threading to manage multiple sessions and tracks the total number of messages sent.

Uploaded by

mygiw.2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

main.py

The document is a Python script for a Telegram spamming tool that sends messages to specified users or dialogs using the Telethon library. It includes configuration settings for message sending methods, deletion options, and timing controls, and handles various exceptions related to Telegram's API limits. The script utilizes threading to manage multiple sessions and tracks the total number of messages sent.

Uploaded by

mygiw.2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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()

You might also like