2020-05-10 22:46:12 +00:00
|
|
|
|
from typing import *
|
|
|
|
|
import royalnet.commands as rc
|
|
|
|
|
import royalnet.utils as ru
|
|
|
|
|
|
2019-11-11 08:56:08 +00:00
|
|
|
|
from ..tables import Diario
|
|
|
|
|
|
|
|
|
|
|
2020-05-10 22:46:12 +00:00
|
|
|
|
class DiarioquoteCommand(rc.Command):
|
2019-11-11 08:56:08 +00:00
|
|
|
|
name: str = "diarioquote"
|
|
|
|
|
|
|
|
|
|
description: str = "Cita una riga del diario."
|
|
|
|
|
|
|
|
|
|
aliases = ["dq", "quote", "dquote"]
|
|
|
|
|
|
|
|
|
|
syntax = "{id}"
|
|
|
|
|
|
2020-05-10 22:46:12 +00:00
|
|
|
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
2019-11-11 08:56:08 +00:00
|
|
|
|
try:
|
|
|
|
|
entry_id = int(args[0].lstrip("#"))
|
|
|
|
|
except ValueError:
|
2020-05-10 22:46:12 +00:00
|
|
|
|
raise rc.CommandError("L'id che hai specificato non è valido.")
|
2020-08-20 01:20:53 +00:00
|
|
|
|
async with data.session_acm() as session:
|
|
|
|
|
entry: Diario = await ru.asyncify(session.query(self.alchemy.get(Diario)).get, entry_id)
|
2019-11-11 08:56:08 +00:00
|
|
|
|
if entry is None:
|
2020-05-10 22:46:12 +00:00
|
|
|
|
raise rc.CommandError("Nessuna riga con quell'id trovata.")
|
2019-11-28 01:30:40 +00:00
|
|
|
|
await data.reply(f"ℹ️ {entry}")
|