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

27 lines
810 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:
2020-08-20 01:20:53 +00:00
async with data.session_acm() as session:
DiarioT = self.alchemy.get(Diario)
entry: List[Diario] = await ru.asyncify(
session.query(DiarioT).order_by(func.random()).limit(1).one_or_none
)
if entry is None:
raise rc.CommandError("Nessuna riga del diario trovata.")
await data.reply(f" {entry}")