Версия 0.1 - рабочая
commit
06627b69ff
|
|
@ -0,0 +1,4 @@
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
- [x] Написать базовый функционал
|
||||||
|
- [ ] Создать соотношение типа "id_пользователя: досутп_к_замку:"
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
from aiogram.utils.keyboard import ReplyKeyboardBuilder
|
||||||
|
|
||||||
|
def FBI_open_up():
|
||||||
|
kb = ReplyKeyboardBuilder()
|
||||||
|
kb.button(text = "Сизам вскройся")
|
||||||
|
|
||||||
|
return kb.as_markup(resize_keyboard = True)
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,65 @@
|
||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from aiogram.types import Message
|
||||||
|
from aiogram.filters import CommandStart
|
||||||
|
from aiogram import Bot, Dispatcher
|
||||||
|
from aiogram.client.default import DefaultBotProperties
|
||||||
|
from aiogram.enums import ParseMode
|
||||||
|
from aiogram import F
|
||||||
|
|
||||||
|
from os import getenv
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from buttons import FBI_open_up
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = getenv("TOKEN")
|
||||||
|
dp = Dispatcher()
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message(CommandStart())
|
||||||
|
async def command_start_handler(msg: Message):
|
||||||
|
await msg.answer("msg happens", reply_markup=FBI_open_up())
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message(F.text == "Сизам вскройся")
|
||||||
|
async def handle_open_door(msg: Message):
|
||||||
|
user_id = msg.from_user.id
|
||||||
|
# print(msg.__dict__)
|
||||||
|
print(user_id)
|
||||||
|
|
||||||
|
url = f"http://{getenv('LOCK_IP')}/cgi-bin/ext"
|
||||||
|
auth = ("ext", f"{getenv('AUTH_API')}")
|
||||||
|
payload = f"CARD={getenv('CARD_ID')}&DIR=0"
|
||||||
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = await asyncio.to_thread(
|
||||||
|
requests.post, url, auth=auth, data=payload, headers=headers, timeout=5
|
||||||
|
)
|
||||||
|
if response.status_code == 200:
|
||||||
|
await msg.answer("Открыто")
|
||||||
|
else:
|
||||||
|
await msg.answer(
|
||||||
|
f"Ошибка при открытии замка. Код ошибки: {response.status_code}"
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
await msg.answer(f"Исключение: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
async def main() -> None:
|
||||||
|
# Initialize Bot instance with default bot properties which will be passed to all API calls
|
||||||
|
bot = Bot(token=TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML))
|
||||||
|
|
||||||
|
# And the run events dispatching
|
||||||
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
||||||
|
asyncio.run(main())
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
aiofiles==24.1.0
|
||||||
|
aiogram==3.20.0.post0
|
||||||
|
aiohappyeyeballs==2.6.1
|
||||||
|
aiohttp==3.11.18
|
||||||
|
aiosignal==1.3.2
|
||||||
|
annotated-types==0.7.0
|
||||||
|
attrs==25.3.0
|
||||||
|
certifi==2025.4.26
|
||||||
|
charset-normalizer==3.4.1
|
||||||
|
frozenlist==1.6.0
|
||||||
|
idna==3.10
|
||||||
|
magic-filter==1.0.12
|
||||||
|
multidict==6.4.3
|
||||||
|
propcache==0.3.1
|
||||||
|
pydantic==2.11.3
|
||||||
|
pydantic_core==2.33.1
|
||||||
|
python-dotenv==1.1.0
|
||||||
|
requests==2.32.3
|
||||||
|
typing-inspection==0.4.0
|
||||||
|
typing_extensions==4.13.2
|
||||||
|
urllib3==2.4.0
|
||||||
|
yarl==1.20.0
|
||||||
Loading…
Reference in New Issue