async def broadcast(event): if event.sender_id != OWNER_ID: await event.answer("You can't use this bot") return await tgbot.send_message( event.chat_id, "Send the message you want to broadcast!\nSend /cancel to stop.") async with event.client.conversation(OWNER_ID) as conv: response = conv.wait_event(events.NewMessage(chats=OWNER_ID)) response = await response themssg = response.message.message if themssg is None: await tgbot.send_message(event.chat_id, "An error has occured...") if themssg == "/cancel": await tgbot.send_message(event.chat_id, "Broadcast cancelled!") return targets = full_userbase() users_cnt = len(full_userbase()) err = 0 success = 0 lmao = await tgbot.send_message( event.chat_id, "Starting broadcast to {} users.".format(users_cnt)) start = datetime.now() for ok in targets: try: await tgbot.send_message(int(ok.chat_id), themssg) success += 1 await asyncio.sleep(0.1) except Exception as e: err += 1 try: await tgbot.send_message( Var.PRIVATE_GROUP_ID, f"**Error**\n{str(e)}\nFailed for user: {chat_id}") except BaseException: pass end = datetime.now() ms = (end - start).seconds done_mssg = """ Broadcast completed!\n Sent to `{}` users in `{}` seconds.\n Failed for `{}` users.\n Total users in bot: `{}`.\n """.format(success, ms, err, users_cnt) await lmao.edit(done_mssg) try: await tgbot.send_message( Var.PRIVATE_GROUP_ID, f"#Broadcast\nCompleted sending a broadcast to {success} users.") except BaseException: await tgbot.send_message( event.chat_id, "Please add me to your Private log group for proper use.")
async def tele(event): allu = len(full_userbase()) blu = len(all_bl_users()) await tgbot.send_message( event.chat_id, "Here is the stats for your bot:\nTotal Users = {}\nBlacklisted Users = {}" .format(allu, blu))
async def settings(event): if event.sender_id == OWNER_ID: allu = len(full_userbase()) blu = len(all_bl_users()) pop = "Here is the stats for your bot:\nTotal Users = {}\nBlacklisted Users = {}".format( allu, blu) await event.answer(pop, alert=True) else: await event.answer("You can't use this bot.", alert=True)