Sfoglia il codice sorgente

Some useful modifications and additions (#208)

* env vars

* use ist as timezone and remove deleted accounts from couple user list

* total members count in gstats

* broadcast message to bot users, broadcast by reeplying to message, broadcast with formatting and buttons
HYBRID 3 anni fa
parent
commit
0c99a012d7
5 ha cambiato i file con 97 aggiunte e 29 eliminazioni
  1. 1 0
      requirements.txt
  2. 20 20
      sample_config.py
  3. 11 4
      wbb/modules/couple.py
  4. 15 0
      wbb/modules/global_stats.py
  5. 50 5
      wbb/modules/sudoers.py

+ 1 - 0
requirements.txt

@@ -25,3 +25,4 @@ fuzzysearch
 img2pdf
 telegraph
 pytube
+pytz

+ 20 - 20
sample_config.py

@@ -1,20 +1,20 @@
-BOT_TOKEN = "467677575:YZfaakjwd545dfg-N6JStihhuw5gQeZHntc"
-API_ID = 123456
-SESSION_STRING = ""  # Check Readme to generate sessions; need for userbot
-API_HASH = "dfxcgs5s12hdcxfgdfz"
-USERBOT_PREFIX = "."
-PHONE_NUMBER = "+916969696969"  # Need for Userbot
-SUDO_USERS_ID = [
-    4543744343,
-    543214651351,
-]  # Sudo users have full access to everything, don't trust anyone
-LOG_GROUP_ID = -100125431255
-GBAN_LOG_GROUP_ID = -100125431255
-MESSAGE_DUMP_CHAT = -1001181696437
-WELCOME_DELAY_KICK_SEC = 300
-MONGO_URL = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
-ARQ_API_KEY = "Get this from @ARQRobot"
-ARQ_API_URL = "https://arq.hamker.in"
-LOG_MENTIONS = True
-RSS_DELAY = 300  # In seconds
-PM_PERMIT = True
+import os
+
+BOT_TOKEN = os.environ.get('BOT_TOKEN')
+API_ID = int(os.environ.get('API_ID'))
+SESSION_STRING = os.environ.get('SESSION_STRING', '')
+API_HASH = os.environ.get('API_HASH')
+USERBOT_PREFIX = os.environ.get('USERBOT_PREFIX', '.')
+PHONE_NUMBER = os.environ.get('PHONE_NUMBER')
+SUDO_USERS_ID = list(map(int, os.environ.get('SUDO_USERS_ID', '').split()))
+LOG_GROUP_ID = int(os.environ.get('LOG_GROUP_ID'))
+GBAN_LOG_GROUP_ID = int(os.environ.get('GBAN_LOG_GROUP_ID'))
+MESSAGE_DUMP_CHAT = int(os.environ.get('MESSAGE_DUMP_CHAT'))
+WELCOME_DELAY_KICK_SEC = int(os.environ.get('WELCOME_DELAY_KICK_SEC', 600))
+MONGO_URL = os.environ.get('MONGO_URL')
+ARQ_API_KEY = os.environ.get('ARQ_API_KEY')
+ARQ_API_URL = os.environ.get('ARQ_API_URL', 'https://arq.hamker.in')
+LOG_MENTIONS = os.environ.get('LOG_MENTIONS', 'True').lower() in ['true', '1']
+RSS_DELAY = int(os.environ.get('RSS_DELAY', 300))
+PM_PERMIT = os.environ.get('PM_PERMIT', 'True').lower() in ['true', '1']
+SLAP_STICKERS = list(map(str, os.environ.get('SLAP_STICKERS').split()))

+ 11 - 4
wbb/modules/couple.py

@@ -23,6 +23,7 @@ SOFTWARE.
 """
 import random
 from datetime import datetime
+import pytz
 
 from pyrogram import enums, filters
 
@@ -36,8 +37,13 @@ __HELP__ = "/detect_gay - To Choose Couple Of The Day"
 
 # Date and time
 def dt():
-    now = datetime.now()
-    dt_string = now.strftime("%d/%m/%Y %H:%M")
+    # Set the timezone to Indian Standard Time
+    ist_timezone = pytz.timezone('Asia/Kolkata')
+
+    # Get the current time in IST
+    ist_now = datetime.now(ist_timezone)
+
+    dt_string = ist_now.strftime("%d/%m/%Y %H:%M")
     dt_list = dt_string.split(" ")
     return dt_list
 
@@ -75,8 +81,9 @@ async def couple(_, message):
         if not is_selected:
             list_of_users = []
             async for i in app.get_chat_members(message.chat.id):
-                if not i.user.is_bot:
-                    list_of_users.append(i.user.id)
+                if not i.user.is_bot and not i.user.is_deleted:
+                    user = await app.get_users(i.user.id)
+                    list_of_users.append(user.id)
             if len(list_of_users) < 2:
                 return await m.edit("Not enough users")
             c1_id = random.choice(list_of_users)

+ 15 - 0
wbb/modules/global_stats.py

@@ -65,6 +65,19 @@ async def clean_db(_, message):
     await m.edit("**Database Cleaned.**")
 
 
+async def get_total_users_count():
+    schats = await get_served_chats()
+    chats = [int(chat["chat_id"]) for chat in schats]
+    total_count = 0
+    for chat_id in chats:
+        try:
+            count = await app.get_chat_members_count(chat_id)
+            total_count += count
+        except Exception:
+            print(f"Error fetching members count for chat: {chat_id}")
+    return total_count
+
+
 @app.on_message(filters.command("gstats") & SUDOERS)
 @capture_err
 async def global_stats(_, message):
@@ -77,6 +90,7 @@ async def global_stats(_, message):
     # For bot served chat and users count
     served_chats = len(await get_served_chats())
     served_users = len(await get_served_users())
+    total_users = await get_total_users_count()  # get total user count
     # Gbans count
     gbans = await get_gbans_count()
     _notes = await get_notes_count()
@@ -144,6 +158,7 @@ async def global_stats(_, message):
     **{warns_count}** Warns, Across **{warns_chats_count}** chats.
     **{karmas_count}** Karma, Across **{karmas_chats_count}** chats.
     **{served_users}** Users, Across **{served_chats}** chats.
+    **{total_users}** Total users in chats.
     **{developers}** Developers And **{commits}** Commits On **[Github]({rurl})**.
 
 **Global Stats of {USERBOT_NAME}**:

+ 50 - 5
wbb/modules/sudoers.py

@@ -27,8 +27,9 @@ import subprocess
 import time
 
 import psutil
-from pyrogram import filters
+from pyrogram import filters, types
 from pyrogram.errors import FloodWait
+from pyrogram.types import InlineKeyboardMarkup
 
 from wbb import (
     BOT_ID,
@@ -45,6 +46,7 @@ from wbb.utils.dbfunctions import (
     get_served_chats,
     is_gbanned_user,
     remove_gban_user,
+    get_served_users,
 )
 from wbb.utils.functions import extract_user, extract_user_and_reason, restart
 
@@ -60,6 +62,8 @@ __HELP__ = """
 
 /broadcast - To Broadcast A Message To All Groups.
 
+/ubroadcast - To Broadcast A Message To All Users.
+
 /update - To Update And Restart The Bot
 
 /eval - Execute Python Code
@@ -181,10 +185,13 @@ async def unban_globally(_, message):
 @app.on_message(filters.command("broadcast") & SUDOERS)
 @capture_err
 async def broadcast_message(_, message):
-    if len(message.command) < 2:
-        return await message.reply_text("**Usage**:\n/broadcast [MESSAGE]")
     sleep_time = 0.1
-    text = message.text.split(None, 1)[1]
+    text = message.reply_to_message.text.markdown
+    reply_message = message.reply_to_message
+
+    reply_markup = None
+    if reply_message.reply_markup:
+        reply_markup = InlineKeyboardMarkup(reply_message.reply_markup.inline_keyboard)
     sent = 0
     schats = await get_served_chats()
     chats = [int(chat["chat_id"]) for chat in schats]
@@ -193,7 +200,11 @@ async def broadcast_message(_, message):
     )
     for i in chats:
         try:
