MCPcopy Create free account
hub / github.com/VJBots/VJ-File-Store / pm_broadcast

Function pm_broadcast

clone_plugins/broadcast.py:14–57  ·  view source on GitHub ↗
(bot, message)

Source from the content-addressed store, hash-verified

12
13@Client.on_message(filters.command("broadcast"))
14async def pm_broadcast(bot, message):
15 me = await bot.get_me()
16 owner = mongo_db.bots.find_one({'bot_id': me.id})
17 ownerid = int(owner['user_id'])
18 if ownerid != message.from_user.id:
19 await message.reply_text("ᴏɴʟʏ ᴏᴡɴᴇʀ ᴄᴏᴍᴍᴀɴᴅ❗")
20 return
21 b_msg = await bot.ask(chat_id = message.from_user.id, text = "Now Send Me Your Broadcast Message")
22 try:
23 users = await clonedb.get_all_users(me.id)
24 sts = await message.reply_text('Broadcasting your messages...')
25 start_time = time.time()
26 total_users = await clonedb.total_users_count(me.id)
27 done = 0
28 blocked = 0
29 deleted = 0
30 failed = 0
31 success = 0
32 async for user in users:
33 if 'user_id' in user:
34 pti, sh = await broadcast_messages(me.id, int(user['user_id']), b_msg)
35 if pti:
36 success += 1
37 elif pti == False:
38 if sh == "Blocked":
39 blocked += 1
40 elif sh == "Deleted":
41 deleted += 1
42 elif sh == "Error":
43 failed += 1
44 done += 1
45 if not done % 20:
46 await sts.edit(f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
47 else:
48 # Handle the case where 'id' key is missing in the user dictionary
49 done += 1
50 failed += 1
51 if not done % 20:
52 await sts.edit(f"Broadcast in progress:\n\nTotal Users {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
53
54 time_taken = datetime.timedelta(seconds=int(time.time()-start_time))
55 await sts.edit(f"Broadcast Completed:\nCompleted in {time_taken} seconds.\n\nTotal Users: {total_users}\nCompleted: {done} / {total_users}\nSuccess: {success}\nBlocked: {blocked}\nDeleted: {deleted}")
56 except Exception as e:
57 print(f"error: {e}")
58
59# Don't Remove Credit Tg - @VJ_Bots
60# Subscribe YouTube Channel For Amazing Bot https://youtube.com/@Tech_VJ

Callers

nothing calls this directly

Calls 3

broadcast_messagesFunction · 0.70
get_all_usersMethod · 0.45
total_users_countMethod · 0.45

Tested by

no test coverage detected