diff --git a/royalnet/bots/generic.py b/royalnet/bots/generic.py index 71c40989..ca05a54f 100644 --- a/royalnet/bots/generic.py +++ b/royalnet/bots/generic.py @@ -74,6 +74,8 @@ class GenericBot: request: rh.Request = rh.Request(handler=event_name, data=args) response: rh.Response = await self.network.request(destination=destination, request=request) if isinstance(response, rh.ResponseFailure): + if response.extra_info["type"] == "CommandError": + raise CommandError(response.extra_info["message"]) raise CommandError(f"Herald action call failed:\n" f"[p]{response}[/p]") elif isinstance(response, rh.ResponseSuccess): diff --git a/royalnet/packs/royal/tables/__init__.py b/royalnet/packs/royal/tables/__init__.py index f20c16fe..d0201a73 100644 --- a/royalnet/packs/royal/tables/__init__.py +++ b/royalnet/packs/royal/tables/__init__.py @@ -5,9 +5,6 @@ from royalnet.packs.common.tables import Discord from .diario import Diario from .aliases import Alias -from .activekvgroups import ActiveKvGroup -from .keyvalues import Keyvalue -from .keygroups import Keygroup from .wikipages import WikiPage from .wikirevisions import WikiRevision from .bios import Bio @@ -24,9 +21,6 @@ available_tables = [ Discord, Diario, Alias, - ActiveKvGroup, - Keyvalue, - Keygroup, WikiPage, WikiRevision, Bio, diff --git a/royalnet/packs/royal/tables/activekvgroups.py b/royalnet/packs/royal/tables/activekvgroups.py deleted file mode 100644 index a4f72cff..00000000 --- a/royalnet/packs/royal/tables/activekvgroups.py +++ /dev/null @@ -1,29 +0,0 @@ -from sqlalchemy import Column, \ - String, \ - Integer, \ - ForeignKey -from sqlalchemy.orm import relationship -from sqlalchemy.ext.declarative import declared_attr - - -class ActiveKvGroup: - __tablename__ = "activekvgroups" - - @declared_attr - def royal_id(self): - return Column(Integer, ForeignKey("users.uid"), primary_key=True) - - @declared_attr - def group_name(self): - return Column(String, ForeignKey("keygroups.group_name"), nullable=False) - - @declared_attr - def royal(self): - return relationship("User", backref="active_kv_group") - - @declared_attr - def group(self): - return relationship("Keygroup", backref="users_with_this_active") - - def __repr__(self): - return f"" diff --git a/royalnet/packs/royal/tables/keygroups.py b/royalnet/packs/royal/tables/keygroups.py deleted file mode 100644 index a1dbf9c8..00000000 --- a/royalnet/packs/royal/tables/keygroups.py +++ /dev/null @@ -1,15 +0,0 @@ -from sqlalchemy import Column, \ - String, \ - ForeignKey -from sqlalchemy.ext.declarative import declared_attr - - -class Keygroup: - __tablename__ = "keygroups" - - @declared_attr - def group_name(self): - return Column(String, ForeignKey("keygroups.group_name"), primary_key=True) - - def __repr__(self): - return f"" diff --git a/royalnet/packs/royal/tables/keyvalues.py b/royalnet/packs/royal/tables/keyvalues.py deleted file mode 100644 index 6d3565d8..00000000 --- a/royalnet/packs/royal/tables/keyvalues.py +++ /dev/null @@ -1,31 +0,0 @@ -from sqlalchemy import Column, \ - String, \ - ForeignKey -from sqlalchemy.orm import relationship -from sqlalchemy.ext.declarative import declared_attr - - -class Keyvalue: - __tablename__ = "keyvalues" - - @declared_attr - def group_name(self): - return Column(String, ForeignKey("keygroups.group_name"), primary_key=True) - - @declared_attr - def key(self): - return Column(String, primary_key=True) - - @declared_attr - def value(self): - return Column(String, nullable=False) - - @declared_attr - def group(self): - return relationship("Keygroup") - - def __repr__(self): - return f"" - - def __str__(self): - return f"{self.key}: [b]{self.value}[/b]" diff --git a/royalnet/packs/rpg/commands/__init__.py b/royalnet/packs/rpg/commands/__init__.py index 3e6d10ca..b58f35ab 100644 --- a/royalnet/packs/rpg/commands/__init__.py +++ b/royalnet/packs/rpg/commands/__init__.py @@ -1,9 +1,11 @@ # Imports go here! - +from .roll import RollCommand +from .dice import DiceCommand # Enter the commands of your Pack here! available_commands = [ - + RollCommand, + DiceCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalnet/packs/rpg/commands/dice.py b/royalnet/packs/rpg/commands/dice.py index 5981c73f..80483154 100644 --- a/royalnet/packs/rpg/commands/dice.py +++ b/royalnet/packs/rpg/commands/dice.py @@ -1,5 +1,3 @@ -import typing -import random import dice from royalnet.commands import * @@ -12,4 +10,22 @@ class DiceCommand(Command): aliases = ["d"] async def run(self, args: CommandArgs, data: CommandData) -> None: - ... + dice_str = args.joined(require_at_least=1) + roll = dice.roll(dice_str) + try: + result = list(roll) + except TypeError: + result = [roll] + message = f"🎲 {dice_str}" + total = 0 + if len(result) > 1: + message += f" = " + for index, die in enumerate(result): + message += f"{die}" + total += int(die) + if (index + 1) < len(result): + message += "+" + else: + total += int(result[0]) + message += f" = [b]{total}[/b]" + await data.reply(message) diff --git a/royalnet/packs/rpg/commands/roll.py b/royalnet/packs/rpg/commands/roll.py index 1c140cd5..bb69dd8f 100644 --- a/royalnet/packs/rpg/commands/roll.py +++ b/royalnet/packs/rpg/commands/roll.py @@ -8,6 +8,8 @@ class RollCommand(Command): description: str = "Roll a dice, from N to M (defaults to 1-100)." + syntax = "[min] [max]" + aliases = ["r", "random"] async def run(self, args: CommandArgs, data: CommandData) -> None: @@ -23,4 +25,4 @@ class RollCommand(Command): minimum = 1 maximum = 100 result = random.randrange(minimum, maximum+1) - await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: {result}") + await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: [b]{result}[/b]")