-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpadho.py
212 lines (186 loc) · 6.79 KB
/
padho.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Idea By @ProgrammingError
# Made By @ProgrammingError
# Thanks To Google😂😂😂
import io
import logging
import random
import sys
import traceback
import redis
import requests
from decouple import config
from telethon import Button, TelegramClient, events
logging.basicConfig(
format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.WARNING
)
APP_ID = config("APP_ID", default=None, cast=int)
API_HASH = config("API_HASH", default=None)
BOT_TOKEN = config("BOT_TOKEN", default=None)
REDIS_URI = config("REDIS_URI", default=None)
REDIS_PASS = config("REDIS_PASS", default=None)
SUDOS = config("SUDOS", default=None)
APIS = config("APIS", default=None)
tgbot = TelegramClient("Botzhub", APP_ID, API_HASH).start(bot_token=BOT_TOKEN)
try:
redis_info = REDIS_URI.split(":")
ud = redis.StrictRedis(
host=redis_info[0],
port=redis_info[1],
password=REDIS_PASS,
charset="utf-8",
decode_responses=True,
)
except BaseException:
pass
apis = APIS.split(" ")
SEARCH_ENGINE_IDS = ["d99e58572df67b77a", "c1b78ad46b86b5213"]
print("Successfully deployed!")
print(f"Your Bot is now running! 🥳🥳🥳")
print("Enjoy! Do join @BotzHub 🥺👉👈")
@tgbot.on(
events.NewMessage(incoming=True, pattern="/start", func=lambda e: e.is_private)
)
async def start(event):
await event.reply(
"Hello!\nI am a bot to search answers for your questions.\nUse me Inline\n\nPlease Join @BotzHub 🥺👉👈",
buttons=[[Button.switch_inline("Search Answer", query="", same_peer=True)]],
)
@tgbot.on(
events.NewMessage(incoming=True, pattern="/stats", func=lambda e: e.is_private)
)
async def start(event):
x = ud.get("USERS")
y = x.split(" ")
count = 0
for xx in y:
count += 1
sudo = SUDOS.split(" ")
if str(event.sender_id) in sudo:
await event.reply(f"The Total Number of users is {count}")
@tgbot.on(
events.NewMessage(incoming=True, pattern="/destroydb", func=lambda e: e.is_private)
)
async def destroy(event):
sudo = SUDOS.split(" ")
if str(event.sender_id) in sudo:
try:
ud.delete("USERS")
await event.reply("Destroyed DataBase successfully!")
except:
await event.reply(traceback.print_exc(file=sys.stdout))
@tgbot.on(
events.NewMessage(incoming=True, pattern="/users", func=lambda e: e.is_private)
)
async def users(e):
x = ud.get("USERS")
y = x.split(" ")
users_list = "List Of Total Users In Bot. \n\n"
for xx in y:
try:
fname = (await tgbot.get_entity(int(xx))).first_name
except ValueError:
fname = "User"
name = f"[{fname}](tg://user?id={xx})"
users_list += f"=> Name: {name}| ID: {xx}\n"
sudo = SUDOS.split(" ")
if str(e.sender_id) in sudo:
if len(users_list) < 4096:
await e.reply(users_list)
else:
with io.BytesIO(str.encode(users_list)) as tedt_file:
tedt_file.name = "userlist.txt"
await tgbot.send_file(
e.chat_id,
tedt_file,
force_document=True,
caption="Total Users In Your Bot.",
allow_cache=False,
)
@tgbot.on(events.NewMessage(incoming=True))
async def add(event):
x = ud.get("USERS")
if x:
y = x.split(" ")
for xx in y:
if str(event.sender_id) not in y:
ud.set("USERS", x + " " + str(event.sender_id))
else:
pass
else:
ud.set("USERS", str(SUDOS))
@tgbot.on(events.InlineQuery(pattern=r"(.*)"))
async def inline_id_handler(event: events.InlineQuery.Event):
API_KEY = random.choice(apis)
SEARCH_ENGINE_ID = random.choice(SEARCH_ENGINE_IDS)
query = event.text
try:
x = ud.get("USERS")
if x:
y = x.split(" ")
for xx in y:
if str(event.query.user_id) not in y:
ud.set("USERS", x + " " + str(event.query.user_id))
else:
pass
else:
ud.set("USERS", str(SUDOS))
padhai = []
if query:
programmingerror = f"https://customsearch.googleapis.com/customsearch/v1?q={query}&cx={SEARCH_ENGINE_ID}&start=1&key={API_KEY}"
shivambro = requests.get(programmingerror).json()
search_items = shivambro.get("items")
if search_items is not None:
for search_item in search_items:
title = search_item.get("title")
# Idea By @ProgrammingError
# Made By @ProgrammingError
# Thanks To Google😂😂😂# https://www.googleapis.com/customsearch/v1?key=AIzaSyAyDBsY3WRtB5YPC6aB_w8JAy6ZdXNc6FU&cx=d99e58572df67b77a&q=vector
danish_00 = search_item.get("link")
atul_xd = search_item.get("snippet")
# Idea By @ProgrammingError
# Made By @ProgrammingError
# Thanks To Google😂😂😂
toppers = f"{title}\n\nAnswer in Short:\n\n{atul_xd}"
padho = f"{title}"
padhai.append(
await event.builder.article(
title=padho,
description=f"{atul_xd}", # Idea By @ProgrammingError
# Made By @ProgrammingError
# Thanks To Google😂😂😂
text=toppers,
buttons=[
[Button.url("Answer", f"{danish_00}")],
[
Button.switch_inline(
"Search Again", query=" ", same_peer=True
)
],
],
)
)
await event.answer(padhai)
else:
print(shivambro)
else:
padhai.append(
await event.builder.article(
title="Give Something to search.",
description="Please write some queries to Search Answer.",
text="Please write some queries to Search Answer.",
buttons=[
[
Button.switch_inline(
"Search Again", query=" ", same_peer=True
)
],
],
)
)
await event.answer(padhai)
except:
traceback.print_exc(file=sys.stdout)
try:
tgbot.run_until_disconnected()
except:
traceback.print_exc(file=sys.stdout)