├── Procfile ├── requirements.txt ├── README.md ├── .github └── workflows │ └── python-app.yml ├── app.json └── padho.py /Procfile: -------------------------------------------------------------------------------- 1 | NoobiezBots: python padho.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-decouple 2 | telethon 3 | requests 4 | redis 5 | google-api-python-client 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Padho Telegram Bot 2 | 3 | Just a bot to find answers to your queries inline. 4 | 5 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/ProgrammingError/padhotgbot) 6 | 7 | Please Join [BotzHub](https://t.me/BotzHub) 🥺👉👈 8 | -------------------------------------------------------------------------------- /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | name: pyLint 2 | 3 | on: push 4 | 5 | jobs: 6 | PEP8: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | 11 | - name: Setup Python 12 | uses: actions/setup-python@v1 13 | with: 14 | python-version: 3.9 15 | 16 | - name: Install black 17 | run: | 18 | pip install black isort autoflake 19 | - name: lint with isort and black 20 | run: | 21 | black . 22 | isort . 23 | autoflake --in-place --recursive --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports . 24 | # commit changes 25 | - uses: stefanzweifel/git-auto-commit-action@v4 26 | with: 27 | commit_message: 'pyLint: auto-fixes' 28 | commit_options: '--no-verify' 29 | repository: . 30 | commit_user_name: ProgrammingError 31 | commit_user_email: error@notavailable.live 32 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Padho TG Bot", 3 | "description": "Simple bot to scrap answers from toppr and brainly in Telethon.", 4 | "logo": "", 5 | "keywords": [ 6 | "telegram", 7 | "telethon", 8 | "telegram-bot", 9 | "noobiezbots" 10 | ], 11 | "repository": "https://github.com/ProgrammingError/padhotgbot", 12 | "website": "notavailable.live", 13 | "success_url": "https://t.me/NoobiezBots", 14 | "env": { 15 | "API_HASH": { 16 | "description": "You API HASH from my.telegram.org", 17 | "value": "" 18 | }, 19 | "APP_ID": { 20 | "description": "You API ID from my.telegram.org", 21 | "value": "" 22 | }, 23 | "BOT_TOKEN": { 24 | "description": "Bot token, get it from @BotFather.", 25 | "value": "" 26 | } 27 | }, 28 | "buildpacks": [ 29 | { 30 | "url": "heroku/python" 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /padho.py: -------------------------------------------------------------------------------- 1 | # Idea By @ProgrammingError 2 | # Made By @ProgrammingError 3 | # Thanks To Google😂😂😂 4 | 5 | import io 6 | import logging 7 | import random 8 | import sys 9 | import traceback 10 | 11 | import redis 12 | import requests 13 | from decouple import config 14 | from telethon import Button, TelegramClient, events 15 | 16 | logging.basicConfig( 17 | format="[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s", level=logging.WARNING 18 | ) 19 | 20 | APP_ID = config("APP_ID", default=None, cast=int) 21 | API_HASH = config("API_HASH", default=None) 22 | BOT_TOKEN = config("BOT_TOKEN", default=None) 23 | REDIS_URI = config("REDIS_URI", default=None) 24 | REDIS_PASS = config("REDIS_PASS", default=None) 25 | SUDOS = config("SUDOS", default=None) 26 | APIS = config("APIS", default=None) 27 | 28 | tgbot = TelegramClient("Botzhub", APP_ID, API_HASH).start(bot_token=BOT_TOKEN) 29 | 30 | try: 31 | redis_info = REDIS_URI.split(":") 32 | ud = redis.StrictRedis( 33 | host=redis_info[0], 34 | port=redis_info[1], 35 | password=REDIS_PASS, 36 | charset="utf-8", 37 | decode_responses=True, 38 | ) 39 | except BaseException: 40 | pass 41 | 42 | apis = APIS.split(" ") 43 | API_KEY = random.choice(apis) 44 | 45 | SEARCH_ENGINE_ID = "d99e58572df67b77a" 46 | 47 | print("Successfully deployed!") 48 | print(f"Your Bot is now running! 🥳🥳🥳") 49 | print("Enjoy! Do join @BotzHub 🥺👉👈") 50 | 51 | 52 | @tgbot.on( 53 | events.NewMessage(incoming=True, pattern="/start", func=lambda e: e.is_private) 54 | ) 55 | async def start(event): 56 | await event.reply( 57 | "Hello!\nI am a bot to search answers for your questions.\nUse me Inline\n\nPlease Join @BotzHub 🥺👉👈", 58 | buttons=[[Button.switch_inline("Search Answer", query="", same_peer=True)]], 59 | ) 60 | 61 | 62 | @tgbot.on( 63 | events.NewMessage(incoming=True, pattern="/stats", func=lambda e: e.is_private) 64 | ) 65 | async def start(event): 66 | x = ud.get("USERS") 67 | y = x.split(" ") 68 | count = 0 69 | for xx in y: 70 | count += 1 71 | sudo = SUDOS.split(" ") 72 | if str(event.sender_id) in sudo: 73 | await event.reply(f"The Total Number of users is {count}") 74 | 75 | 76 | @tgbot.on( 77 | events.NewMessage(incoming=True, pattern="/destroydb", func=lambda e: e.is_private) 78 | ) 79 | async def destroy(event): 80 | sudo = SUDOS.split(" ") 81 | if str(event.sender_id) in sudo: 82 | try: 83 | ud.delete("USERS") 84 | await event.reply("Destroyed DataBase successfully!") 85 | except: 86 | await event.reply(traceback.print_exc(file=sys.stdout)) 87 | 88 | 89 | @tgbot.on( 90 | events.NewMessage(incoming=True, pattern="/users", func=lambda e: e.is_private) 91 | ) 92 | async def users(e): 93 | x = ud.get("USERS") 94 | y = x.split(" ") 95 | users_list = "List Of Total Users In Bot. \n\n" 96 | for xx in y: 97 | try: 98 | fname = (await tgbot.get_entity(int(xx))).first_name 99 | except ValueError: 100 | fname = "User" 101 | name = f"[{fname}](tg://user?id={xx})" 102 | users_list += f"=> Name: {name}| ID: {xx}\n" 103 | sudo = SUDOS.split(" ") 104 | if str(e.sender_id) in sudo: 105 | if len(users_list) < 4096: 106 | await e.reply(users_list) 107 | else: 108 | with io.BytesIO(str.encode(users_list)) as tedt_file: 109 | tedt_file.name = "userlist.txt" 110 | await tgbot.send_file( 111 | e.chat_id, 112 | tedt_file, 113 | force_document=True, 114 | caption="Total Users In Your Bot.", 115 | allow_cache=False, 116 | ) 117 | 118 | 119 | @tgbot.on(events.NewMessage(incoming=True)) 120 | async def add(event): 121 | x = ud.get("USERS") 122 | if x: 123 | y = x.split(" ") 124 | for xx in y: 125 | if str(event.sender_id) not in y: 126 | ud.set("USERS", x + " " + str(event.sender_id)) 127 | else: 128 | pass 129 | else: 130 | ud.set("USERS", str(SUDOS)) 131 | 132 | 133 | @tgbot.on(events.InlineQuery(pattern=r"(.*)")) 134 | async def inline_id_handler(event: events.InlineQuery.Event): 135 | query = event.text 136 | try: 137 | x = ud.get("USERS") 138 | if x: 139 | y = x.split(" ") 140 | for xx in y: 141 | if str(event.query.user_id) not in y: 142 | ud.set("USERS", x + " " + str(event.query.user_id)) 143 | else: 144 | pass 145 | else: 146 | ud.set("USERS", str(SUDOS)) 147 | 148 | padhai = [] 149 | 150 | if query: 151 | programmingerror = f"https://customsearch.googleapis.com/customsearch/v1?q={query}&cx={SEARCH_ENGINE_ID}&start=1&key={API_KEY}" 152 | shivambro = requests.get(programmingerror).json() 153 | search_items = shivambro.get("items") 154 | for search_item in search_items: 155 | title = search_item.get("title") 156 | # Idea By @ProgrammingError 157 | # Made By @ProgrammingError 158 | # Thanks To Google😂😂😂# https://www.googleapis.com/customsearch/v1?key=AIzaSyAyDBsY3WRtB5YPC6aB_w8JAy6ZdXNc6FU&cx=d99e58572df67b77a&q=vector 159 | danish_00 = search_item.get("link") 160 | atul_xd = search_item.get("snippet") 161 | # Idea By @ProgrammingError 162 | # Made By @ProgrammingError 163 | # Thanks To Google😂😂😂 164 | toppers = f"{title}\n\nAnswer in Short:\n\n{atul_xd}" 165 | padho = f"{title}" 166 | padhai.append( 167 | await event.builder.article( 168 | title=padho, 169 | description=f"{atul_xd}", # Idea By @ProgrammingError 170 | # Made By @ProgrammingError 171 | # Thanks To Google😂😂😂 172 | text=toppers, 173 | buttons=[ 174 | [Button.url("Answer", f"{danish_00}")], 175 | [ 176 | Button.switch_inline( 177 | "Search Again", query=" ", same_peer=True 178 | ) 179 | ], 180 | ], 181 | ) 182 | ) 183 | await event.answer(padhai) 184 | else: 185 | padhai.append( 186 | await event.builder.article( 187 | title="Give Something to search.", 188 | description="Please write some queries to Search Answer.", 189 | text="Please write some queries to Search Answer.", 190 | buttons=[ 191 | [ 192 | Button.switch_inline( 193 | "Search Again", query=" ", same_peer=True 194 | ) 195 | ], 196 | ], 197 | ) 198 | ) 199 | await event.answer(padhai) 200 | except: 201 | traceback.print_exc(file.sys.stdout) 202 | 203 | 204 | try: 205 | tgbot.run_until_disconnected() 206 | except: 207 | traceback.print_exc(file=sys.stdout) 208 | --------------------------------------------------------------------------------