Procházet zdrojové kódy

Added Some Image commands and fixed many things (#15)

* Disable modules which has filename ends with _DISABLED.py

Disable rice module for now

* Added Some Image commands and fixed many things

* Update rice_DISABLED.py

* fixed /rice filter

* Update README.md

* Update README.md

* quikphix

* changed id to username

* quikphix

* smol phix

Co-authored-by: Dash Eclipse <dashezup@disroot.org>
Akshay Rajput před 5 roky
rodič
revize
f2746b4e45

+ 2 - 19
README.md

@@ -14,24 +14,7 @@ Just Another Telegram Bot Written In Python Using Pyrogram.
 1. `git clone https://github.com/thehamkercat/WilliamButcherBot`, to download the source code.
 2. `cd wbb`, to enter the directory.
 3. `pip3 install -r requirements.txt`, to install the requirements.
-4. `cp sample_config.ini config.ini` It should look like the code below:<br>
+4. `cp sample_config.ini config.ini`
 
-```
-   [pyrogram]
-   api_id = 12345
-   api_hash = 0123456789abcdef0123456789abcdef
-   bot_token = 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
-   
-   [admin]
-   owner_id = 1243703097
-   sudo_user_id = 79813487
-   neofetch = True
-
-   [prefix]
-   prefixes = /
-
-   [mods]
-   load_modules =
-   noload_modules =
-   ```
+6. Edit `config.ini` with your own values
 5. Run with `python3 -m wbb`

+ 1 - 0
sample_config.ini

@@ -7,6 +7,7 @@ api_hash = r7s8c3b22d4869bd6ca7cc756cb9
 owner_id = 1243703097
 sudo_user_id = 79813487
 neofetch = True
+alpha_coders_wall_api_key = ca45r8c444s55g7t5s3a4esd33hs6t
 
 [prefix]
 prefixes = /

+ 1 - 0
wbb/__init__.py

@@ -34,6 +34,7 @@ config.read("config.ini")
 OWNER_ID = int(config.get("admin", "owner_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"))
 Command = config.get("prefix", "prefixes").split()
 MOD_LOAD = config.get("mods", "load_modules").split()
 MOD_NOLOAD = config.get("mods", "noload_modules").split()

+ 1 - 0
wbb/modules/__init__.py

@@ -16,6 +16,7 @@ def __list_all_modules():
         and f.endswith(".py")
         and not f.endswith("__init__.py")
         and not f.endswith("__main__.py")
+        and not f.endswith("_DISABLED.py")
     ]
 
     if MOD_LOAD or MOD_NOLOAD:

+ 61 - 0
wbb/modules/images.py

@@ -0,0 +1,61 @@
+from wbb.utils import cust_filter
+from wbb import app, WALL_API_KEY
+import urllib.request
+import json
+from random import randint
+import requests as r
+
+__MODULE__ = "Images"
+__HELP__ = "/cat - Get Cute Cats Images\n" + \
+           "/dog - Get Cute Dogs Images"
+
+
+@app.on_message(cust_filter.command(commands=("cat")))
+async def cat(client, message):
+    with urllib.request.urlopen(
+        "https://api.thecatapi.com/v1/images/search"
+    ) as url:
+        data = json.loads(url.read().decode())
+    cat_url = (data[0]['url'])
+    await message.reply_photo(cat_url)
+
+
+@app.on_message(cust_filter.command(commands=("dog")))
+async def dog(client, message):
+    with urllib.request.urlopen(
+        "https://api.thedogapi.com/v1/images/search"
+    ) as url:
+        data = json.loads(url.read().decode())
+    dog_url = (data[0]['url'])
+    await message.reply_photo(dog_url)
+
+
+@app.on_message(cust_filter.command(commands=("wall")))
+async def wall(client, message):
+    app.set_parse_mode("markdown")
+    m = await message.reply_text("Searching!")
+    try:
+        term = (message.text.split(None, 1)[1])
+    except IndexError:
+        await m.edit("`\"/wall\" needs a keyword argument`")
+
+    api = "https://wall.alphacoders.com/api2.0/get.php?auth=" + \
+        "{}&method=search&term={}".format(WALL_API_KEY, term)
+
+    json_rep = r.get(api).json()
+    if not json_rep.get("success"):
+        await m.edit("FTS! something unusual happened, " +
+                     "report to support @Thepirategang")
+    else:
+        wallpapers = json_rep.get("wallpapers")
+        if not wallpapers:
+            await m.edit(
+                "Found literally nothing!,You should work on your English.")
+            return
+        else:
+            index = randint(0, len(wallpapers) - 1)
+            wallpaper = wallpapers[index]
+            wallpaper = wallpaper.get("url_image")
+            wallpaper = wallpaper.replace("\\", "")
+            await message.reply_document(wallpaper)
+    await m.delete()

+ 7 - 1
wbb/modules/music.py

@@ -18,7 +18,13 @@ ydl_opts = {
 async def music(client, message):
     await message.reply_chat_action("typing")
     app.set_parse_mode("html")
-    link = (message.text.split(None, 1)[1])
+    try:
+        link = (message.text.split(None, 1)[1])
+    except IndexError:
+        await message.reply_text(
+            "<code>\"/music\" needs a keyword argument</code>"
+            )
+
     with youtube_dl.YoutubeDL(ydl_opts) as ydl:
         info_dict = ydl.extract_info(link, download=False)
         audio_file = ydl.prepare_filename(info_dict)

+ 4 - 4
wbb/modules/paste.py

@@ -29,7 +29,7 @@ async def paste(client, message):
             await m.edit(final_link, disable_web_page_preview=True)
     elif bool(message.reply_to_message) is False:
         await message.reply_text(
-            '''Reply To A Message With /paste, Just Hitting /paste
-Won't Do Anything Other Than Proving Everyone That
-You Are Obsessed To 'BlueTextMustClickofobia'.'''
-        )
+            "```Reply To A Message With /paste, Just Hitting /paste " +
+            "Won't Do Anything Other Than Proving Everyone That " +
+            "You Are Obsessed To 'BlueTextMustClickofobia'```"
+            )

+ 6 - 3
wbb/modules/rice.py → wbb/modules/rice_DISABLED.py

@@ -1,16 +1,19 @@
 from wbb import app
 from wbb.utils import cust_filter
 from pyrogram import filters
+
+
 __MODULE__ = "Rice"
-__HELP__ = "/rice - To Forward Your Linux Rice To DE_WM's Rice Gallery"
+__HELP__ = "/rice - To Forward Your Linux Rice To DE_WM's" \
+            "Rice Gallery only works in [DE_WM](t.me/de_wm)"
 
 
-@app.on_message(filters.chat('de_wm') & cust_filter.command(commands=("rice")))
+@app.on_message(filters.chat('DE_WM') & cust_filter.command(commands=("rice")))
 async def rice(client, message):
     app.set_parse_mode("markdown")
     m = await message.reply_text("```Forwarding!```")
     id = message.reply_to_message.from_user.id
-    await message.reply_to_message.forward(-1001490017589)
+    await message.reply_to_message.forward('RiceGallery')
     await m.edit(
         f"[Your](tg://user?id={id}) Rice Forwared"
         " To [Rice Gallery](https://t.me/RiceGallery)",