diff --git a/shizuchat/modules/start.py b/shizuchat/modules/start.py new file mode 100644 index 0000000..8d253ad --- /dev/null +++ b/shizuchat/modules/start.py @@ -0,0 +1,482 @@ +import asyncio +import logging +import random +from shizuchat import shizuchat +from datetime import datetime +from pymongo import MongoClient +from pyrogram.enums import ChatType +from pyrogram import Client, filters +from config import OWNER_ID, MONGO_URL, OWNER_USERNAME +from pyrogram.errors import FloodWait, ChatAdminRequired +from shizuchat.database.chats import get_served_chats, add_served_chat +from shizuchat.database.users import get_served_users, add_served_user +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, CallbackQuery +from shizuchat.modules.helpers import ( + START, + START_BOT, + PNG_BTN, + CLOSE_BTN, + HELP_BTN, + HELP_BUTN, + HELP_READ, + HELP_START, + SOURCE_READ, +) + +STICKER = [ + "CAACAgUAAx0CepnpNQABAQ0ZZwi4keVWGDS7Zc4Ugl07nazStioAAoYKAAIFp0FW4tWKLEhqx54eBA", + "CAACAgUAAx0CepnpNQABAQ0bZwi4ty5H4bQFRiADbIDRjvmqrvwAAs8KAAISAAFwVwABdUaWHySE3B4E", + "CAACAgUAAx0CepnpNQABAQ0aZwi4tLgnRHxBeCGoKYkHaOtihKgAAj4MAAIfJXFXhnQ9Zw3NF_AeBA", + + "CAACAgUAAx0CepnpNQABAQ0cZwi4vvVDhrmnrLZJjKZXwZHm6J8AAogMAAKn83BXvz4RP6rTTEYeBA", +] + + +EMOJIOS = [ + "💣", + "💥", + "🪄", + "🧨", + "⚡", + "🤡", + "👻", + "🎃", + "🎩", + "🕊", +] + +BOT = "https://envs.sh/nAW.jpg" +IMG = [ + "https://envs.sh/nAS.jpg", + "https://envs.sh/nAB.jpg", + "https://envs.sh/nAI.jpg", +] + + + +chatdb = MongoClient(MONGO_URL) +status_db = chatdb["ChatBotStatusDb"]["StatusCollection"] + +async def set_default_status(chat_id): + try: + if not await status_db.find_one({"chat_id": chat_id}): + await status_db.insert_one({"chat_id": chat_id, "status": "enabled"}) + except Exception as e: + print(f"Error setting default status for chat {chat_id}: {e}") + +@shizuchat.on_message(filters.new_chat_members) +async def welcomejej(client, message: Message): + await add_served_chat(message.chat.id) + await set_default_status(message.chat.id) + users = len(await get_served_users()) + chats = len(await get_served_chats()) + try: + for member in message.new_chat_members: + + if member.id == shizuchat.id: + reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(f"sᴇʟᴇᴄᴛ ʟᴀɴɢᴜᴀɢᴇ", callback_data="choose_lang")]]) + await message.reply_photo(photo=random.choice(IMG), caption=START.format(shizuchat.mention or "can't mention", users, chats), reply_markup=reply_markup) + chat = message.chat + try: + invitelink = await shizuchat.export_chat_invite_link(message.chat.id) + link = f"[ɢᴇᴛ ʟɪɴᴋ]({invitelink})" + except ChatAdminRequired: + link = "No Link" + + try: + groups_photo = await shizuchat.download_media( + chat.photo.big_file_id, file_name=f"chatpp{chat.id}.png" + ) + chat_photo = ( + groups_photo if groups_photo else "https://envs.sh/nAW.jpg" + ) + except AttributeError: + chat_photo = "https://envs.sh/nAW.jpg" + + count = await shizuchat.get_chat_members_count(chat.id) + chats = len(await get_served_chats()) + username = chat.username if chat.username else "𝐏ʀɪᴠᴀᴛᴇ 𝐆ʀᴏᴜᴘ" + msg = ( + f"**🎉ᴄʜᴀᴛ ʙᴏᴛ ᴀᴅᴅᴇᴅ ɪɴ ᴀ #ɴᴇᴡ_ɢʀᴏᴜᴘ❤️**\n\n" + f"**💫ᴄʜᴀᴛ ɴᴀᴍᴇ:** {chat.title}\n" + f"**💕ᴄʜᴀᴛ ɪᴅ:** `{chat.id}`\n" + f"**🔐ᴄʜᴀᴛ ᴜsᴇʀɴᴀᴍᴇ:** @{username}\n" + f"**🖇️ɢʀᴏᴜᴘ ʟɪɴᴋ:** {link}\n" + f"**♥️ɢʀᴏᴜᴘ ᴍᴇᴍʙᴇʀs:** {count}\n" + f"**💞ᴀᴅᴅᴇᴅ ʙʏ:** {message.from_user.mention}\n\n" + f"**ᴛᴏᴛᴀʟ ᴄʜᴀᴛs :** {chats}" + ) + + try: + owner_username = True + + if owner_username: + await shizuchat.send_photo( + int(OWNER_ID), + photo=chat_photo, + caption=msg, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + f"{message.from_user.first_name}", + user_id=message.from_user.id)]])) + else: + await shizuchat.send_photo( + int(OWNER_ID), + photo=chat_photo, + caption=msg, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + f"{message.from_user.first_name}", + user_id=message.from_user.id)]])) + except Exception as e: + logging.info(f"Error fetching owner username: {e}") + await shizuchat.send_photo( + int(OWNER_ID), + photo=chat_photo, + caption=msg, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + f"{message.from_user.first_name}", + user_id=message.from_user.id)]])) + + except Exception as e: + logging.info(f"Error: {e}") + + +@shizuchat.on_cmd(["start", "aistart"]) +async def start(_, m: Message): + users = len(await get_served_users()) + chats = len(await get_served_chats()) + if m.chat.type == ChatType.PRIVATE: + accha = await m.reply_text( + text=random.choice(EMOJIOS), + ) + await asyncio.sleep(0.5) + + await accha.edit("**__ᴅ__**") + await accha.edit("**__ᴅι__**") + await accha.edit("**__ᴅιи__**") + await accha.edit("**__ᴅιиg__**") + await accha.edit("**__ᴅιиg ᴅ__**") + await accha.edit("**__ᴅιиg ᴅσ__**") + await accha.edit("**__ᴅιиg ᴅσи__**") + await accha.edit("**__ᴅιиg ᴅσиg__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ ѕ__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ sт__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ ѕтα__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ ѕтαя__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ sтαят__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ sтαятι__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ sтαятιи__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ sтαятιиg__**") + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ ѕтαятιиg.__**") + await asyncio.sleep(0.1) + await accha.edit("**__ᴅιиg ᴅσиg ꨄ sтαятιиg.....__**") + await asyncio.sleep(0.1) + await accha.edit("**__ᴅιиg ᴅσиg ꨄ︎ ѕтαятιиg.__**") + await asyncio.sleep(0.1) + await accha.edit("**__ᴅιиg ᴅσиg ꨄ sтαятιиg.....__**") + await accha.delete() + + umm = await m.reply_sticker(sticker=random.choice(STICKER)) + chat_photo = BOT + if m.chat.photo: + try: + userss_photo = await shizuchat.download_media(m.chat.photo.big_file_id) + await umm.delete() + if userss_photo: + chat_photo = userss_photo + except AttributeError: + chat_photo = BOT + + users = len(await get_served_users()) + chats = len(await get_served_chats()) + await m.reply_photo(photo=chat_photo, caption=START.format(shizuchat.mention or "can't mention", users, chats), reply_markup=InlineKeyboardMarkup(START_BOT)) + await add_served_user(m.chat.id) + keyboard = InlineKeyboardMarkup([[InlineKeyboardButton(f"{m.chat.first_name}", user_id=m.chat.id)]]) + await shizuchat.send_photo(int(OWNER_ID), photo=chat_photo, caption=f"{m.from_user.mention} ʜᴀs sᴛᴀʀᴛᴇᴅ ʙᴏᴛ. \n\n**ɴᴀᴍᴇ :** {m.chat.first_name}\n**ᴜsᴇʀɴᴀᴍᴇ :** @{m.chat.username}\n**ɪᴅ :** {m.chat.id}\n\n**ᴛᴏᴛᴀʟ ᴜsᴇʀs :** {users}", reply_markup=keyboard) + + else: + await m.reply_photo( + photo=random.choice(IMG), + caption=START.format(shizuchat.mention or "can't mention", users, chats), + reply_markup=InlineKeyboardMarkup(HELP_START), + ) + await add_served_chat(m.chat.id) + + +@shizuchat.on_cmd("help") +async def help(client: shizuchat, m: Message): + if m.chat.type == ChatType.PRIVATE: + hmm = await m.reply_photo( + photo=random.choice(IMG), + caption=HELP_READ, + reply_markup=InlineKeyboardMarkup(HELP_BTN), + ) + + else: + await m.reply_photo( + photo=random.choice(IMG), + caption="**ʜᴇʏ, ᴘᴍ ᴍᴇ ғᴏʀ ʜᴇʟᴘ ᴄᴏᴍᴍᴀɴᴅs!**", + reply_markup=InlineKeyboardMarkup(HELP_BUTN), + ) + await add_served_chat(m.chat.id) + + +@shizuchat.on_cmd("repo") +async def repo(_, m: Message): + await m.reply_text( + text=SOURCE_READ, + reply_markup=InlineKeyboardMarkup(CLOSE_BTN), + disable_web_page_preview=True, + ) + + + + +@shizuchat.on_cmd("ping") +async def ping(_, message: Message): + start = datetime.now() + loda = await message.reply_photo( + photo=random.choice(IMG), + caption="ᴘɪɴɢɪɴɢ...", + ) + + ms = (datetime.now() - start).microseconds / 1000 + await loda.edit_text( + text=f"ʜᴇᴛ ʙᴀʙʏ!!\n{shizuchat.name} ᴄʜᴀᴛʙᴏᴛ ιѕ ᴀʟɪᴠᴇ 🥀 ᴀɴᴅ ᴡᴀʀᴋɪɴɢ ғɪɴᴇ ᴡɪᴛʜ ᴀ ᴘɪɴɢ ᴏғ\n➥ `{ms}` ms\n\n|| ᴍᴀᴅᴇ ᴡɪᴛʜ ❣️ ʙʏ [ʙᴀᴅ ᴍᴜɴᴅᴀ](https://t.me/{OWNER_USERNAME}) ||", + reply_markup=InlineKeyboardMarkup(PNG_BTN), + ) + if message.chat.type == ChatType.PRIVATE: + await add_served_user(message.from_user.id) + else: + await add_served_chat(message.chat.id) + + +@shizuchat.on_message(filters.command("stats")) +async def stats(cli: Client, message: Message): + users = len(await get_served_users()) + chats = len(await get_served_chats()) + await message.reply_text( + f"""{(await cli.get_me()).mention} ᴄʜᴀᴛʙᴏᴛ sᴛᴀᴛs: + +➻ **ᴄʜᴀᴛs :** {chats} +➻ **ᴜsᴇʀs :** {users}""" + ) + + +from pyrogram.enums import ParseMode + +from shizuchat import shizuchat + + +@shizuchat.on_cmd("id") +async def getid(client, message): + chat = message.chat + your_id = message.from_user.id + message_id = message.id + reply = message.reply_to_message + + text = f"**[ᴍᴇssᴀɢᴇ ɪᴅ:]({message.link})** `{message_id}`\n" + text += f"**[ʏᴏᴜʀ ɪᴅ:](tg://user?id={your_id})** `{your_id}`\n" + + if not message.command: + message.command = message.text.split() + + if not message.command: + message.command = message.text.split() + + if len(message.command) == 2: + try: + split = message.text.split(None, 1)[1].strip() + user_id = (await client.get_users(split)).id + text += f"**[ᴜsᴇʀ ɪᴅ:](tg://user?id={user_id})** `{user_id}`\n" + + except Exception: + return await message.reply_text("ᴛʜɪs ᴜsᴇʀ ᴅᴏᴇsɴ'ᴛ ᴇxɪsᴛ.", quote=True) + + text += f"**[ᴄʜᴀᴛ ɪᴅ:](https://t.me/{chat.username})** `{chat.id}`\n\n" + + if ( + not getattr(reply, "empty", True) + and not message.forward_from_chat + and not reply.sender_chat + ): + text += f"**[ʀᴇᴘʟɪᴇᴅ ᴍᴇssᴀɢᴇ ɪᴅ:]({reply.link})** `{reply.id}`\n" + text += f"**[ʀᴇᴘʟɪᴇᴅ ᴜsᴇʀ ɪᴅ:](tg://user?id={reply.from_user.id})** `{reply.from_user.id}`\n\n" + + if reply and reply.forward_from_chat: + text += f"ᴛʜᴇ ғᴏʀᴡᴀʀᴅᴇᴅ ᴄʜᴀɴɴᴇʟ, {reply.forward_from_chat.title}, ʜᴀs ᴀɴ ɪᴅ ᴏғ `{reply.forward_from_chat.id}`\n\n" + print(reply.forward_from_chat) + + if reply and reply.sender_chat: + text += f"ɪᴅ ᴏғ ᴛʜᴇ ʀᴇᴘʟɪᴇᴅ ᴄʜᴀᴛ/ᴄʜᴀɴɴᴇʟ, ɪs `{reply.sender_chat.id}`" + print(reply.sender_chat) + + await message.reply_text( + text, + disable_web_page_preview=True, + parse_mode=ParseMode.DEFAULT, + ) + + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +AUTO_SLEEP = 5 +IS_BROADCASTING = False +broadcast_lock = asyncio.Lock() + + +@shizuchat.on_message( + filters.command(["broadcast", "gcast"]) & filters.user(int(OWNER_ID)) +) +async def broadcast_message(client, message): + global IS_BROADCASTING + async with broadcast_lock: + if IS_BROADCASTING: + return await message.reply_text( + "A broadcast is already in progress. Please wait for it to complete." + ) + + IS_BROADCASTING = True + try: + query = message.text.split(None, 1)[1].strip() + except IndexError: + query = message.text.strip() + except Exception as eff: + return await message.reply_text( + f"**Error**: {eff}" + ) + try: + if message.reply_to_message: + broadcast_content = message.reply_to_message + broadcast_type = "reply" + flags = { + "-pin": "-pin" in query, + "-pinloud": "-pinloud" in query, + "-nogroup": "-nogroup" in query, + "-user": "-user" in query, + } + else: + if len(message.command) < 2: + return await message.reply_text( + "**Please provide text after the command or reply to a message for broadcasting.**" + ) + + flags = { + "-pin": "-pin" in query, + "-pinloud": "-pinloud" in query, + "-nogroup": "-nogroup" in query, + "-user": "-user" in query, + } + + for flag in flags: + query = query.replace(flag, "").strip() + + if not query: + return await message.reply_text( + "Please provide a valid text message or a flag: -pin, -nogroup, -pinloud, -user" + ) + + + broadcast_content = query + broadcast_type = "text" + + + await message.reply_text("**Started broadcasting...**") + + if not flags.get("-nogroup", False): + sent = 0 + pin_count = 0 + chats = await get_served_chats() + + for chat in chats: + chat_id = int(chat["chat_id"]) + if chat_id == message.chat.id: + continue + try: + if broadcast_type == "reply": + m = await shizuchat.forward_messages( + chat_id, message.chat.id, [broadcast_content.id] + ) + else: + m = await shizuchat.send_message( + chat_id, text=broadcast_content + ) + sent += 1 + + if flags.get("-pin", False) or flags.get("-pinloud", False): + try: + await m.pin( + disable_notification=flags.get("-pin", False) + ) + pin_count += 1 + except Exception as e: + logger.error( + f"Failed to pin message in chat {chat_id}: {e}" + ) + + except FloodWait as e: + flood_time = int(e.value) + logger.warning( + f"FloodWait of {flood_time} seconds encountered for chat {chat_id}." + ) + if flood_time > 200: + logger.info( + f"Skipping chat {chat_id} due to excessive FloodWait." + ) + continue + await asyncio.sleep(flood_time) + except Exception as e: + logger.error(f"Error broadcasting to chat {chat_id}: {e}") + continue + + await message.reply_text( + f"**Broadcasted to {sent} chats and pinned in {pin_count} chats.**" + ) + + if flags.get("-user", False): + susr = 0 + users = await get_served_users() + + for user in users: + user_id = int(user["user_id"]) + try: + if broadcast_type == "reply": + m = await shizuchat.forward_messages( + user_id, message.chat.id, [broadcast_content.id] + ) + else: + m = await shizuchat.send_message( + user_id, text=broadcast_content + ) + susr += 1 + + except FloodWait as e: + flood_time = int(e.value) + logger.warning( + f"FloodWait of {flood_time} seconds encountered for user {user_id}." + ) + if flood_time > 200: + logger.info( + f"Skipping user {user_id} due to excessive FloodWait." + ) + continue + await asyncio.sleep(flood_time) + except Exception as e: + logger.error(f"Error broadcasting to user {user_id}: {e}") + continue + + await message.reply_text(f"**Broadcasted to {susr} users.**") + + finally: + IS_BROADCASTING = False +