فهرست منبع

Added user info

TheHamkerCat 5 سال پیش
والد
کامیت
ad7a0f6232
8فایلهای تغییر یافته به همراه110 افزوده شده و 6 حذف شده
  1. 4 0
      app.json
  2. 1 0
      requirements.txt
  3. 2 0
      sample_config.py
  4. 5 5
      wbb/__init__.py
  5. 18 1
      wbb/modules/inline.py
  6. 57 0
      wbb/modules/user_info.py
  7. 11 0
      wbb/utils/dbfunctions.py
  8. 12 0
      wbb/utils/inlinefuncs.py

+ 4 - 0
app.json

@@ -70,6 +70,10 @@
         "MESSAGE_DUMP_CHAT": {
             "description": "Chat_id of the group where useless things will go",
             "required": true
+        },
+        "SPAMWATCH_API_KEY": {
+            "description": "Get this from @SpamWatchBot",
+            "required": true
         }
     }
 }

+ 1 - 0
requirements.txt

@@ -1,4 +1,5 @@
 ffmpeg-python
+spamwatch
 carbonnow
 aiohttp
 aiofiles

+ 2 - 0
sample_config.py

@@ -14,6 +14,7 @@ if HEROKU:
     FERNET_ENCRYPTION_KEY = environ.get("FERNET_ENCRYPTION_KEY", None)
     WELCOME_DELAY_KICK_SEC = int(environ.get("WELCOME_DELAY_KICK_SEC", None))
     MONGO_DB_URI = environ.get("MONGO_DB_URI", None)
+    SPAMWATCH_API_KEY = environ.get("SPAMWATCH_API_KEY", None)
     ARQ_API_BASE_URL = environ.get("ARQ_API_BASE_URL", None)
 
 else:
@@ -29,5 +30,6 @@ else:
     FERNET_ENCRYPTION_KEY = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=" # Leave this as it is
     WELCOME_DELAY_KICK_SEC = 300
     MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourDataBaseName?retryWrites=true&w=majority"
+    SPAMWATCH_API_KEY = "Get this from @SpamWatchBot"
     # NOTE Don't make changes below this line
     ARQ_API_BASE_URL = "http://thearq.tech"

+ 5 - 5
wbb/__init__.py

@@ -30,7 +30,7 @@ from Python_ARQ import ARQ
 from telegraph import Telegraph
 from os import path
 import time
-
+import spamwatch as spamwatch_
 is_config = path.exists('config.py')
 if is_config:
     from config import *
@@ -39,6 +39,7 @@ else:
 
 listen = listen
 USERBOT_PREFIX = USERBOT_PREFIX
+SPAMWATCH_API_KEY = SPAMWATCH_API_KEY
 SUDOERS = SUDO_USERS_ID
 GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
 FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
@@ -62,13 +63,12 @@ mongo_client = MongoClient(MONGO_DB_URI)
 db = mongo_client.wbb
 # ARQ client
 arq = ARQ(ARQ_API_BASE_URL)
-
+# Telegram client
 telegraph = Telegraph()
 telegraph.create_account(short_name="wbb")
-
 session = aiohttp.ClientSession()
-
-
+# Spamwatch client
+spamwatch = spamwatch_.Client(SPAMWATCH_API_KEY)
 
 BOT_ID = 0
 BOT_NAME = ""

+ 18 - 1
wbb/modules/inline.py

@@ -351,7 +351,7 @@ async def inline_query_handler(client, query):
                     switch_pm_parameter='inline',
                 )
                 return
-            link = text.strip().split()[1]
+            link = text.split()[1]
             answerss = await carbon_inline_func(answers, link)
             await client.answer_inline_query(
                 query.id,
@@ -414,6 +414,23 @@ async def inline_query_handler(client, query):
                 results=answerss,
                 cache_time=2
             )
