-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
91 lines (78 loc) · 3.45 KB
/
Copy pathbot.py
File metadata and controls
91 lines (78 loc) · 3.45 KB
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
import os
from pyrogram import Client
from pyrogram.errors import FloodWait
import time
# Create 'sessions' directory if it doesn't exist
if not os.path.exists("sessions"):
os.makedirs("sessions")
# Function to create a Pyrogram client, storing session files in the 'sessions' folder
def create_client(name):
return Client(
name=name, # Corrected the argument from 'session_name' to 'name'
api_id="Api id",
api_hash="Api Hash",
workdir="sessions" # Store session files in 'sessions' folder
)
# Function to create a session
async def create_session(name):
async with create_client(name) as app:
print(f"Session '{name}' created successfully.")
# Function to join a Telegram channel using all existing sessions
async def join_channel(channel_link):
sessions = os.listdir("sessions") # List all session files
if not sessions:
print("No sessions found. Please create a session first.")
return
for session_file in sessions:
session_name = os.path.splitext(session_file)[0] # Strip the file extension
try:
async with create_client(session_name) as app:
await app.join_chat(channel_link)
print(f"Successfully joined channel {channel_link} using session '{session_name}'.")
except Exception as e:
print(f"Failed to join channel with session '{session_name}': {e}")
# Function to react to a Telegram post using all existing sessions
async def react_to_post(chat_id, message_id, emoji):
sessions = os.listdir("sessions") # List all session files
if not sessions:
print("No sessions found. Please create a session first.")
return
for session_file in sessions:
session_name = os.path.splitext(session_file)[0] # Strip the file extension
try:
async with create_client(session_name) as app:
await app.send_reaction(chat_id=chat_id, message_id=message_id, emoji=emoji)
print(f"Successfully reacted with {emoji} using session '{session_name}'.")
except FloodWait as e:
print(f"Rate limited for session '{session_name}'. Waiting for {e.x} seconds.")
time.sleep(e.x)
except Exception as e:
print(f"Failed to react with session '{session_name}': {e}")
# Menu function
def show_menu():
print("Welcome to Telegram Session Bot!")
print("1. Create session")
print("2. Join channel with all sessions")
print("3. React to post with all sessions")
return input("Enter your choice (1/2/3): ")
# Main program
if __name__ == "__main__":
choice = show_menu()
if choice == '1':
session_name = input("Enter a unique session name: ")
create_client(session_name).run(create_session(session_name))
elif choice == '2':
channel_link = input("Enter the channel link: ")
create_client("").run(join_channel(channel_link))
elif choice == '3':
post_link = input("Enter the post link: ")
try:
# Split post link to get chat_id and message_id
chat_id, message_id = post_link.replace('https://t.me/', '').split('/')
message_id = int(message_id) # Convert message_id to integer
emoji = "🔥" # Fire emoji for reacting
create_client("").run(react_to_post(chat_id, message_id, emoji))
except ValueError:
print("Invalid post link format.")
else:
print("Invalid choice. Exiting...")