mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
commit
38d98684f5
12 changed files with 93 additions and 83 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"<ActiveKvGroup royal={self.royal} group={self.group_name}>"
|
|
@ -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"<Keygroup {self.group_name}>"
|
|
@ -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"<Keyvalue group={self.group_name} key={self.key} value={self.value}>"
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.key}: [b]{self.value}[/b]"
|
7
royalnet/packs/rpg/__init__.py
Normal file
7
royalnet/packs/rpg/__init__.py
Normal file
|
@ -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"]
|
||||
|
12
royalnet/packs/rpg/commands/__init__.py
Normal file
12
royalnet/packs/rpg/commands/__init__.py
Normal file
|
@ -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]
|
31
royalnet/packs/rpg/commands/dice.py
Normal file
31
royalnet/packs/rpg/commands/dice.py
Normal file
|
@ -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)
|
28
royalnet/packs/rpg/commands/roll.py
Normal file
28
royalnet/packs/rpg/commands/roll.py
Normal file
|
@ -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]")
|
10
royalnet/packs/rpg/tables/__init__.py
Normal file
10
royalnet/packs/rpg/tables/__init__.py
Normal file
|
@ -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]
|
|
@ -1 +1 @@
|
|||
semantic = "5.0a69"
|
||||
semantic = "5.0a70"
|
||||
|
|
Loading…
Reference in a new issue