+
+        elif text.split()[0] == "info":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='User Info | info [USERNAME|ID]',
+                    switch_pm_parameter='inline',
+                )
+                return
+            tex = text.split()[1].strip()
+            answerss = await user_info_inline_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
     except Exception as e:
         e = traceback.format_exc()
         print(e, " InLine")

+ 57 - 0
wbb/modules/user_info.py

@@ -0,0 +1,57 @@
+from wbb import app, SUDOERS, spamwatch
+from pyrogram import filters
+from wbb.utils.dbfunctions import is_gbanned_user, user_global_karma
+import os
+import traceback
+
+__MODULE__ = "Info"
+__HELP__ = "/info [USERNAME|ID] - Get info about a user."
+
+
+async def get_user_info(user):
+    user = await app.get_users(user)
+    user_id = user.id
+    username = user.username
+    first_name = user.first_name
+    mention = user.mention("Link")
+    status = user.status
+    dc_id = user.dc_id
+    photo_id = user.photo.big_file_id if user.photo else None
+    is_gbanned = await is_gbanned_user(user_id)
+    is_sudo = user_id in SUDOERS
+    karma = await user_global_karma(user_id)
+    banned_in_spamwatch = False if spamwatch.get_ban(
+        user_id) == False else True
+    caption = f"""
+**ID:** `{user_id}`
+**DC:** {dc_id}
+**Name:** {first_name}
+**Username:** {("@" + username) if username else None}
+**Permalink:** {mention}
+**Status:** {status}
+**Sudo:** {is_sudo}
+**Karma:** {karma}
+**Gbanned:** {is_gbanned}
+**Spamwatch Restricted:** {banned_in_spamwatch}
+"""
+    return [caption, photo_id]
+
+
+@app.on_message(filters.command("info"))
+async def info_func(_, message):
+    try:
+        if len(message.command) != 2:
+            await message.reply_text("**Usage:**/info [USERNAME|ID]")
+            return
+        user = message.text.split(None, 1)[1]
+        info_caption, photo_id = await get_user_info(user)
+        if not photo_id:
+            await app.send_message(message.chat.id, text=info_caption)
+            return
+        photo = await app.download_media(photo_id)
+        await app.send_photo(message.chat.id, photo=photo, caption=info_caption)
+        os.remove(photo)
+    except Exception as e:
+        await message.reply_text(str(e))
+        e = traceback.format_exc()
+        print(e)

+ 11 - 0
wbb/utils/dbfunctions.py

@@ -300,6 +300,17 @@ async def get_karmas_count() -> dict:
     }
 
 
+async def user_global_karma(user_id) -> int:
+    chats = karmadb.find({"chat_id": {"$lt": 0}})
+    if not chats:
+        return 0
+    total_karma = 0
+    for chat in await chats.to_list(length=1000000):
+        karma = await get_karma(chat['chat_id'], await int_to_alpha(user_id))
+        total_karma += int(karma['karma']) if karma else 0
+    return total_karma
+
+
 async def get_karmas(chat_id: int) -> Dict[str, int]:
     karma = await karmadb.find_one({"chat_id": chat_id})
     if karma:

+ 12 - 0
wbb/utils/inlinefuncs.py

@@ -43,6 +43,7 @@ from pyrogram import __version__ as pyrover, filters
 from time import time, ctime
 from random import randint
 from wbb.utils.fetch import fetch
+from wbb.modules.user_info import get_user_info
 from wbb.modules.userbot import eval_executer_func
 from wbb.modules.music import download_youtube_audio
 from wbb.utils.functions import test_speedtest, get_http_status_code, make_carbon
@@ -901,3 +902,14 @@ async def carbon_inline_func(answers, link):
         )
     )
     return answers
+
+
+async def user_info_inline_func(answers, user):
+    caption, photo_id = await get_user_info(user)
+    answers.append(
+        InlineQueryResultArticle(
+            title="Found User.",
+            input_message_content=InputTextMessageContent(caption)
+        )
+    )
+    return answers