Add telegram bot
This commit is contained in:
@@ -6,6 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models import Event, EventType, Marathon, Challenge, Difficulty, Participant, Assignment, AssignmentStatus
|
||||
from app.schemas.event import EventEffects, EVENT_INFO, COMMON_ENEMY_BONUSES
|
||||
from app.services.telegram_notifier import telegram_notifier
|
||||
|
||||
|
||||
class EventService:
|
||||
@@ -89,6 +90,14 @@ class EventService:
|
||||
if created_by_id:
|
||||
await db.refresh(event, ["created_by"])
|
||||
|
||||
# Send Telegram notifications
|
||||
result = await db.execute(select(Marathon).where(Marathon.id == marathon_id))
|
||||
marathon = result.scalar_one_or_none()
|
||||
if marathon:
|
||||
await telegram_notifier.notify_event_start(
|
||||
db, marathon_id, event_type, marathon.title
|
||||
)
|
||||
|
||||
return event
|
||||
|
||||
async def _assign_common_enemy_to_all(
|
||||
@@ -124,6 +133,9 @@ class EventService:
|
||||
result = await db.execute(select(Event).where(Event.id == event_id))
|
||||
event = result.scalar_one_or_none()
|
||||
if event:
|
||||
event_type = event.type
|
||||
marathon_id = event.marathon_id
|
||||
|
||||
event.is_active = False
|
||||
if not event.end_time:
|
||||
event.end_time = datetime.utcnow()
|
||||
@@ -145,6 +157,14 @@ class EventService:
|
||||
|
||||
await db.commit()
|
||||
|
||||
# Send Telegram notifications about event end
|
||||
result = await db.execute(select(Marathon).where(Marathon.id == marathon_id))
|
||||
marathon = result.scalar_one_or_none()
|
||||
if marathon:
|
||||
await telegram_notifier.notify_event_end(
|
||||
db, marathon_id, event_type, marathon.title
|
||||
)
|
||||
|
||||
async def consume_jackpot(self, db: AsyncSession, event_id: int) -> None:
|
||||
"""Consume jackpot event after one spin"""
|
||||
await self.end_event(db, event_id)
|
||||
|
||||
Reference in New Issue
Block a user