1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/commands/diarioquote.py

26 lines
780 B
Python
Raw Normal View History

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.")
entry: Diario = await ru.asyncify(data.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.")
await data.reply(f" {entry}")