This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
main.py
107 lines (87 loc) · 2.85 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Author: Fayas (https://github.com/FayasNoushad) (@FayasNoushad)
import os
import requests
from dotenv import load_dotenv
from requests.utils import requote_uri
from pyrogram import Client, filters
from pyrogram.types import *
load_dotenv()
API = "https://api.abirhasan.wtf/google?query="
Bot = Client(
"Google-Search-Bot",
bot_token=os.environ.get("BOT_TOKEN"),
api_id=int(os.environ.get("API_ID")),
api_hash=os.environ.get("API_HASH")
)
START_TEXT = """Hello {}
I am a google search bot. \
Send a text for google search result.
> `I can search from google. Use me in inline.`
Made by @FayasNoushad"""
JOIN_BUTTON = [
InlineKeyboardButton(
text='⚙ Join Updates Channel ⚙',
url='https://telegram.me/FayasNoushad'
)
]
@Bot.on_message(filters.private & filters.command(["start"]))
async def start(bot, update):
await update.reply_text(
text=START_TEXT.format(update.from_user.mention),
reply_markup=InlineKeyboardMarkup([JOIN_BUTTON]),
disable_web_page_preview=True,
quote=True
)
@Bot.on_message(filters.private & filters.text)
async def filter(bot, update):
await update.reply_text(
text="`Click the button below for searching...`",
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton(text="Search Here", switch_inline_query_current_chat=update.text)],
[InlineKeyboardButton(text="Search in another chat", switch_inline_query=update.text)]
]
),
disable_web_page_preview=True,
quote=True
)
@Bot.on_inline_query()
async def inline(bot, update):
results = google(update.query)
answers = []
for result in results:
answers.append(
InlineQueryResultArticle(
title=result["title"],
description=result["description"],
input_message_content=InputTextMessageContent(
message_text=result["text"],
disable_web_page_preview=True
),
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton(text="Link", url=result["link"])],
JOIN_BUTTON
]
)
)
)
await update.answer(answers)
def google(query):
r = requests.get(API + requote_uri(query))
informations = r.json()["results"][:50]
results = []
for info in informations:
text = f"**Title:** `{info['title']}`"
text += f"\n**Description:** `{info['description']}`"
text += f"\n\nMade by @FayasNoushad"
results.append(
{
"title": info['title'],
"description": info['description'],
"text": text,
"link": info['link']
}
)
return results
Bot.run()