diff --git a/requirements.txt b/requirements.txt index 970cc74d..db842be4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,11 +3,12 @@ async-timeout==3.0.1 attrs==19.3.0 bcrypt==3.1.7 certifi==2019.9.11 -cffi==1.13.0 +cffi==1.13.01 chardet==3.0.4 Click==7.0 cryptography==2.8 dateparser==0.7.2 +dice==2.4.2 discord.py==1.2.4 dnspython==1.15.0 dnspython3==1.15.0 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/__init__.py b/royalnet/packs/rpg/__init__.py new file mode 100644 index 00000000..4d839b28 --- /dev/null +++ b/royalnet/packs/rpg/__init__.py @@ -0,0 +1,7 @@ +# This is a template Pack __init__. You can use this without changing anything in other packages too! + +from .commands import available_commands +from .tables import available_tables + +__all__ = ["commands", "tables", "available_commands", "available_tables"] + diff --git a/royalnet/packs/rpg/commands/__init__.py b/royalnet/packs/rpg/commands/__init__.py new file mode 100644 index 00000000..b58f35ab --- /dev/null +++ b/royalnet/packs/rpg/commands/__init__.py @@ -0,0 +1,12 @@ +# 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__ +__all__ = [command.__class__.__qualname__ for command in available_commands] diff --git a/royalnet/packs/rpg/commands/dice.py b/royalnet/packs/rpg/commands/dice.py new file mode 100644 index 00000000..80483154 --- /dev/null +++ b/royalnet/packs/rpg/commands/dice.py @@ -0,0 +1,31 @@ +import dice +from royalnet.commands import * + + +class DiceCommand(Command): + name: str = "dice" + + description: str = "Roll a dice, using 'dice'." + + 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 new file mode 100644 index 00000000..bb69dd8f --- /dev/null +++ b/royalnet/packs/rpg/commands/roll.py @@ -0,0 +1,28 @@ +import typing +import random +from royalnet.commands import * + + +class RollCommand(Command): + name: str = "roll" + + 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: + first: typing.Optional[str] = args.optional(0) + second: typing.Optional[str] = args.optional(1) + if second: + minimum = int(first) + maximum = int(second) + elif first: + minimum = 1 + maximum = int(first) + else: + minimum = 1 + maximum = 100 + result = random.randrange(minimum, maximum+1) + await data.reply(f"🎲 Dice roll [{minimum}-{maximum}]: [b]{result}[/b]") diff --git a/royalnet/packs/rpg/tables/__init__.py b/royalnet/packs/rpg/tables/__init__.py new file mode 100644 index 00000000..23bc7c24 --- /dev/null +++ b/royalnet/packs/rpg/tables/__init__.py @@ -0,0 +1,10 @@ +# Imports go here! + + +# Enter the tables of your Pack here! +available_tables = [ + +] + +# Don't change this, it should automatically generate __all__ +__all__ = [table.__class__.__qualname__ for table in available_tables] diff --git a/royalnet/version.py b/royalnet/version.py index 9a00a37b..23334d27 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.0a69" +semantic = "5.0a70"