Ver Fonte

Luna user identification

TheHamkerCat há 5 anos atrás
pai
commit
1739e5e2c2
3 ficheiros alterados com 95 adições e 8 exclusões
  1. 9 5
      wbb/modules/chatbot.py
  2. 85 0
      wbb/modules/quotly.py
  3. 1 3
      wbb/utils/inlinefuncs.py

+ 9 - 5
wbb/modules/chatbot.py

@@ -72,8 +72,8 @@ async def chatbot_status(_, message):
         await message.reply_text("**Usage**\n/chatbot [ON|OFF]")
 
 
-async def lunaQuery(query):
-    luna = await arq.luna(query)
+async def lunaQuery(query: str, user_id: int):
+    luna = await arq.luna(query, user_id)
     return luna.result
 
 
@@ -90,7 +90,9 @@ async def chatbot_talk(_, message):
     if message.reply_to_message.from_user.id != BOT_ID:
         return
     query = message.text
-    response = await lunaQuery(query)
+    await app2.send_chat_action(message.chat.id, "typing")
+    response = await lunaQuery(query, message.from_user.id if message.from_user else 0)
+    await app2.send_chat_action(message.chat.id, "cancel")
     await message.reply_text(response)
 
 
@@ -149,7 +151,9 @@ async def chatbot_talk_ubot(_, message):
     else:
         if username not in query:
             return
-    response = await lunaQuery(query)
+    await app2.send_chat_action(message.chat.id, "typing")
+    response = await lunaQuery(query, message.from_user.id if message.from_user else 0)
+    await app2.send_chat_action(message.chat.id, "cancel")
     await message.reply_text(response)
 
 
@@ -163,6 +167,6 @@ async def chatbot_talk_ubot_pm(_, message):
         return
     query = message.text
     await app2.send_chat_action(message.chat.id, "typing")
-    response = await lunaQuery(query)
+    response = await lunaQuery(query, message.from_user.id if message.from_user else 0)
     await message.reply_text(response)
     await app2.send_chat_action(message.chat.id, "cancel")

+ 85 - 0
wbb/modules/quotly.py

@@ -0,0 +1,85 @@
+from io import BytesIO
+
+from pyrogram import filters
+from pyrogram.types import Message
+
+from wbb import app, app2, arq
+from wbb.core.decorators.errors import capture_err
+
+__MODULE__ = "Quotly"
+__HELP__ = """
+/q - To quote a message.
+/q [INTEGER] - To quote more than 1 messages.
+"""
+
+
+async def quotify(messages: list):
+    response = await arq.quotly(messages)
+    sticker = response.result
+    sticker = BytesIO(sticker)
+    sticker.name = "sticker.webp"
+    return sticker
+
+
+def getArg(message: Message) -> str:
+    arg = message.text.strip().split(None, 1)[1].strip()
+    return arg
+
+
+def isArgInt(message: Message) -> bool:
+    count = getArg(message)
+    try:
+        count = int(count)
+        return [True, count]
+    except ValueError:
+        return [False, 0]
+
+
+@app.on_message(filters.command("q"))
+async def quotly_func(_, message: Message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a message to quote it.")
+        return
+    if not message.reply_to_message.text:
+        await message.reply_text("Replied message has no text, can't quote it.")
+        return
+    m = await message.reply_text("Quoting Messages")
+    if len(message.command) < 2:
+        messages = [message.reply_to_message]
+
+    elif len(message.command) == 2:
+        arg = isArgInt(message)
+        if arg[0]:
+            if arg[1] < 2 or arg[1] > 6:
+                await m.edit("Argument must be between 2-6.")
+                return
+            count = arg[1]
+            messages = await app.get_messages(
+                message.chat.id,
+                [
+                    i
+                    for i in range(
+                        message.reply_to_message.message_id,
+                        message.reply_to_message.message_id + count,
+                    )
+                ],
+                replies=0,
+            )
+        else:
+            if getArg(message) != "r":
+                await m.edit(
+                    "Incorrect Argument, Pass **'r'** or **'INT'**, **EX:** __/q 2__"
+                )
+                return
+            reply_message = await app.get_messages(
+                message.chat.id, message.reply_to_message.message_id, replies=1
+            )
+            reply_message = reply_message.reply_to_message
+            messages = [reply_message, message.reply_to_message]
+    else:
+        await m.edit("Incorrect argument, check quotly module in help section.")
+        return
+    sticker = await quotify(messages)
+    await message.reply_sticker(sticker)
+    await m.delete()
+    sticker.close()

+ 1 - 3
wbb/utils/inlinefuncs.py

@@ -965,9 +965,7 @@ async def tmdb_func(answers, query):
         )
         answers.append(
             InlineQueryResultPhoto(
-                photo_url=result.backdrop
-                if result.backdrop
-                else result.poster,
+                photo_url=result.backdrop if result.backdrop else result.poster,
                 caption=caption,
                 title=result.title,
                 description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",