1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/royalpack/commands/diarioshuffle.py

30 lines
805 B
Python
Raw Normal View History

from typing import *
2020-05-10 22:46:12 +00:00
import royalnet.commands as rc
import royalnet.utils as ru
from sqlalchemy import func
2020-05-10 22:46:12 +00:00
from ..tables import Diario
2020-05-10 22:46:12 +00:00
class DiarioshuffleCommand(rc.Command):
name: str = "diarioshuffle"
description: str = "Cita una riga casuale del diario."
aliases = ["dis", "dishuffle", "dish"]
syntax = ""
2020-05-10 22:46:12 +00:00
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
DiarioT = self.alchemy.get(Diario)
2020-05-10 22:46:12 +00:00
entry: List[Diario] = await ru.asyncify(
data.session
.query(DiarioT)
.order_by(func.random())
.limit(1)
.one_or_none
)
if entry is None:
2020-05-10 22:46:12 +00:00
raise rc.CommandError("Nessuna riga del diario trovata.")
await data.reply(f" {entry}")