-            await app.send_message(i, text=text)
+            await app.send_message(
+                i,
+                text=text,
+                reply_markup=reply_markup,
+            )
             await asyncio.sleep(sleep_time)
             sent += 1
         except FloodWait as e:
@@ -217,3 +228,37 @@ async def update_restart(_, message):
         return await message.reply_text(str(e))
     m = await message.reply_text("**Updated with default branch, restarting now.**")
     await restart(m)
+
+
+@app.on_message(filters.command("ubroadcast") & SUDOERS)
+@capture_err
+async def broadcast_message(_, message):
+    sleep_time = 0.1
+    sent = 0
+    schats = await get_served_users()
+    chats = [int(chat["user_id"]) for chat in schats]
+    text = message.reply_to_message.text.markdown
+    reply_message = message.reply_to_message
+
+    reply_markup = None
+    if reply_message.reply_markup:
+        reply_markup = InlineKeyboardMarkup(reply_message.reply_markup.inline_keyboard)
+
+    m = await message.reply_text(
+        f"Broadcast in progress, will take {len(chats) * sleep_time} seconds."
+    )
+
+    for i in chats:
+        try:
+            await app.send_message(
+                i,
+                text=text,
+                reply_markup=reply_markup,
+            )
+            await asyncio.sleep(sleep_time)
+            sent += 1
+        except FloodWait as e:
+            await asyncio.sleep(int(e.value))
+        except Exception:
+            pass
+    await m.edit(f"**Broadcasted Message to {sent} Users.**")