From d8bc4b792cb9c2be6d474887e7f0e62d87216a11 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 5 Nov 2019 10:56:45 +0100 Subject: [PATCH] Create diarioquote command (closes #81) --- royalnet/packs/royal/commands/__init__.py | 2 ++ royalnet/packs/royal/commands/diarioquote.py | 25 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 royalnet/packs/royal/commands/diarioquote.py diff --git a/royalnet/packs/royal/commands/__init__.py b/royalnet/packs/royal/commands/__init__.py index d33a1e17..88785ff3 100644 --- a/royalnet/packs/royal/commands/__init__.py +++ b/royalnet/packs/royal/commands/__init__.py @@ -21,6 +21,7 @@ from .soundcloud import SoundcloudCommand from .zawarudo import ZawarudoCommand from .emojify import EmojifyCommand from .leagueoflegends import LeagueoflegendsCommand +from .diarioquote import DiarioquoteCommand # Enter the commands of your Pack here! available_commands = [ @@ -46,6 +47,7 @@ available_commands = [ ZawarudoCommand, EmojifyCommand, LeagueoflegendsCommand, + DiarioquoteCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalnet/packs/royal/commands/diarioquote.py b/royalnet/packs/royal/commands/diarioquote.py new file mode 100644 index 00000000..aa2051e4 --- /dev/null +++ b/royalnet/packs/royal/commands/diarioquote.py @@ -0,0 +1,25 @@ +from royalnet.commands import * +from royalnet.utils import * +from ..tables import Diario + + +class DiarioquoteCommand(Command): + name: str = "diarioquote" + + description: str = "Cita una riga del diario." + + aliases = ["dq", "quote", "dquote"] + + syntax = "{id}" + + tables = {Diario} + + async def run(self, args: CommandArgs, data: CommandData) -> None: + try: + entry_id = int(args[0].lstrip("#")) + except ValueError: + raise CommandError("L'id che hai specificato non รจ valido.") + entry: Diario = await data.session.query(self.alchemy.Diario).get(entry_id) + if entry is None: + raise CommandError("Nessuna riga con quell'id trovata.") + await data.reply(str(entry))