add Stan, bdmtss, quote, layout mapping, upd README.md
This commit is contained in:
@@ -27,3 +27,21 @@ Bot is easily understandable reading in-code comments of the handler functions,
|
|||||||
Continuous log reading on Linux:
|
Continuous log reading on Linux:
|
||||||
|
|
||||||
```# journalctl --unit=lutz.service -f --no-pager```
|
```# journalctl --unit=lutz.service -f --no-pager```
|
||||||
|
|
||||||
|
|
||||||
|
### Hot to interact with Lutz bot?
|
||||||
|
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
|
||||||
|
* 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 (
|
||||||
|
* lutz - Send Lutz book
|
||||||
+2
-1
@@ -2,7 +2,7 @@ from importlib import reload
|
|||||||
|
|
||||||
from . import config
|
from . import config
|
||||||
from . import me
|
from . import me
|
||||||
from . import reminder
|
from . import stan
|
||||||
from . import report
|
from . import report
|
||||||
from . import bot as bot_mod
|
from . import bot as bot_mod
|
||||||
|
|
||||||
@@ -12,3 +12,4 @@ def reload_modules():
|
|||||||
reload(config)
|
reload(config)
|
||||||
reload(me)
|
reload(me)
|
||||||
reload(bot_mod)
|
reload(bot_mod)
|
||||||
|
reload(stan)
|
||||||
|
|||||||
+42
-11
@@ -5,10 +5,12 @@ from telebot import types
|
|||||||
import logging
|
import logging
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
|
from . import stan
|
||||||
from . import reminder
|
from . import reminder
|
||||||
from . import admin
|
from . import admin
|
||||||
from . import report
|
from . import report
|
||||||
from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU, WHITEUN, WHITEIDS
|
from .config import bot, URL_RX, ALLOWED_WORDS, ADMIN_ID, TOKEN, PYTHONCHATRU, WHITEUN, WHITEIDS, RUS_ENG_TABLE, \
|
||||||
|
ENG_RUS_TABLE, RUS
|
||||||
from .me import get_me
|
from .me import get_me
|
||||||
|
|
||||||
# https://core.telegram.org/bots/api Telegram Bot API
|
# https://core.telegram.org/bots/api Telegram Bot API
|
||||||
@@ -141,10 +143,21 @@ def send_lutz_command(message):
|
|||||||
bot.send_document(
|
bot.send_document(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
document='BQACAgQAAxkBAAPBYsWJG9Ml0fPrnbU9UyzTQiQSuHkAAjkDAAIstCxSkuRbXAlcqeQpBA',
|
document='BQACAgQAAxkBAAPBYsWJG9Ml0fPrnbU9UyzTQiQSuHkAAjkDAAIstCxSkuRbXAlcqeQpBA',
|
||||||
caption="""<i><b>Learning Python</b>, 5th Edition</i>
|
caption="вот, не позорься")
|
||||||
├ by Mark Lutz
|
|
||||||
└ Released June 2013""",
|
|
||||||
parse_mode='HTML')
|
@bot.message_handler(commands=['bdmtss'])
|
||||||
|
def send_bdmtss_audio(message):
|
||||||
|
bot.send_audio(message.chat.id, 'CQACAgIAAxkBAAIJT2Oej0ir56sDp5v2lbUsT75rxmKVAAKAJwACOo7xSEuuBINnWxEKLAQ')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['tr'])
|
||||||
|
def translate_layout(message):
|
||||||
|
if message.reply_to_message and message.reply_to_message.text:
|
||||||
|
if message.reply_to_message.text[0] in RUS:
|
||||||
|
bot.send_message(message.chat.id, message.reply_to_message.text.translate(RUS_ENG_TABLE))
|
||||||
|
else:
|
||||||
|
bot.send_message(message.chat.id, message.reply_to_message.text.translate(ENG_RUS_TABLE))
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['lib', 'library', 'book', 'books'])
|
@bot.message_handler(commands=['lib', 'library', 'book', 'books'])
|
||||||
@@ -210,6 +223,20 @@ def send_stats(message):
|
|||||||
parse_mode='HTML', disable_web_page_preview=True)
|
parse_mode='HTML', disable_web_page_preview=True)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['add'])
|
||||||
|
def add_stan_quote(message):
|
||||||
|
if message.reply_to_message and message.reply_to_message.text:
|
||||||
|
with open('Stan.txt', 'a', encoding='utf8') as stan_quotes:
|
||||||
|
stan_quotes.write('\n' + message.reply_to_message.text)
|
||||||
|
bot.send_message(message.chat.id, f'Добавил: {message.reply_to_message.text}',
|
||||||
|
parse_mode='HTML', disable_web_page_preview=True)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['quote'])
|
||||||
|
def stan_speak(message):
|
||||||
|
bot.send_message(message.chat.id, stan.speak(0))
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['reset_stats'])
|
@bot.message_handler(commands=['reset_stats'])
|
||||||
def send_stats(message):
|
def send_stats(message):
|
||||||
report.reset_report_stats()
|
report.reset_report_stats()
|
||||||
@@ -243,11 +270,6 @@ def admin_panel(message: types.Message):
|
|||||||
logging.warning(f'[UNBAN (M)] {unban_id}')
|
logging.warning(f'[UNBAN (M)] {unban_id}')
|
||||||
|
|
||||||
|
|
||||||
def check_chat(message: types.Message):
|
|
||||||
if message.chat.id == PYTHONCHATRU:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['tsya'])
|
@bot.message_handler(commands=['tsya'])
|
||||||
def send_tsya_link(message: types.Message):
|
def send_tsya_link(message: types.Message):
|
||||||
""" тся/ться """
|
""" тся/ться """
|
||||||
@@ -344,7 +366,12 @@ def check_unwanted_list(type_message: types.Message) -> bool:
|
|||||||
@bot.message_handler(func=check_unwanted_list)
|
@bot.message_handler(func=check_unwanted_list)
|
||||||
def unwanted_mentions(message: types.Message):
|
def unwanted_mentions(message: types.Message):
|
||||||
""" Reply to unwanted mentions. """
|
""" Reply to unwanted mentions. """
|
||||||
bot.reply_to(message, f'У нас таких не любят! 🥴', parse_mode='HTML')
|
bot.reply_to(message, f'у нас тут таких не любят')
|
||||||
|
|
||||||
|
|
||||||
|
def check_chat(message: types.Message):
|
||||||
|
if message.chat.id == PYTHONCHATRU:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(func=check_chat, content_types=['text', 'sticker', 'photo', 'animation', 'video',
|
@bot.message_handler(func=check_chat, content_types=['text', 'sticker', 'photo', 'animation', 'video',
|
||||||
@@ -358,6 +385,10 @@ def unwanted_mentions(message: types.Message):
|
|||||||
else:
|
else:
|
||||||
s['Messages'][message.from_user.id]['Count'] += 1
|
s['Messages'][message.from_user.id]['Count'] += 1
|
||||||
|
|
||||||
|
quote = stan.speak(20)
|
||||||
|
if quote:
|
||||||
|
bot.send_message(message.chat.id, quote)
|
||||||
|
|
||||||
|
|
||||||
@app.route(f"/bot{TOKEN}/", methods=['POST'])
|
@app.route(f"/bot{TOKEN}/", methods=['POST'])
|
||||||
def webhook():
|
def webhook():
|
||||||
|
|||||||
@@ -17,3 +17,9 @@ ALLOWED_WORDS = ['paste', 'github', 'google', 'nometa', 'python', 'django', 'fla
|
|||||||
|
|
||||||
WHITEUN = set(os.environ.get('whitelist', '<<<ERR_USRS').split(','))
|
WHITEUN = set(os.environ.get('whitelist', '<<<ERR_USRS').split(','))
|
||||||
WHITEIDS = {int(i) for i in os.environ.get('whiteids', '<<<ERR_IDS').split(',')}
|
WHITEIDS = {int(i) for i in os.environ.get('whiteids', '<<<ERR_IDS').split(',')}
|
||||||
|
|
||||||
|
|
||||||
|
RUS = """ёйцукенгшщзхъфывапролджэячсмитьбю.Ё!"№;%:?ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,"""
|
||||||
|
ENG = """`qwertyuiop[]asdfghjkl;'zxcvbnm,./~!@#$%^&QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?"""
|
||||||
|
RUS_ENG_TABLE = str.maketrans(RUS, ENG)
|
||||||
|
ENG_RUS_TABLE = str.maketrans(ENG, RUS)
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
""" Stan quote generator. """
|
||||||
|
import random
|
||||||
|
|
||||||
|
stan = [i.rstrip() for i in open('Stan.txt', 'r', encoding='utf8')]
|
||||||
|
|
||||||
|
|
||||||
|
def speak(chance):
|
||||||
|
chance = random.randint(0, chance)
|
||||||
|
if chance == 0:
|
||||||
|
return random.choice(stan)
|
||||||
Reference in New Issue
Block a user