1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/giftpack/commands/getgift.py

29 lines
860 B
Python
Raw Normal View History

2019-12-25 01:41:52 +00:00
from typing import *
from royalnet.commands import *
from royalnet.utils import *
from ..tables import XmasGift
from sqlalchemy.sql.expression import func
class GetgiftCommand(Command):
name = "getgift"
aliases = ["drawgift"]
description = "Estrai un regalo qualsiasi."
async def _get_gift(self, args, data):
# Requires postgres
return data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False).order_by(func.random()).first()
async def run(self, args: CommandArgs, data: CommandData) -> None:
xmasgift = await self._get_gift(args, data)
if xmasgift is None:
raise CommandError("Nessun regalo sorteggiabile.")
await data.reply(f"🎁 Il prossimo regalo è...\n"
f"{xmasgift}!")
xmasgift.drawn = True
await data.session_commit()