Spaces:
Sleeping
Sleeping
Create code4.py
Browse files
code4.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from telethon.sync import TelegramClient, events
|
3 |
+
from telethon.tl.functions.messages import ImportChatInviteRequest
|
4 |
+
from telethon.tl.custom import Button
|
5 |
+
import random
|
6 |
+
|
7 |
+
api_id = "28810829"
|
8 |
+
api_hash = "d3f304bbd0b69b8c30dbec4be5824748"
|
9 |
+
bot_token = os.getenv("BOT_TOKEN")
|
10 |
+
|
11 |
+
client = TelegramClient('session_name', api_id, api_hash, bot_token=bot_token)
|
12 |
+
|
13 |
+
client.start()
|
14 |
+
|
15 |
+
links = ['https://t.me/+AiYPUMktDuM5NTQ1', 'https://t.me/+wkX4zJVyz44zZjFl']
|
16 |
+
|
17 |
+
@client.on(events.NewMessage)
|
18 |
+
async def handle_new_message(event):
|
19 |
+
if event.message.chat.id == -1001141878146:
|
20 |
+
return
|
21 |
+
sender_id = event.message.sender_id
|
22 |
+
|
23 |
+
await event.message.delete()
|
24 |
+
|
25 |
+
group_invite_link = random.choice(links)
|
26 |
+
await client.send_message(sender_id, f"Hey there! You sent a message, but I've deleted it. If you'd like to join our group, click the button below:")
|
27 |
+
await client.send_message(sender_id, f"{group_invite_link}", buttons=[[Button.url("Join Group", group_invite_link)]])
|
28 |
+
|
29 |
+
client.run_until_disconnected()
|