From 8965238a986383d428f32851e6940a550be8a159 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 21 Oct 2019 13:32:35 +0200 Subject: [PATCH] Start work on roll and dice commands --- requirements.txt | 3 ++- royalnet/packs/rpg/__init__.py | 7 +++++++ royalnet/packs/rpg/commands/__init__.py | 10 ++++++++++ royalnet/packs/rpg/commands/dice.py | 15 ++++++++++++++ royalnet/packs/rpg/commands/roll.py | 26 +++++++++++++++++++++++++ royalnet/packs/rpg/tables/__init__.py | 10 ++++++++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 royalnet/packs/rpg/__init__.py create mode 100644 royalnet/packs/rpg/commands/__init__.py create mode 100644 royalnet/packs/rpg/commands/dice.py create mode 100644 royalnet/packs/rpg/commands/roll.py create mode 100644 royalnet/packs/rpg/tables/__init__.py 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/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..3e6d10ca --- /dev/null +++ b/royalnet/packs/rpg/commands/__init__.py @@ -0,0 +1,10 @@ +# Imports go here! + + +# Enter the commands of your Pack here! +available_commands = [ + +] + +# 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..5981c73f --- /dev/null +++ b/royalnet/packs/rpg/commands/dice.py @@ -0,0 +1,15 @@ +import typing +import random +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: + ... diff --git a/royalnet/packs/rpg/commands/roll.py b/royalnet/packs/rpg/commands/roll.py new file mode 100644 index 00000000..1c140cd5 --- /dev/null +++ b/royalnet/packs/rpg/commands/roll.py @@ -0,0 +1,26 @@ +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)." + + 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}]: {result}") 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]