diff --git a/StringSessionBot/gcast.py b/StringSessionBot/gcast.py index c4c9647..1399256 100644 --- a/StringSessionBot/gcast.py +++ b/StringSessionBot/gcast.py @@ -1,4 +1,4 @@ -# This code is written by TheTaemAlexa +# This code is written by TheTeamAlexa import pickledb from Data import Data @@ -6,43 +6,20 @@ from pyrogram.types import InlineKeyboardMarkup, Message # Initialize the database -db = pickledb.load("user_db.db", False) - +db = pickledb.load('user_db.db', False) # Filters to use command def filter(cmd: str): return filters.private & filters.incoming & filters.command(cmd) - # Owner id owner_id = 6174058850 - -async def handle_broadcast(client, message): - if message.text: - users = db.getall() - delivered_count = 0 - - for user_id in users: - try: - user_id = int(user_id) - await client.send_message( - user_id, "Broadcast message By @TheTeamAlexa: " + message.text - ) - delivered_count += 1 - except ValueError: - pass - - await client.send_message( - message.chat.id, f"Broadcast sent successfully to {delivered_count} users!" - ) - - # Start Message @Client.on_message(filter("start")) -async def start(bot: Client, msg: Message): # Corrected 'message' to 'msg' +async def start(bot: Client, msg: Message): user = await bot.get_me() - user_id = msg.from_user.id # Corrected 'message' to 'msg' + user_id = msg.from_user.id if not db.get(str(user_id)): db.set(str(user_id), True) mention = user.mention @@ -52,12 +29,21 @@ async def start(bot: Client, msg: Message): # Corrected 'message' to 'msg' reply_markup=InlineKeyboardMarkup(Data.buttons), ) - -@Client.on_message(filters.command("gcast") & filters.private) +@Client.on_message(filter("gcast") & filters.private) async def gcast_command(client, message): if message.from_user.id == owner_id: await message.reply_text("Enter the message you want to broadcast:") - # Wait for the user's response - await client.add_handler(handle_broadcast, message.chat.id) + elif message.text: + users = db.getall() + delivered_count = 0 + for user_id in users: + try: + user_id = int(user_id) + await client.send_message(user_id, f"Broadcast message By @TheTeamAlexa: {message.text}") + delivered_count += 1 + except ValueError: + pass + + await client.send_message(message.chat.id, f"Broadcast sent successfully to {delivered_count} users!") else: await message.reply_text("You are not authorized to use this command.")