Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 77 additions & 58 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,79 @@
# MIT License

# Copyright (c) 2022 Muhammed

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Telegram Link : https://telegram.dog/Mo_Tech_Group
# Repo Link : https://github.com/PR0FESS0R-99/Auto-Approved-Bot
# License Link : https://github.com/PR0FESS0R-99/Auto-Approved-Bot/blob/Auto-Approved-Bot/LICENSE

from os import environ
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, User, ChatJoinRequest

pr0fess0r_99=Client(
"Auto Approved Bot",
bot_token = environ["BOT_TOKEN"],
api_id = int(environ["API_ID"]),
api_hash = environ["API_HASH"]
import os
from telegram import Update
from telegram.ext import (
Application,
CommandHandler,
ChatJoinRequestHandler,
CallbackContext,
)

CHAT_ID = [int(pr0fess0r_99) for pr0fess0r_99 in environ.get("CHAT_ID", None).split()]
TEXT = environ.get("APPROVED_WELCOME_TEXT", "Hello {mention}\nWelcome To {title}\n\nYour Auto Approved")
APPROVED = environ.get("APPROVED_WELCOME", "on").lower()

@pr0fess0r_99.on_message(filters.private & filters.command(["start"]))
async def start(client: pr0fess0r_99, message: Message):
approvedbot = await client.get_me()
button = [[ InlineKeyboardButton("📦 Repo", url="https://github.com/PR0FESS0R-99/Auto-Approved-Bot"), InlineKeyboardButton("Updates 📢", url="t.me/Mo_Tech_YT") ],
[ InlineKeyboardButton("➕️ Add Me To Your Chat ➕️", url=f"http://t.me/{approvedbot.username}?startgroup=botstart") ]]
await client.send_message(chat_id=message.chat.id, text=f"**__Hello {message.from_user.mention} Iam Auto Approver Join Request Bot Just [Add Me To Your Group Channnl](http://t.me/{approvedbot.username}?startgroup=botstart) || Repo https://github.com/PR0FESS0R-99/Auto-Approved-Bot||**__", reply_markup=InlineKeyboardMarkup(button), disable_web_page_preview=True)

@pr0fess0r_99.on_chat_join_request((filters.group | filters.channel) & filters.chat(CHAT_ID) if CHAT_ID else (filters.group | filters.channel))
async def autoapprove(client: pr0fess0r_99, message: ChatJoinRequest):
chat=message.chat # Chat
user=message.from_user # User
print(f"{user.first_name} Joined 🤝") # Logs
await client.approve_chat_join_request(chat_id=chat.id, user_id=user.id)
if APPROVED == "on":
await client.send_message(chat_id=chat.id, text=TEXT.format(mention=user.mention, title=chat.title))
# print("Welcome....")

print("Auto Approved Bot")
pr0fess0r_99.run()
# Bot token aur admin ID environment variables se lenge
BOT_TOKEN = os.getenv("BOT_TOKEN", "7546733528:AAHdvZlHjJxWg-Pxz-SmfUy1nU5GBzrF1NU")
ADMIN_ID = int(os.getenv("ADMIN_ID", "7561026494"))

async def start(update: Update, context: CallbackContext) -> None:
"""Bot start command"""
await update.message.reply_text(
"Namaste! Main ek auto request accept bot hoon. Mujhe apke channel ya group mein admin banaye aur join requests apne aap accept honge!"
)

async def handle_join_request(update: Update, context: CallbackContext) -> None:
"""Naye join requests ko handle karta hai"""
join_request = update.chat_join_request
chat = join_request.chat
user = join_request.from_user

try:
# Request ko approve karo
await context.bot.approve_chat_join_request(
chat_id=chat.id,
user_id=user.id
)

# Welcome message bhejo (optional)
welcome_msg = f"Namaste {user.first_name}! {chat.title} mein swagat hai!"
await context.bot.send_message(
chat_id=user.id,
text=welcome_msg
)

# Admin ko notification bhejo
await context.bot.send_message(
chat_id=ADMIN_ID,
text=f"New member: {user.first_name} (ID: {user.id}) joined {chat.title}"
)

except Exception as e:
# Error logging
await context.bot.send_message(
chat_id=ADMIN_ID,
text=f"Error approving join request: {str(e)}"
)

async def stats(update: Update, context: CallbackContext) -> None:
"""Admin ke liye stats command"""
if update.message.from_user.id != ADMIN_ID:
await update.message.reply_text("Ye command sirf admin ke liye hai!")
return

# Basic stats (is example mein static hai, aap database ya counter add kar sakte hain)
await update.message.reply_text(
"Bot Stats:\n- Active Channels: 1\n- Total Approved Requests: N/A\nStats abhi basic hain, aur features jaldi add honge!"
)

def main() -> None:
"""Bot ko run karne ka main function"""
# Application initialize karo
application = Application.builder().token(BOT_TOKEN).build()

# Handlers add karo
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("stats", stats))
application.add_handler(ChatJoinRequestHandler(handle_join_request))

# Bot start karo
print("Bot shuru ho raha hai...")
application.run_polling(allowed_updates=Update.ALL_TYPES)

if __name__ == "__main__":
main()