Skip to content

Commit

Permalink
fix: Typo & assign position
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisan09 committed May 20, 2023
1 parent 80f2d30 commit f2a1b92
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 116 deletions.
2 changes: 1 addition & 1 deletion userbot/core/inlinebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ async def inline_popup_info(event, builder):
),
builder.article(
title="Troll",
description="Send troll message to your friends.\nSyntax: toll @usename",
description="Send troll message to your friends.\nSyntax: troll @usename",
text="__Send **troll message** which everyone can see except the reciever.\n\nFor multiple users give space to username & use **|** to seperate text.__",
thumb=get_thumb("troll.png"),
buttons=[
Expand Down
4 changes: 2 additions & 2 deletions userbot/helpers/functions/ialivetext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from ...Config import Config
from .utils import get_readable_time

Heroku = heroku3.from_key(Config.HEROKU_API_KEY)
heroku_api = "https://api.heroku.com"

# UniBorg Telegram UseRBot
# Copyright (C) 2020 @UniBorg
Expand Down Expand Up @@ -44,6 +42,8 @@ def check_data_base_heal_th():
async def catalive(StartTime):
_, check_sgnirts = check_data_base_heal_th()
sudo = "Enabled" if Config.SUDO_USERS else "Disabled"
Heroku = heroku3.from_key(Config.HEROKU_API_KEY)
heroku_api = "https://api.heroku.com"
uptime = await get_readable_time((time.time() - StartTime))
try:
useragent = (
Expand Down
224 changes: 111 additions & 113 deletions userbot/plugins/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import re
from datetime import datetime
import contextlib

from search_engine_parser import BingSearch, GoogleSearch, YahooSearch
from search_engine_parser.core.exceptions import NoResultsOrTrafficError
Expand All @@ -26,115 +27,6 @@
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 <flags> <query>",
"{tr}gs <query>",
],
"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 <query>",
"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),
Expand Down Expand Up @@ -189,7 +81,7 @@ async def reverse(event):
)
# scamming telethon to send media as album
# gif file can't album so doing single
try:
with contextlib.suppress(Exception):
image = await catub.send_file(BOTLOG_CHATID, url, silent=True)
if url.endswith(".gif"):
await unsavegif(event, image)
Expand All @@ -202,9 +94,6 @@ async def reverse(event):
await edit_or_reply(catevent, f"**📥 Downloaded : {checker}/{limit}**")
if checker >= int(limit):
break
except Exception:
pass

end = datetime.now()
ms = (end - start).seconds
caption = f'<b>➥ Google Reverse Search:</b> <code>{data["title"]}</code>\n<b>➥ View Source: <a href="{data["google"]}">Google Image</a></b>\n<b>➥ View Similar: <a href="{data["lens"]}">Google Lens</a> </b>(Desktop)\n<b>➥ Time Taken:</b> <code>{ms} seconds</code>'
Expand Down Expand Up @@ -256,3 +145,112 @@ 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 <flags> <query>",
"{tr}gs <query>",
],
"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 <query>",
"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"

0 comments on commit f2a1b92

Please sign in to comment.