From 648458fae641467c71786b70f9c6a177162631cf Mon Sep 17 00:00:00 2001 From: "sandeep.n" Date: Tue, 27 Aug 2024 18:55:38 +0530 Subject: [PATCH] revert DB_URI changes --- docker-compose.yml | 9 +- requirements.txt | 2 +- sample_config.py | 2 +- userbot/plugins/google.py | 220 +++++++++++++++++++------------------- 4 files changed, 118 insertions(+), 115 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c42829ac79..bc23502efe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ version: '3.3' services: - app: + app: container_name: cat build: context: . @@ -18,11 +18,11 @@ services: command: python3 -m userbot restart: on-failure environment: - - DB_URI=postgresql://postgres:postgres@db/catuserbot + - DATABASE_URL=postgresql://postgres:postgres@db/catuserbot depends_on: - db - db: + db: image: postgres restart: always environment: @@ -34,3 +34,6 @@ services: volumes: db: driver: local + botdata: + driver: local + diff --git a/requirements.txt b/requirements.txt index 649d180c48..5cedddca8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ cinemagoer cloudscraper colour cowpy -c-telethon emoji==1.7.0 fonttools geopy @@ -59,6 +58,7 @@ wand wget git+https://github.com/Jisan09/search-engine-parser +git+https://github.com/Jisan09/Telethon@test git+https://github.com/goldsmith/Wikipedia git+https://github.com/sandy1709/py-googletrans git+https://github.com/alexmercerind/youtube-search-python diff --git a/sample_config.py b/sample_config.py index 9562e14677..d0c7b0e53a 100644 --- a/sample_config.py +++ b/sample_config.py @@ -18,7 +18,7 @@ class Config(object): APP_ID = int(os.environ.get("APP_ID", 6)) API_HASH = os.environ.get("API_HASH") or None # Datbase url heroku sets it automatically else get this from elephantsql - DB_URI = os.environ.get("DB_URI", None) + DB_URI = os.environ.get("DATABASE_URL", None) # Get this value by running python3 stringsetup.py or https://repl.it/@sandeep1709/generatestringsession STRING_SESSION = os.environ.get("STRING_SESSION", None) # Telegram BOT Token and bot username from @BotFather diff --git a/userbot/plugins/google.py b/userbot/plugins/google.py index f7dfd548e0..d836cf8ecb 100644 --- a/userbot/plugins/google.py +++ b/userbot/plugins/google.py @@ -1,4 +1,4 @@ -""" Reverse search image and Google search """ +"""Reverse search image and Google search""" # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# CatUserBot #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # Copyright (C) 2020-2023 by TgCatUB@Github. @@ -27,6 +27,115 @@ plugin_category = "tools" +@catub.cat_cmd( + pattern="gs ([\s\S]*)", + command=("gs", plugin_category), + info={ + "header": "Google search command.", + "flags": { + "-l": "for number of search results.", + "-p": "for choosing which page results should be showed.", + }, + "usage": [ + "{tr}gs ", + "{tr}gs ", + ], + "examples": [ + "{tr}gs catuserbot", + "{tr}gs -l6 catuserbot", + "{tr}gs -p2 catuserbot", + "{tr}gs -p2 -l7 catuserbot", + ], + }, +) +async def gsearch(q_event): + "Google search command." + catevent = await edit_or_reply(q_event, "`searching........`") + match = q_event.pattern_match.group(1) + page = re.findall(r"-p\d+", match) + lim = re.findall(r"-l\d+", match) + try: + page = page[0] + page = page.replace("-p", "") + match = match.replace(f"-p{page}", "") + except IndexError: + page = 1 + try: + lim = lim[0] + lim = lim.replace("-l", "") + match = match.replace(f"-l{lim}", "") + lim = int(lim) + if lim <= 0: + lim = 5 + except IndexError: + lim = 5 + # smatch = urllib.parse.quote_plus(match) + smatch = match.replace(" ", "+") + search_args = str(smatch), page + gsearch = GoogleSearch() + bsearch = BingSearch() + ysearch = YahooSearch() + try: + gresults = await gsearch.async_search(*search_args) + except NoResultsOrTrafficError: + try: + gresults = await bsearch.async_search(*search_args) + except NoResultsOrTrafficError: + try: + gresults = await ysearch.async_search(*search_args) + except Exception as e: + return await edit_delete(catevent, f"**Error:**\n`{e}`", time=10) + msg = "" + for i in range(lim): + if i > len(gresults["links"]): + break + try: + title = gresults["titles"][i] + link = gresults["links"][i] + desc = gresults["descriptions"][i] + msg += f"👉[{title}]({link})\n`{desc}`\n\n" + except IndexError: + break + await edit_or_reply( + catevent, + "**Search Query:**\n`" + match + "`\n\n**Results:**\n" + msg, + link_preview=False, + aslink=True, + linktext=f"**The search results for the query **__{match}__ **are** :", + ) + if BOTLOG: + await q_event.client.send_message( + BOTLOG_CHATID, + f"Google Search query `{match}` was executed successfully", + ) + + +@catub.cat_cmd( + pattern="gis ([\s\S]*)", + command=("gis", plugin_category), + info={ + "header": "Google search in image format", + "usage": "{tr}gis ", + "examples": "{tr}gis cat", + }, +) +async def gis(event): + "To search in google and send result in picture." + + +@catub.cat_cmd( + pattern="grs$", + command=("grs", plugin_category), + info={ + "header": "Google reverse search command.", + "description": "Reverse search replied media in google and shows results.", + "usage": "{tr}grs", + }, +) +async def grs(event): + "Google Reverse Search" + + @catub.cat_cmd( pattern="(grs|reverse)(?:\s|$)([\s\S]*)", command=("reverse", plugin_category), @@ -145,112 +254,3 @@ async def google_search(event): results = await event.client.inline_query("@StickerizerBot", query) await results[0].click(event.chat_id, reply_to=reply_to_id, hide_via=True) await event.delete() - - -@catub.cat_cmd( - pattern="gs ([\s\S]*)", - command=("gs", plugin_category), - info={ - "header": "Google search command.", - "flags": { - "-l": "for number of search results.", - "-p": "for choosing which page results should be showed.", - }, - "usage": [ - "{tr}gs ", - "{tr}gs ", - ], - "examples": [ - "{tr}gs catuserbot", - "{tr}gs -l6 catuserbot", - "{tr}gs -p2 catuserbot", - "{tr}gs -p2 -l7 catuserbot", - ], - }, -) -async def gsearch(q_event): - "Google search command." - catevent = await edit_or_reply(q_event, "`searching........`") - match = q_event.pattern_match.group(1) - page = re.findall(r"-p\d+", match) - lim = re.findall(r"-l\d+", match) - try: - page = page[0] - page = page.replace("-p", "") - match = match.replace(f"-p{page}", "") - except IndexError: - page = 1 - try: - lim = lim[0] - lim = lim.replace("-l", "") - match = match.replace(f"-l{lim}", "") - lim = int(lim) - if lim <= 0: - lim = 5 - except IndexError: - lim = 5 - # smatch = urllib.parse.quote_plus(match) - smatch = match.replace(" ", "+") - search_args = str(smatch), page - gsearch = GoogleSearch() - bsearch = BingSearch() - ysearch = YahooSearch() - try: - gresults = await gsearch.async_search(*search_args) - except NoResultsOrTrafficError: - try: - gresults = await bsearch.async_search(*search_args) - except NoResultsOrTrafficError: - try: - gresults = await ysearch.async_search(*search_args) - except Exception as e: - return await edit_delete(catevent, f"**Error:**\n`{e}`", time=10) - msg = "" - for i in range(lim): - if i > len(gresults["links"]): - break - try: - title = gresults["titles"][i] - link = gresults["links"][i] - desc = gresults["descriptions"][i] - msg += f"👉[{title}]({link})\n`{desc}`\n\n" - except IndexError: - break - await edit_or_reply( - catevent, - "**Search Query:**\n`" + match + "`\n\n**Results:**\n" + msg, - link_preview=False, - aslink=True, - linktext=f"**The search results for the query **__{match}__ **are** :", - ) - if BOTLOG: - await q_event.client.send_message( - BOTLOG_CHATID, - f"Google Search query `{match}` was executed successfully", - ) - - -@catub.cat_cmd( - pattern="gis ([\s\S]*)", - command=("gis", plugin_category), - info={ - "header": "Google search in image format", - "usage": "{tr}gis ", - "examples": "{tr}gis cat", - }, -) -async def gis(event): - "To search in google and send result in picture." - - -@catub.cat_cmd( - pattern="grs$", - command=("grs", plugin_category), - info={ - "header": "Google reverse search command.", - "description": "Reverse search replied media in google and shows results.", - "usage": "{tr}grs", - }, -) -async def grs(event): - "Google Reverse Search"