2020-03-23 01:55:25 +00:00
|
|
|
|
from typing import *
|
2020-05-10 22:46:12 +00:00
|
|
|
|
import royalnet.commands as rc
|
|
|
|
|
import royalnet.utils as ru
|
2020-03-23 01:55:25 +00:00
|
|
|
|
from sqlalchemy import func
|
|
|
|
|
|
2020-05-10 22:46:12 +00:00
|
|
|
|
from ..tables import Diario
|
|
|
|
|
|
2020-03-23 01:55:25 +00:00
|
|
|
|
|
2020-05-10 22:46:12 +00:00
|
|
|
|
class DiarioshuffleCommand(rc.Command):
|
2020-03-23 01:55:25 +00:00
|
|
|
|
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}")
|