Преглед изворни кода

Beta (#29)

* Added /mute and /unmute

* Added /succ back

* Added Captcha

* Added /cheat cheatsheet

* Added /weather

* Added Translator, /tr command btw

* Added /song, jiosaavn
TheHamkerCat пре 5 година
родитељ
комит
639b98f697
10 измењених фајлова са 286 додато и 16 уклоњено
  1. 5 0
      commands.txt
  2. 1 0
      requirements.txt
  3. 3 0
      sample_config.ini
  4. 5 3
      wbb/__init__.py
  5. 46 2
      wbb/modules/admin.py
  6. 91 7
      wbb/modules/greetings.py
  7. 56 1
      wbb/modules/misc.py
  8. 2 1
      wbb/modules/rice.py
  9. 48 0
      wbb/modules/succ.py
  10. 29 2
      wbb/modules/sudoers.py

+ 5 - 0
commands.txt

@@ -3,6 +3,7 @@
 ban - Ban A User
 ban - Ban A User
 banme - Ban Yourself
 banme - Ban Yourself
 cat - Get Cute Cats Images
 cat - Get Cute Cats Images
+cheat - Get Programming Related Help
 commit - Generate Funny Commit Messages
 commit - Generate Funny Commit Messages
 decrypt - Decrypt Text
 decrypt - Decrypt Text
 del - Delete Replied Message
 del - Delete Replied Message
@@ -19,6 +20,7 @@ kick - Kick A User
 kickme - Kick Yourself
 kickme - Kick Yourself
 log - Get Logs From Last Run.
 log - Get Logs From Last Run.
 music - [link] To Download Music From Various Websites
 music - [link] To Download Music From Various Websites
+mute - Mute A User
 paste - Paste To Neokobin
 paste - Paste To Neokobin
 pin - Pin The Replied Message
 pin - Pin The Replied Message
 ping - Get Response Time From All TG Datacenters
 ping - Get Response Time From All TG Datacenters
@@ -34,9 +36,12 @@ speedtest - To Perform A Speedtest.
 so - Search For Something On StackOverflow
 so - Search For Something On StackOverflow
 stats  - To Check System Status.
 stats  - To Check System Status.
 succ - Sends Succ Image For A Given Word
 succ - Sends Succ Image For A Given Word
+tr - Translate A Message
 ud - Search For Something In Urban Dictionary
 ud - Search For Something In Urban Dictionary
 unban - Unban A User
 unban - Unban A User
+unmute - Unmute A User
 unpin - Unpin The Last Pinned Message.
 unpin - Unpin The Last Pinned Message.
 wall - Get Wallpapers
 wall - Get Wallpapers
+weather - Get Weather Info
 wiki - Search For Something On Wikipedia
 wiki - Search For Something On Wikipedia
 yt - Search For Something On YouTube
 yt - Search For Something On YouTube

+ 1 - 0
requirements.txt

@@ -10,3 +10,4 @@ youtube_dl
 search_engine_parser
 search_engine_parser
 wikipedia
 wikipedia
 ipinfo
 ipinfo
+googletrans==4.0.0-rc1

+ 3 - 0
sample_config.ini

@@ -12,6 +12,9 @@ alpha_coders_wall_api_key = ca45r8c444s55g7t5s3a4esd33hs6t
 # Follow this tutorial to generate a key
 # Follow this tutorial to generate a key
 # https://cryptography.io/en/latest/fernet.html
 # https://cryptography.io/en/latest/fernet.html
 fernet_encryption_key = iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=
 fernet_encryption_key = iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM=
+captcha_delay_in_seconds = 300
+#https://github.com/cyberboysumanjay/JioSaavnAPI
+jio_saavn_api = http://127.0.0.1:5000/result/?query=
 
 
 [prefix]
 [prefix]
 prefixes = /
 prefixes = /

+ 5 - 3
wbb/__init__.py

@@ -32,9 +32,11 @@ config = ConfigParser()
 config.read("config.ini")
 config.read("config.ini")
 OWNER_ID = int(config.get("admin", "owner_id"))
 OWNER_ID = int(config.get("admin", "owner_id"))
 SUDO_USER_ID = int(config.get("admin", "sudo_user_id"))
 SUDO_USER_ID = int(config.get("admin", "sudo_user_id"))
-NEOFETCH = (config.get("admin", "neofetch"))
-WALL_API_KEY = (config.get("admin", "alpha_coders_wall_api_key"))
-FERNET_ENCRYPTION_KEY = (config.get("admin", "fernet_encryption_key"))
+NEOFETCH = config.get("admin", "neofetch")
+WALL_API_KEY = config.get("admin", "alpha_coders_wall_api_key")
+FERNET_ENCRYPTION_KEY = config.get("admin", "fernet_encryption_key")
+WELCOME_DELAY_KICK_SEC = int(config.get("admin", "captcha_delay_in_seconds"))
+JSMAPI = config.get("admin", "jio_saavn_api")
 Command = config.get("prefix", "prefixes").split()
 Command = config.get("prefix", "prefixes").split()
 MOD_LOAD = config.get("mods", "load_modules").split()
 MOD_LOAD = config.get("mods", "load_modules").split()
 MOD_NOLOAD = config.get("mods", "noload_modules").split()
 MOD_NOLOAD = config.get("mods", "noload_modules").split()

+ 46 - 2
wbb/modules/admin.py

@@ -1,5 +1,5 @@
 from pyrogram import filters
 from pyrogram import filters
-from pyrogram.types import Message
+from pyrogram.types import Message, ChatPermissions
 from wbb import OWNER_ID, SUDO_USER_ID, app
 from wbb import OWNER_ID, SUDO_USER_ID, app
 from wbb.utils import cust_filter
 from wbb.utils import cust_filter
 from wbb.utils.botinfo import BOT_ID
 from wbb.utils.botinfo import BOT_ID
@@ -14,7 +14,10 @@ __HELP__ = '''/ban    - Ban A User
 /kickme - Kicks A User Who Issued The Command
 /kickme - Kicks A User Who Issued The Command
 /promote - Promote A Member
 /promote - Promote A Member
 /pin - Pin A Message
 /pin - Pin A Message
-/unpin - Unpin A Message'''
+/unpin - Unpin A Message
+/mute - Mute A User
+/unmute - Unmute A User
+/report - Report To All Admins'''
 
 
 SUDO = [OWNER_ID, SUDO_USER_ID]
 SUDO = [OWNER_ID, SUDO_USER_ID]
 
 
@@ -342,3 +345,44 @@ async def unpin(_, message: Message):
             await app.unpin_all_chat_messages(chat_id)
             await app.unpin_all_chat_messages(chat_id)
     else:
     else:
         await message.reply_text("You're Not An Admin, Stop Spamming!")
         await message.reply_text("You're Not An Admin, Stop Spamming!")
+
+# Mute members
+
+
+@app.on_message(cust_filter.command(commands=("mute")) & ~filters.edited)
+async def mute(_, message: Message):
+    chat_id = message.chat.id
+    admins = await list_admins(chat_id)
+    from_user_id = message.from_user.id
+    username = message.text.replace("/mute", "")
+
+    if from_user_id in admins or from_user_id in SUDO:
+        if username != "":
+            victim = username
+        else:
+            victim = message.reply_to_message.from_user.id
+        await message.chat.restrict_member(victim,
+                                           permissions=ChatPermissions())
+        await message.reply_text("Muted!")
+    else:
+        await message.reply_text("Get Yourself An Admin Tag!")
+
+# Unmute members
+
+
+@app.on_message(cust_filter.command(commands=("unmute")) & ~filters.edited)
+async def unmute(_, message: Message):
+    chat_id = message.chat.id
+    admins = await list_admins(chat_id)
+    from_user_id = message.from_user.id
+    username = message.text.replace("/unmute", "")
+
+    if from_user_id in admins or from_user_id in SUDO:
+        if username != "":
+            victim = username
+        else:
+            victim = message.reply_to_message.from_user.id
+        await message.chat.unban_member(victim)
+        await message.reply_text("Unmuted!")
+    else:
+        await message.reply_text("Get Yourself An Admin Tag!")

+ 91 - 7
wbb/modules/greetings.py

@@ -1,12 +1,96 @@
-from pyrogram import filters, emoji
-from pyrogram.types import Message
-from wbb import app
+"""
+ Thanks to @dashezup for this module
+ Repo - https://github.com/dashezup/tgbot
 
 
-MESSAGE = "{} Welcome {}!"
+A Pyrogram Smart Plugin to verify if new members are human
+# the bot must be admin in the chat
+# should not be lesser than 30 or the user may be banned if he didn't
+# press the verification button
+"""
+
+
+import asyncio
+from datetime import datetime
+from pyrogram import filters
+from wbb import app, WELCOME_DELAY_KICK_SEC
+from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
+from pyrogram.types import ChatPermissions
+from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
 
 
 
 
 @app.on_message(filters.new_chat_members)
 @app.on_message(filters.new_chat_members)
 async def welcome(_, message: Message):
 async def welcome(_, message: Message):
-    new_members = [i.mention for i in message.new_chat_members]
-    text = MESSAGE.format(emoji.CROWN, ",  ".join(new_members))
-    await message.reply_text(text, disable_web_page_preview=True)
+    """Mute new member and send message with button"""
+    new_members = [f"{u.mention}" for u in message.new_chat_members]
+    text = (f"Welcome, {', '.join(new_members)}\n**Are you human?**\n"
+            "You will be removed from this chat if you are not verified "
+            f"in {WELCOME_DELAY_KICK_SEC} seconds")
+    await message.chat.restrict_member(message.from_user.id, ChatPermissions())
+    button_message = await message.reply(
+        text,
+        reply_markup=InlineKeyboardMarkup(
+            [
+                [
+                    InlineKeyboardButton(
+                        "Press Here to Verify",
+                        callback_data="pressed_button"
+                    )
+                ]
+            ]
+        ),
+        quote=True
+    )
+    await kick_restricted_after_delay(WELCOME_DELAY_KICK_SEC, button_message)
+
+
+@app.on_callback_query(filters.regex("pressed_button"))
+async def callback_query_welcome_button(_, callback_query):
+    """After the new member presses the button, set his permissions to
+    chat permissions, delete button message and join message
+    """
+    button_message = callback_query.message
+    join_message = button_message.reply_to_message
+    pending_user = join_message.from_user
+    pending_user_id = pending_user.id
+    pressed_user_id = callback_query.from_user.id
+    if pending_user_id == pressed_user_id:
+        await callback_query.answer("Congrats, captcha passed!")
+        await button_message.chat.unban_member(pending_user_id)
+        await button_message.delete()
+        await join_message.delete()
+    else:
+        await callback_query.answer("This is not for you")
+
+
+async def kick_restricted_after_delay(delay, button_message: Message):
+    """If the new member is still restricted after the delay, delete
+    button message and join message and then kick him
+    """
+    await asyncio.sleep(delay)
+    join_message = button_message.reply_to_message
+    group_chat = button_message.chat
+    user_id = join_message.from_user.id
+    await join_message.delete()
+    await button_message.delete()
+    await _ban_restricted_user_until_date(group_chat, user_id, duration=delay)
+
+
+@app.on_message(filters.left_chat_member)
+async def left_chat_member(_, message: Message):
+    """When a restricted member left the chat, ban him for a while"""
+    group_chat = message.chat
+    user_id = message.left_chat_member.id
+    await _ban_restricted_user_until_date(group_chat, user_id,
+                                          duration=WELCOME_DELAY_KICK_SEC)
+
+
+async def _ban_restricted_user_until_date(group_chat,
+                                          user_id: int,
+                                          duration: int):
+    try:
+        member = await group_chat.get_member(user_id)
+        if member.status == "restricted":
+            until_date = int(datetime.utcnow().timestamp() + duration)
+            await group_chat.kick_member(user_id, until_date=until_date)
+    except UserNotParticipant:
+        pass

+ 56 - 1
wbb/modules/misc.py

@@ -1,8 +1,10 @@
 import secrets
 import secrets
 import string
 import string
+import requests
 import ipinfo
 import ipinfo
 from pyrogram import filters
 from pyrogram import filters
 from pyrogram.types import Message
 from pyrogram.types import Message
+from googletrans import Translator
 from cryptography.fernet import Fernet
 from cryptography.fernet import Fernet
 from wbb.utils.botinfo import BOT_ID
 from wbb.utils.botinfo import BOT_ID
 from wbb import app, FERNET_ENCRYPTION_KEY
 from wbb import app, FERNET_ENCRYPTION_KEY
@@ -18,7 +20,10 @@ __HELP__ = '''/commit - Generate Funny Commit Messages
 /http - Get Cats Reference Photo For Http Error Codes
 /http - Get Cats Reference Photo For Http Error Codes
 /encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
 /encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
 /decrypt - Decrypt Text
 /decrypt - Decrypt Text
-/ipinfo - Get Info About An Ip Address'''
+/ipinfo - Get Info About An Ip Address
+/cheat - Get Programming Related Help
+/weather - To Get Weather Info
+/tr - Translate A Message'''
 
 
 
 
 @app.on_message(cust_filter.command(commands=("commit")) & ~filters.edited)
 @app.on_message(cust_filter.command(commands=("commit")) & ~filters.edited)
@@ -169,3 +174,53 @@ Timezone - {details.timezone}`''')
     else:
     else:
         await message.reply_text('`/ipinfo` Requires An IP As Argument'
         await message.reply_text('`/ipinfo` Requires An IP As Argument'
                                  + '. Ex - `/ipinfo 1.1.1.1`')
                                  + '. Ex - `/ipinfo 1.1.1.1`')
+
+# Cheat.sh
+
+
+@app.on_message(cust_filter.command(commands=("cheat")) & ~filters.edited)
+async def cheat(_, message: Message):
+    text = message.text.replace("/cheat ", "")
+    ftext = text.split()
+    try:
+        language = ftext[0]
+    except IndexError:
+        await message.reply_text("/cheat [language] [query]")
+    try:
+        query = ftext[1]
+    except IndexError:
+        await message.reply_text("/cheat [language] [query]")
+    r = requests.get(f"http://cht.sh/{language}/{query}?QT")
+    reply = r.text
+    await message.reply_text(f"`{reply}`")
+
+# Weather
+
+
+@app.on_message(cust_filter.command(commands=("weather")) & ~filters.edited)
+async def weather(_, message: Message):
+    city = message.text.replace("/weather ", "")
+    if city != "":
+        r = requests.get(f"https://wttr.in/{city}?mnTC0")
+        data = r.text
+        await message.reply_text(f"`{data}`")
+    else:
+        await message.reply_text("/weather [city]")
+
+# Translate
+
+
+@app.on_message(cust_filter.command(commands=("tr")) & ~filters.edited)
+async def tr(_, message: Message):
+    lang = message.text.replace("/tr", "")
+    flang = lang.replace(" ", "")
+
+    if message.reply_to_message and flang != "":
+        text = message.reply_to_message.text
+        i = Translator().translate(text, dest=flang)
+        await message.reply_text(i.text)
+    else:
+        await message.reply_text("Reply to a message with /tr [language code]"
+                                 + "\nGet supported language list from here -"
+                                 + " https://py-googletrans.readthedocs.io/en"
+                                 + "/latest/#googletrans-languages")

+ 2 - 1
wbb/modules/rice.py

@@ -62,7 +62,8 @@ async def callback_query_forward_rice(_, callback_query):
                   f"<b>Approver</b>: {approver.mention()}\n"
                   f"<b>Approver</b>: {approver.mention()}\n"
                   f"<b>Forwarded</b>: "
                   f"<b>Forwarded</b>: "
                   f"<a href=\"{link}\">Rice Gallery</a>")
                   f"<a href=\"{link}\">Rice Gallery</a>")
-    await m_rice.reply_text(reply_text, disable_web_page_preview=True)
+    await m_rice.reply_text(reply_text, parse_mode="html",
+                            disable_web_page_preview=True)
 
 
 
 
 @app.on_callback_query(filters.regex("ignore"))
 @app.on_callback_query(filters.regex("ignore"))

+ 48 - 0
wbb/modules/succ.py

@@ -0,0 +1,48 @@
+import random
+from pyrogram.types import Message
+from pyrogram import filters
+from wbb import app
+from wbb.utils import cust_filter
+
+__MODULE__ = "Succ"
+__HELP__ = "/succ - Sends Succ Image For A Given Argument"
+
+hack = ['https://i.ibb.co/YLLhCtt/i.png', 'https://i.ibb.co/DMzyLMZ/e.jpg',
+        'https://i.ibb.co/sqngHGt/d.jpg', 'https://i.ibb.co/b1Y1rGf/a.jpg']
+
+kemeest = "'https://i.ibb.co/bB4pqNN/i.jpg'"
+educ = "'https://i.ibb.co/LCB3yTX/q.jpg'"
+health = "'https://i.ibb.co/TKHxkH4/m.jpg'"
+nhealth = "'https://i.ibb.co/dBVBzJY/p.jpg'"
+feminism = "'https://i.ibb.co/PNhPJR1/o.jpg'"
+security = "'https://i.ibb.co/ctf3MGM/c.jpg'"
+
+
+def suck(text):
+    socc = {'komidi': 'message.reply_photo("https://i.ibb.co/mRL3Nnf/j.jpg")',
+            'kemist': f'message.reply_photo({kemeest})',
+            'ejucation': f'message.reply_photo({educ})',
+            'helth': f'message.reply_photo({health})',
+            'nothelth': f'message.reply_photo({nhealth})',
+            'femnnism': f'message.reply_photo({feminism})',
+            'tehc': 'message.reply_photo("https://i.ibb.co/gdSvHSr/n.jpg")',
+            'stonks': 'message.reply_photo("https://i.ibb.co/TtZ144x/h.png")',
+            'sekuriti': 'message.reply_photo({security})',
+            'phijiks': 'message.reply_photo("https://i.ibb.co/Zz4wBnc/g.png")',
+            'welth': 'message.reply_photo("https://i.ibb.co/JxFm4pW/k.jpg")',
+            'smrt': 'message.reply_photo("https://i.ibb.co/7bVkyC7/l.jpg")',
+            'hacc': 'message.reply_photo(random.choice(hack))'}
+    return socc.get(text)
+
+
+@app.on_message(cust_filter.command(commands=("succ")) & ~filters.edited)
+def succ(_, message: Message):
+    result = suck(message.text.replace('/succ ', ''))
+    print(result)
+    if result is None:
+        message.reply_text('''"/succ" Needs And Argument
+Args - `komidi, kemist, ejucation, helth, nothelth,
+femnnism, tehc, hacc, stonks, sekuriti,
+phijiks, welth, smrt`''')
+    print(random)
+    exec(result)

+ 29 - 2
wbb/modules/sudoers.py

@@ -1,12 +1,14 @@
 import os
 import os
 import re
 import re
+import requests
 import time
 import time
+import wget
 from pyrogram import filters, types
 from pyrogram import filters, types
 from pyrogram.types import Message
 from pyrogram.types import Message
 import speedtest
 import speedtest
 import psutil
 import psutil
 from wbb.utils import cust_filter, nekobin, formatter
 from wbb.utils import cust_filter, nekobin, formatter
-from wbb import app, OWNER_ID, SUDO_USER_ID, bot_start_time, NEOFETCH
+from wbb import app, OWNER_ID, SUDO_USER_ID, bot_start_time, NEOFETCH, JSMAPI
 
 
 __MODULE__ = "Sudoers"
 __MODULE__ = "Sudoers"
 __HELP__ = '''/log - To Get Logs From Last Run.
 __HELP__ = '''/log - To Get Logs From Last Run.
@@ -92,7 +94,7 @@ Latency  - {round((i["latency"]))} ms
 # Stats Module
 # Stats Module
 
 
 
 
-@ app.on_message(
+@app.on_message(
     filters.user(SUDOERS) & cust_filter.command(commands=("stats"))
     filters.user(SUDOERS) & cust_filter.command(commands=("stats"))
 )
 )
 async def get_stats(_, message: Message):
 async def get_stats(_, message: Message):
@@ -124,3 +126,28 @@ async def get_stats(_, message: Message):
 {neofetch}
 {neofetch}
 ```''')
 ```''')
     await message.reply_text(stats)
     await message.reply_text(stats)
+
+# Song
+
+
+@app.on_message(
+    filters.user(SUDOERS) & cust_filter.command(commands=("song"))
+)
+async def song(_, message: Message):
+    text = message.text.replace("/song ", "")
+    query = text.replace(" ", "%20")
+    r = requests.get(f"{JSMAPI}{query}")
+
+    i = 0
+    while i < 2:
+        sname = r.json()[i]['song']
+        slink = r.json()[i]['media_url']
+        ssingers = r.json()[i]['singers']
+        sduration = r.json()[i]['duration']
+        file = wget.download(slink)
+        ffile = file.replace("mp4", "m4a")
+        os.rename(file, ffile)
+        await message.reply_audio(audio=ffile, title=sname,
+                                  performer=ssingers, duration=int(sduration))
+        i += 1
+        os.remove(ffile)