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-03-23 01:55:25 +00:00
|
|
|
|
DiarioT = self.alchemy.get(Diario)
|
2020-05-10 22:46:12 +00:00
|
|
|
|
entry: List[Diario] = await ru.asyncify(
|
2020-03-23 01:55:25 +00:00
|
|
|
|
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.")
|
2020-03-23 01:55:25 +00:00
|
|
|
|
await data.reply(f"ℹ️ {entry}")
|