-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink_remover_bot.py
More file actions
127 lines (110 loc) Β· 4.08 KB
/
link_remover_bot.py
File metadata and controls
127 lines (110 loc) Β· 4.08 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import asyncio
import re
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
# Fetch environment variables
API_ID = int(os.getenv("API_ID"))
API_HASH = os.getenv("API_HASH")
BOT_TOKEN = os.getenv("BOT_TOKEN")
# Initialize the bot
app = Client("link_remover_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
# Professional messages
START_MESSAGE = """
π **Welcome to LinkGuard Bot!**
I help keep your group clean and safe by:
- Removing **all links** and **@ mentions**.
- Sending polite warnings to violators.
- Preventing spam and scams.
**β€ Add me to your group and make me an admin to activate my features.**
"""
HELP_MESSAGE = """
π **How to use LinkGuard Bot:**
1. **Add me to your group.**
2. **Make me an admin** (with delete messages permission).
3. I will:
- Automatically remove all links and mentions.
- Send warnings to violators.
For further assistance, contact the developer.
"""
DEVELOPER_INFO_MESSAGE = """
π¨βπ» **Developer Info:**
**Name**: Hyperosis Love
**Username**: [@hyperosislove](https://t.me/hyperosislove)
**About**: A passionate developer focused on automation and security.
**Contact**: Reach out to me anytime via [Telegram](https://t.me/hyperosislove).
"""
WARNING_TEMPLATE = """
π« **Warning!**
Dear {username}, posting links or mentions is not allowed in this group.
Please follow the rules to avoid further actions. Thank you!
"""
# Function to check for links or mentions
def contains_prohibited_content(message_text):
return bool(re.search(r"http[s]?://|www\.|^@[\w\d]+", message_text))
# /start command handler
@app.on_message(filters.private & filters.command("start"))
async def start(client, message):
buttons = [
[
InlineKeyboardButton("β Add me to your group", url="https://t.me/your_bot_username?startgroup=true"),
InlineKeyboardButton("βΉοΈ How to Use", callback_data="help"),
],
[
InlineKeyboardButton("π Contact Developer", url="https://t.me/hyperosislove"),
],
]
try:
await message.reply_text(
"Welcome to LinkGuard Bot!\n\n"
"This bot helps you keep your group clean by removing links and mentions.\n"
"Click the buttons below to get started.",
reply_markup=InlineKeyboardMarkup(buttons),
parse_mode="Markdown",
)
except ValueError:
await message.reply_text(
"Welcome to LinkGuard Bot!\n\n"
"This bot helps you keep your group clean by removing links and mentions.\n"
"Click the buttons below to get started.",
reply_markup=InlineKeyboardMarkup(buttons),
)
# Callback query handler for help
@app.on_callback_query(filters.regex("help"))
async def help(client, callback_query):
try:
await callback_query.message.edit_text(
HELP_MESSAGE,
parse_mode="Markdown",
)
except ValueError:
await callback_query.message.edit_text(
HELP_MESSAGE,
)
# Callback query handler for developer info
@app.on_callback_query(filters.regex("developer_info"))
async def developer_info(client, callback_query):
try:
await callback_query.message.edit_text(
DEVELOPER_INFO_MESSAGE,
parse_mode="Markdown",
)
except ValueError:
await callback_query.message.edit_text(
DEVELOPER_INFO_MESSAGE,
)
# Group message handler
@app.on_message(filters.group & ~filters.service)
async def check_message(client, message):
if message.text and contains_prohibited_content(message.text):
await message.delete() # Delete prohibited message
user = message.from_user
warning_message = await message.reply_text(
WARNING_TEMPLATE.format(username=f"@{user.username}" if user.username else user.first_name),
parse_mode="Markdown",
)
await asyncio.sleep(10) # Wait 10 seconds
await warning_message.delete() # Delete warning message
# Run the bot
if __name__ == "__main__":
app.run()