add buttons

This commit is contained in:
Rykov7
2023-01-23 16:14:41 +03:00
parent bbb0cbc9b5
commit 74f78bcc58
3 changed files with 25 additions and 13 deletions
+18 -6
View File
@@ -71,26 +71,38 @@ def delete_message(message: types.Message):
@bot.message_handler(commands=['links']) @bot.message_handler(commands=['links'])
def send_links(message): def send_links(message):
send_or_reply(message, f"{RULES}\n{FAQ}\n{LIB}") markup = types.InlineKeyboardMarkup()
markup.add(RULES, FAQ, LIB, row_width=1)
answer = "Почитай на досуге"
if message.reply_to_message:
bot.reply_to(message.reply_to_message, answer, reply_maarkup=markup)
else:
bot.send_message(message.chat.id, answer, reply_markup=markup)
@bot.message_handler(commands=['rules', 'r']) @bot.message_handler(commands=['rules', 'rule', 'r'])
def send_rules(message): def send_rules(message):
markup = types.InlineKeyboardMarkup()
markup.add(RULES, row_width=1)
args = message.text.split() args = message.text.split()
if len(args) > 1 and args[-1].isdigit(): if len(args) > 1 and args[-1].isdigit():
send_or_reply(message, rules.get_rule(args[-1])) send_or_reply(message, f'<b>Правило {args[-1]}</b>\n<i>{rules.get_rule(args[-1])}</i>', reply_markup=markup)
else: else:
send_or_reply(message, f'{RULES}') send_or_reply(message, 'Почитай', reply_markup=markup)
@bot.message_handler(commands=['faq']) @bot.message_handler(commands=['faq'])
def send_faq(message): def send_faq(message):
send_or_reply(message, f'{FAQ}') markup = types.InlineKeyboardMarkup()
markup.add(FAQ, row_width=1)
send_or_reply(message, 'Почитай', reply_markup=markup)
@bot.message_handler(commands=['lib', 'library', 'books']) @bot.message_handler(commands=['lib', 'library', 'books'])
def send_lib(message): def send_lib(message):
send_or_reply(message, f'{LIB}') markup = types.InlineKeyboardMarkup()
markup.add(LIB, row_width=1)
send_or_reply(message, 'Советую', reply_markup=markup)
@bot.message_handler(commands=['lutz']) @bot.message_handler(commands=['lutz'])
+4 -4
View File
@@ -1,7 +1,7 @@
import os import os
import re import re
import logging import logging
from telebot import TeleBot, logger from telebot import TeleBot, logger, types
from dotenv import load_dotenv from dotenv import load_dotenv
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%Y.%m.%d %H:%M:%S') logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', datefmt='%Y.%m.%d %H:%M:%S')
@@ -31,9 +31,9 @@ ENG = """`qwertyuiop[]asdfghjkl;'zxcvbnm,./~!@#$%^&QWERTYUIOP{}|ASDFGHJKL:"ZXCVB
RUS_ENG_TABLE = str.maketrans(RUS, ENG) RUS_ENG_TABLE = str.maketrans(RUS, ENG)
ENG_RUS_TABLE = str.maketrans(ENG, RUS) ENG_RUS_TABLE = str.maketrans(ENG, RUS)
RULES = '🟡 <b><a href="https://telegra.ph/pythonchatru-07-07">Правила чата</a></b>' RULES = types.InlineKeyboardButton('🟡 Правила чата', url='https://telegra.ph/pythonchatru-07-07')
FAQ = '🔵 <b><a href="https://telegra.ph/faq-10-07-4">Частые вопросы</a></b>' FAQ = types.InlineKeyboardButton('🔵 Частые вопросы', url='https://telegra.ph/faq-10-07-4')
LIB = '📚 <b><a href="https://telegra.ph/what-to-read-10-06">Библиотека питониста</a></b>' LIB = types.InlineKeyboardButton('📚 Библиотека', url='https://telegra.ph/what-to-read-10-06')
SPAM = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/', 'uclck.ru/'] SPAM = ['me.sv/', 'tg.sv/', 'goo.by/', 'go.sv/', 'intim.video/', 'uclck.ru/']
NON_GRATA = ['дудар', 'хауди', 'dudar'] NON_GRATA = ['дудар', 'хауди', 'dudar']
+3 -3
View File
@@ -53,8 +53,8 @@ def is_white(message: types.Message) -> bool:
return message.from_user.username in WHITEUN or message.from_user.id in WHITEIDS return message.from_user.username in WHITEUN or message.from_user.id in WHITEIDS
def send_or_reply(m: types.Message, answer): def send_or_reply(m: types.Message, answer, **kwargs):
if m.reply_to_message: if m.reply_to_message:
bot.reply_to(m.reply_to_message, answer) bot.reply_to(m.reply_to_message, answer, **kwargs)
else: else:
bot.send_message(m.chat.id, answer) bot.send_message(m.chat.id, answer, **kwargs)