add stackoverflow searcher

This commit is contained in:
Rykov7
2022-12-25 12:13:40 +03:00
parent 467b47c099
commit fbf3dba2ae
4 changed files with 29 additions and 19 deletions
+2 -2
View File
@@ -34,14 +34,14 @@ Bot can recieve commands and behave depending on chat situation.
Standard command pack for bot father includes:
* nobot - Telebot shouldn't be your first Python project
* noparse - Web-scraper shouldn't be your first Python project
* nogui - GUI app shouldn't be your first Python project
* nometa - Don't ask meta questions
* neprivet - Don't hello
* bdmtss - Rimshot
* quote - Random quote
* add - Add quote
* g - Google it [Request text can be any text from replied message or arguments if there's text after `\g example`]
* rules - Chat rules
* faq - FAQ
* books - Pythonista's Library (
* books - Pythonista's Library
* lutz - Send Lutz book
+9 -14
View File
@@ -1,7 +1,7 @@
import shelve
from datetime import datetime as dt
from flask import Flask, request, abort
from urllib import parse
import threading
from time import sleep
@@ -9,7 +9,7 @@ from . import stan
from . import reminder
from . import reloader
from . import report
from .me import get_me
from .helpers import get_me, search_it
from .filters import *
from .config import *
@@ -184,18 +184,13 @@ GUI приложение <i>не должно</i> быть твоим первы
@bot.message_handler(commands=['g'])
def google_it(message: types.Message):
""" Google it! """
search_engine = 'https://www.google.com/search?q='
if message.reply_to_message and message.reply_to_message.text:
if len(message.text.split()) == 1:
r = parse.quote_plus(message.reply_to_message.text)
else:
r = parse.quote_plus(' '.join(message.text.split()[1:]))
bot.reply_to(message.reply_to_message, f"{search_engine}{r}",
disable_web_page_preview=True)
else:
if len(message.text.split()) > 1:
r = parse.quote_plus(' '.join(message.text.split()[1:]))
bot.reply_to(message, f"{search_engine}{r}")
search_it('https://www.google.com/search?q=', message)
@bot.message_handler(commands=['s'])
def google_it(message: types.Message):
""" Stackoverflow it! """
search_it('https://stackoverflow.com/search?q=', message)
@bot.message_handler(func=check_nongrata)
+16 -1
View File
@@ -1,8 +1,9 @@
""" Send User's info. """
from urllib import parse
from .config import bot
def get_me(message):
# Fields tip: https://core.telegram.org/bots/api#user
msg = f"<b>Telegram ID:</b> <code>{message.from_user.id}</code>\n\
├ <b>Is bot:</b> {message.from_user.is_bot}\n\
├ <b>First name:</b> {message.from_user.first_name}\n"
@@ -18,3 +19,17 @@ def get_me(message):
msg += f" ├ <b>Chat ID:</b> {message.chat.id}"
return msg
def search_it(engine, message):
if message.reply_to_message and message.reply_to_message.text:
if len(message.text.split()) == 1:
r = parse.quote_plus(message.reply_to_message.text)
else:
r = parse.quote_plus(' '.join(message.text.split()[1:]))
bot.reply_to(message.reply_to_message, f"{engine}{r}",
disable_web_page_preview=True)
else:
if len(message.text.split()) > 1:
r = parse.quote_plus(' '.join(message.text.split()[1:]))
bot.reply_to(message, f"{engine}{r}")
+2 -2
View File
@@ -3,7 +3,7 @@ from importlib import reload
from . import bot
from . import filters
from . import config
from . import me
from . import helpers
from . import report
from . import stan
@@ -12,6 +12,6 @@ def reload_modules():
reload(bot)
reload(filters)
reload(config)
reload(me)
reload(helpers)
reload(report)
reload(stan)