mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-12-16 21:20:39 +03:00
update poetry.lock
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
from asyncio import Queue, sleep
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property
|
||||
@@ -13,13 +14,14 @@ from app.constants import API_PREFIX
|
||||
from settings.config import Settings
|
||||
|
||||
|
||||
class Bot:
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
class BotApplication:
|
||||
def __init__(self, settings: Settings, start_with_webhook: bool = False) -> None:
|
||||
self.application: Application = ( # type: ignore
|
||||
Application.builder().token(token=settings.TELEGRAM_API_TOKEN).build()
|
||||
)
|
||||
self.add_handlers()
|
||||
self.settings = settings
|
||||
self.start_with_webhook = start_with_webhook
|
||||
|
||||
async def set_webhook(self) -> None:
|
||||
await self.application.initialize()
|
||||
@@ -32,8 +34,18 @@ class Bot:
|
||||
@staticmethod
|
||||
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Send a message when the command /help is issued."""
|
||||
|
||||
if update.message:
|
||||
await update.message.reply_text('Help!')
|
||||
await asyncio.sleep(10)
|
||||
await update.message.reply_text(
|
||||
'Help!',
|
||||
disable_notification=True,
|
||||
api_kwargs={
|
||||
"text": "Hello World",
|
||||
"date": int(time.time()) + 30,
|
||||
"schedule_date": int(time.time()) + 30,
|
||||
},
|
||||
)
|
||||
return None
|
||||
|
||||
def add_handlers(self) -> None:
|
||||
@@ -59,15 +71,15 @@ class Bot:
|
||||
|
||||
@dataclass
|
||||
class BotQueue:
|
||||
bot: Bot
|
||||
queue: Queue = asyncio.Queue() # type: ignore
|
||||
bot_app: Application # type: ignore[type-arg]
|
||||
queue: Queue = asyncio.Queue() # type: ignore[type-arg]
|
||||
|
||||
async def put_updates_on_queue(self, request: Request) -> Response:
|
||||
"""
|
||||
Listen {WEBHOOK_PATH}/{TELEGRAM_WEB_TOKEN} path and proxy post request to bot
|
||||
"""
|
||||
data = await request.json()
|
||||
tg_update = Update.de_json(data=data, bot=self.bot.application.bot)
|
||||
tg_update = Update.de_json(data=data, bot=self.bot_app.bot)
|
||||
self.queue.put_nowait(tg_update)
|
||||
|
||||
return Response(status_code=HTTPStatus.ACCEPTED)
|
||||
@@ -75,5 +87,6 @@ class BotQueue:
|
||||
async def get_updates_from_queue(self) -> None:
|
||||
while True:
|
||||
update = await self.queue.get()
|
||||
await self.bot.application.process_update(update)
|
||||
await sleep(0.1)
|
||||
print(update)
|
||||
await self.bot_app.process_update(update)
|
||||
await sleep(0)
|
||||
|
||||
Reference in New Issue
Block a user