mirror of
https://github.com/Marsh232/Telegram-IP-CALC.git
synced 2025-07-02 15:55:43 +00:00
Add button
This commit is contained in:
parent
a203d712cc
commit
de1c1af628
2
.gitignore
vendored
2
.gitignore
vendored
@ -39,5 +39,5 @@ coverage.xml
|
|||||||
*.pot
|
*.pot
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
src/config.json
|
src/сonfig.json
|
||||||
.idea/
|
.idea/
|
@ -12,7 +12,7 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)-29s - %(le
|
|||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
def __init__(self, config_file="config.json"):
|
def __init__(self, config_file="сonfig.json"):
|
||||||
self.log = logging.getLogger(__name__)
|
self.log = logging.getLogger(__name__)
|
||||||
self.debug = self.log.debug
|
self.debug = self.log.debug
|
||||||
|
|
||||||
|
8
src/keyboard.py
Normal file
8
src/keyboard.py
Normal file
@ -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)
|
19
src/main.py
19
src/main.py
@ -10,9 +10,10 @@ from aiogram import Bot, Dispatcher, types
|
|||||||
from aiogram.types import ChatType, ParseMode
|
from aiogram.types import ChatType, ParseMode
|
||||||
from aiogram.utils import executor
|
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")
|
log = logging.getLogger("Bot")
|
||||||
bot = Bot(token=config.token)
|
bot = Bot(token=config.token)
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
@ -67,16 +68,16 @@ def subnets(ip, prefix):
|
|||||||
@dp.message_handler(commands=["start"], chat_type=ChatType.PRIVATE)
|
@dp.message_handler(commands=["start"], chat_type=ChatType.PRIVATE)
|
||||||
async def start(msg: types.Message):
|
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}'")
|
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):
|
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}'")
|
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 - разбить на подсети")
|
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):
|
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}'")
|
log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'")
|
||||||
text = msg.text
|
text = msg.text
|
||||||
@ -99,14 +100,14 @@ async def calcnet(msg: types.Message):
|
|||||||
parse_mode=ParseMode.MARKDOWN)
|
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):
|
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}'")
|
log.info(f"New message from {msg.from_user.id}(@{msg.from_user.username}) in {msg.chat.id}: '{msg.text}'")
|
||||||
text = msg.text
|
text = msg.text
|
||||||
splt = text.split(" ")
|
splt = text.split(" ")
|
||||||
if len(splt) > 1:
|
if len(splt) > 1:
|
||||||
ip = splt[1]
|
ip = splt[1]
|
||||||
await msg.reply("Не гатова")
|
await msg.reply("Не готова")
|
||||||
else:
|
else:
|
||||||
await msg.reply("**Командна введена не правильно**\n"
|
await msg.reply("**Командна введена не правильно**\n"
|
||||||
"Пример выполнения команды: `/calcsub 192.168.0.1/24 26`",
|
"Пример выполнения команды: `/calcsub 192.168.0.1/24 26`",
|
||||||
@ -114,6 +115,4 @@ async def calcsub(msg: types.Message):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
executor.start_polling(dp)
|
executor.start_polling(dp)
|
||||||
# Тут должна быть кнопка типа "Подсети"
|
|
||||||
# subnets(input("ip: "), input('\nВведите префикс: '))
|
|
Loading…
x
Reference in New Issue
Block a user