diff --git a/.gitignore b/.gitignore index 47b5316..93428e1 100644 --- a/.gitignore +++ b/.gitignore @@ -39,5 +39,5 @@ coverage.xml *.pot # Sphinx documentation docs/_build/ -src/config.json +src/сonfig.json .idea/ \ No newline at end of file diff --git a/src/config.py b/src/config.py index b2b1fc1..82d1990 100644 --- a/src/config.py +++ b/src/config.py @@ -12,7 +12,7 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)-29s - %(le class Config: # noinspection PyTypeChecker - def __init__(self, config_file="config.json"): + def __init__(self, config_file="сonfig.json"): self.log = logging.getLogger(__name__) self.debug = self.log.debug diff --git a/src/keyboard.py b/src/keyboard.py new file mode 100644 index 0000000..d1dcfe2 --- /dev/null +++ b/src/keyboard.py @@ -0,0 +1,8 @@ +from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove + +network = KeyboardButton('Сеть') +subnet = KeyboardButton('Подсети') +help = KeyboardButton('Помощь') + +kb = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True) +kb.row(network, subnet, help) \ No newline at end of file diff --git a/src/main.py b/src/main.py index 1d01006..449a668 100644 --- a/src/main.py +++ b/src/main.py @@ -10,9 +10,10 @@ from aiogram import Bot, Dispatcher, types from aiogram.types import ChatType, ParseMode from aiogram.utils import executor -from src.config import Config +from config import Config +from keyboard import * -config = Config("config.json") +config = Config("сonfig.json") log = logging.getLogger("Bot") bot = Bot(token=config.token) dp = Dispatcher(bot) @@ -67,16 +68,16 @@ def subnets(ip, prefix): @dp.message_handler(commands=["start"], chat_type=ChatType.PRIVATE) async def start(msg: types.Message): log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'") - await msg.reply(f"Привет, дорогой мой {msg.from_user.username}") + await msg.reply(f"Привет, дорогой мой {msg.from_user.username}", reply_markup=kb) -@dp.message_handler(commands=["help"], chat_type=ChatType.PRIVATE) +@dp.message_handler(lambda msg: msg.text.startswith('Помощь')) async def start(msg: types.Message): log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'") await msg.reply("Команды:\n/calcnet - посчитать сеть\n/calcsub - разбить на подсети") -@dp.message_handler(commands=["calcnet"], chat_type=ChatType.PRIVATE) +@dp.message_handler(lambda msg: msg.text.startswith('Сеть')) async def calcnet(msg: types.Message): log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'") text = msg.text @@ -99,14 +100,14 @@ async def calcnet(msg: types.Message): parse_mode=ParseMode.MARKDOWN) -@dp.message_handler(commands=["calcsub"], chat_type=ChatType.PRIVATE) +@dp.message_handler(lambda msg: msg.text.startswith('Подсети')) async def calcsub(msg: types.Message): log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'") text = msg.text splt = text.split(" ") if len(splt) > 1: ip = splt[1] - await msg.reply("Не гатова") + await msg.reply("Не готова") else: await msg.reply("**Командна введена не правильно**\n" "Пример выполнения команды: `/calcsub 192.168.0.1/24 26`", @@ -114,6 +115,4 @@ async def calcsub(msg: types.Message): if __name__ == '__main__': - executor.start_polling(dp) - # Тут должна быть кнопка типа "Подсети" - # subnets(input("ip: "), input('\nВведите префикс: ')) + executor.start_polling(dp) \ No newline at end of file