Add telegram bot
This commit is contained in:
@@ -8,8 +8,9 @@ from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.models import (
|
||||
Dispute, DisputeStatus, DisputeVote,
|
||||
Assignment, AssignmentStatus, Participant,
|
||||
Assignment, AssignmentStatus, Participant, Marathon, Challenge, Game,
|
||||
)
|
||||
from app.services.telegram_notifier import telegram_notifier
|
||||
|
||||
|
||||
class DisputeService:
|
||||
@@ -58,8 +59,53 @@ class DisputeService:
|
||||
|
||||
await db.commit()
|
||||
|
||||
# Send Telegram notification about dispute resolution
|
||||
await self._notify_dispute_resolved(db, dispute, result_status == DisputeStatus.RESOLVED_INVALID.value)
|
||||
|
||||
return result_status, votes_valid, votes_invalid
|
||||
|
||||
async def _notify_dispute_resolved(
|
||||
self,
|
||||
db: AsyncSession,
|
||||
dispute: Dispute,
|
||||
is_valid: bool
|
||||
) -> None:
|
||||
"""Send notification about dispute resolution to the assignment owner."""
|
||||
try:
|
||||
# Get assignment with challenge and marathon info
|
||||
result = await db.execute(
|
||||
select(Assignment)
|
||||
.options(
|
||||
selectinload(Assignment.participant),
|
||||
selectinload(Assignment.challenge).selectinload(Challenge.game)
|
||||
)
|
||||
.where(Assignment.id == dispute.assignment_id)
|
||||
)
|
||||
assignment = result.scalar_one_or_none()
|
||||
if not assignment:
|
||||
return
|
||||
|
||||
participant = assignment.participant
|
||||
challenge = assignment.challenge
|
||||
game = challenge.game if challenge else None
|
||||
|
||||
# Get marathon
|
||||
result = await db.execute(
|
||||
select(Marathon).where(Marathon.id == game.marathon_id if game else 0)
|
||||
)
|
||||
marathon = result.scalar_one_or_none()
|
||||
|
||||
if marathon and participant:
|
||||
await telegram_notifier.notify_dispute_resolved(
|
||||
db,
|
||||
user_id=participant.user_id,
|
||||
marathon_title=marathon.title,
|
||||
challenge_title=challenge.title if challenge else "Unknown",
|
||||
is_valid=is_valid
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"[DisputeService] Failed to send notification: {e}")
|
||||
|
||||
async def _handle_invalid_proof(self, db: AsyncSession, dispute: Dispute) -> None:
|
||||
"""
|
||||
Handle the case when proof is determined to be invalid.
|
||||
|
||||
Reference in New Issue
Block a user