mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
First working version (1.0)
This commit is contained in:
parent
363ce6373c
commit
7adef44e00
24 changed files with 1325 additions and 115 deletions
|
@ -1,5 +1 @@
|
||||||
# `examplepack`
|
# `giftpack`
|
||||||
|
|
||||||
This is an example Pack for [Royalnet](https://github.com/Steffo99/royalnet)!
|
|
||||||
|
|
||||||
> To be updated with more info on how to create your own pack.
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
# Imports go here!
|
|
||||||
# TODO: If you create a new command, remember to import it here...
|
|
||||||
from .example import ExampleCommand
|
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
|
||||||
# TODO: and add it to the list here!
|
|
||||||
available_commands = [
|
|
||||||
ExampleCommand,
|
|
||||||
]
|
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
|
||||||
__all__ = [command.__name__ for command in available_commands]
|
|
|
@ -1,12 +0,0 @@
|
||||||
from typing import *
|
|
||||||
from royalnet.commands import *
|
|
||||||
from royalnet.utils import *
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleCommand(Command):
|
|
||||||
name: str = "example"
|
|
||||||
|
|
||||||
description: str = "Say Hello to the world!"
|
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
|
||||||
await data.reply("Hello world!")
|
|
|
@ -1,10 +0,0 @@
|
||||||
from typing import *
|
|
||||||
from royalnet.commands import *
|
|
||||||
from royalnet.utils import *
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleEvent(Event):
|
|
||||||
name = "example"
|
|
||||||
|
|
||||||
async def run(self, **kwargs) -> dict:
|
|
||||||
return {"hello": "world"}
|
|
|
@ -1,13 +0,0 @@
|
||||||
from starlette.requests import Request
|
|
||||||
from starlette.responses import *
|
|
||||||
from royalnet.constellation import *
|
|
||||||
from royalnet.utils import *
|
|
||||||
|
|
||||||
|
|
||||||
class ApiExampleStar(PageStar):
|
|
||||||
path = "/api/example"
|
|
||||||
|
|
||||||
async def page(self, request: Request) -> JSONResponse:
|
|
||||||
return JSONResponse({
|
|
||||||
"hello": "world",
|
|
||||||
})
|
|
|
@ -1,13 +0,0 @@
|
||||||
from starlette.requests import Request
|
|
||||||
from starlette.responses import *
|
|
||||||
from royalnet.constellation import *
|
|
||||||
from royalnet.utils import *
|
|
||||||
|
|
||||||
|
|
||||||
class ApiExcsampleStar(ExceptionStar):
|
|
||||||
error = 404
|
|
||||||
|
|
||||||
async def page(self, request: Request) -> JSONResponse:
|
|
||||||
return JSONResponse({
|
|
||||||
"error": "404 not found",
|
|
||||||
})
|
|
|
@ -1,19 +0,0 @@
|
||||||
from sqlalchemy import *
|
|
||||||
from sqlalchemy.orm import *
|
|
||||||
from sqlalchemy.ext.declarative import declared_attr
|
|
||||||
|
|
||||||
|
|
||||||
class Example:
|
|
||||||
__tablename__ = "examples"
|
|
||||||
|
|
||||||
@declared_attr
|
|
||||||
def creator_id(self):
|
|
||||||
return Column(Integer, ForeignKey("users.uid"), primary_key=True)
|
|
||||||
|
|
||||||
@declared_attr
|
|
||||||
def creator(self):
|
|
||||||
return relationship("User", backref=backref("examples_createdx"))
|
|
||||||
|
|
||||||
@declared_attr
|
|
||||||
def example(self):
|
|
||||||
return Column(String, nullable=False, default="Hello world!")
|
|
|
@ -1,2 +0,0 @@
|
||||||
# TODO: Increment this every new version of your pack!
|
|
||||||
semantic = "0.1.0"
|
|
22
giftpack/commands/__init__.py
Normal file
22
giftpack/commands/__init__.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Imports go here!
|
||||||
|
from .addgift import AddgiftCommand
|
||||||
|
from .delgift import DelgiftCommand
|
||||||
|
from .getgift import GetgiftCommand
|
||||||
|
from .getgiftdst import GetgiftdstCommand
|
||||||
|
from .getgiftid import GetgiftidCommand
|
||||||
|
from .getgiftsrc import GetgiftsrcCommand
|
||||||
|
from .listgifts import ListgiftsCommand
|
||||||
|
|
||||||
|
# Enter the commands of your Pack here!
|
||||||
|
available_commands = [
|
||||||
|
AddgiftCommand,
|
||||||
|
DelgiftCommand,
|
||||||
|
GetgiftCommand,
|
||||||
|
GetgiftdstCommand,
|
||||||
|
GetgiftidCommand,
|
||||||
|
GetgiftsrcCommand,
|
||||||
|
ListgiftsCommand,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Don't change this, it should automatically generate __all__
|
||||||
|
__all__ = [command.__name__ for command in available_commands]
|
29
giftpack/commands/addgift.py
Normal file
29
giftpack/commands/addgift.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from royalnet.utils import *
|
||||||
|
from ..tables import XmasGift
|
||||||
|
|
||||||
|
|
||||||
|
class AddgiftCommand(Command):
|
||||||
|
name: str = "addgift"
|
||||||
|
|
||||||
|
aliases = ["newgift"]
|
||||||
|
|
||||||
|
description: str = "Aggiungi un nuovo regalo al pool."
|
||||||
|
|
||||||
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
|
source = args[0]
|
||||||
|
destination = args[1]
|
||||||
|
extra_text = " ".join(args[2:])
|
||||||
|
|
||||||
|
xmasgift = self.alchemy.get(XmasGift)(
|
||||||
|
source=source,
|
||||||
|
destination=destination,
|
||||||
|
extra_text=extra_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
data.session.add(xmasgift)
|
||||||
|
await data.session_commit()
|
||||||
|
|
||||||
|
await data.reply(f"🎁 Regalo creato:\n"
|
||||||
|
f"{xmasgift}")
|
19
giftpack/commands/delgift.py
Normal file
19
giftpack/commands/delgift.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from ..tables import XmasGift
|
||||||
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
|
||||||
|
class DelgiftCommand(Command):
|
||||||
|
name: str = "delgift"
|
||||||
|
|
||||||
|
description: str = "Elimina dal database il regalo con l'id specificato."
|
||||||
|
|
||||||
|
syntax: str = ""
|
||||||
|
|
||||||
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
|
gift = data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False, gift_id=int(args[0])).order_by(func.random()).first()
|
||||||
|
data.session.delete(gift)
|
||||||
|
await data.reply(f"🎁 Regalo eliminato (bye bye!):\n"
|
||||||
|
f"{gift}")
|
||||||
|
await data.session_commit()
|
28
giftpack/commands/getgift.py
Normal file
28
giftpack/commands/getgift.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from royalnet.utils import *
|
||||||
|
from ..tables import XmasGift
|
||||||
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
|
||||||
|
class GetgiftCommand(Command):
|
||||||
|
name = "getgift"
|
||||||
|
|
||||||
|
aliases = ["drawgift"]
|
||||||
|
|
||||||
|
description = "Estrai un regalo qualsiasi."
|
||||||
|
|
||||||
|
async def _get_gift(self, args, data):
|
||||||
|
# Requires postgres
|
||||||
|
return data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False).order_by(func.random()).first()
|
||||||
|
|
||||||
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
|
xmasgift = await self._get_gift(args, data)
|
||||||
|
if xmasgift is None:
|
||||||
|
raise CommandError("Nessun regalo sorteggiabile.")
|
||||||
|
|
||||||
|
await data.reply(f"🎁 Il prossimo regalo è...\n"
|
||||||
|
f"{xmasgift}!")
|
||||||
|
|
||||||
|
xmasgift.drawn = True
|
||||||
|
await data.session_commit()
|
18
giftpack/commands/getgiftdst.py
Normal file
18
giftpack/commands/getgiftdst.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from .getgift import GetgiftCommand
|
||||||
|
from ..tables import XmasGift
|
||||||
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
|
||||||
|
class GetgiftdstCommand(GetgiftCommand):
|
||||||
|
name: str = "getgiftdst"
|
||||||
|
|
||||||
|
aliases = ["drawgiftdst"]
|
||||||
|
|
||||||
|
description: str = "Estrai un regalo con un certo destinatario."
|
||||||
|
|
||||||
|
syntax: str = "{destinatario}"
|
||||||
|
|
||||||
|
async def _get_gift(self, args, data):
|
||||||
|
return data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False, destination=args[0]).order_by(func.random()).first()
|
18
giftpack/commands/getgiftid.py
Normal file
18
giftpack/commands/getgiftid.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from .getgift import GetgiftCommand
|
||||||
|
from ..tables import XmasGift
|
||||||
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
|
||||||
|
class GetgiftidCommand(GetgiftCommand):
|
||||||
|
name: str = "getgiftid"
|
||||||
|
|
||||||
|
aliases = ["drawgiftid"]
|
||||||
|
|
||||||
|
description: str = "Estrai un regalo con un certo id."
|
||||||
|
|
||||||
|
syntax: str = "{id}"
|
||||||
|
|
||||||
|
async def _get_gift(self, args, data):
|
||||||
|
return data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False, gift_id=int(args[0])).order_by(func.random()).first()
|
18
giftpack/commands/getgiftsrc.py
Normal file
18
giftpack/commands/getgiftsrc.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from .getgift import GetgiftCommand
|
||||||
|
from ..tables import XmasGift
|
||||||
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
|
||||||
|
class GetgiftsrcCommand(GetgiftCommand):
|
||||||
|
name: str = "getgiftsrc"
|
||||||
|
|
||||||
|
aliases = ["drawgiftsrc"]
|
||||||
|
|
||||||
|
description: str = "Estrai un regalo con un certo mittente."
|
||||||
|
|
||||||
|
syntax: str = "{mittente}"
|
||||||
|
|
||||||
|
async def _get_gift(self, args, data):
|
||||||
|
return data.session.query(self.alchemy.get(XmasGift)).filter_by(drawn=False, source=args[0]).order_by(func.random()).first()
|
19
giftpack/commands/listgifts.py
Normal file
19
giftpack/commands/listgifts.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from typing import *
|
||||||
|
from royalnet.commands import *
|
||||||
|
from ..tables import XmasGift
|
||||||
|
|
||||||
|
|
||||||
|
class ListgiftsCommand(Command):
|
||||||
|
name: str = "listgifts"
|
||||||
|
|
||||||
|
aliases = ["listgift"]
|
||||||
|
|
||||||
|
description: str = "Elenca tutti i regali registrati."
|
||||||
|
|
||||||
|
syntax: str = ""
|
||||||
|
|
||||||
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
|
gifts = data.session.query(self.alchemy.get(XmasGift)).all()
|
||||||
|
msg = "🎁 Elenco regali:\n"
|
||||||
|
gift_msg = "\n".join([str(gift) for gift in gifts])
|
||||||
|
await data.reply(msg + gift_msg)
|
|
@ -1,11 +1,8 @@
|
||||||
# Imports go here!
|
# Imports go here!
|
||||||
# TODO: If you create a new event, remember to import it here...
|
|
||||||
from .example import ExampleEvent
|
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
# TODO: and add it to the list here!
|
|
||||||
available_events = [
|
available_events = [
|
||||||
ExampleEvent,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
|
@ -1,18 +1,13 @@
|
||||||
# Imports go here!
|
# Imports go here!
|
||||||
# TODO: If you create a new star, remember to import it here...
|
|
||||||
from .api_example import ApiExampleStar
|
|
||||||
from .api_excsample import ApiExcsampleStar
|
|
||||||
|
|
||||||
# Enter the PageStars of your Pack here!
|
# Enter the PageStars of your Pack here!
|
||||||
# TODO: and to add it either to the list here if it is a PageStar...
|
|
||||||
available_page_stars = [
|
available_page_stars = [
|
||||||
ApiExampleStar,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Enter the ExceptionStars of your Pack here!
|
# Enter the ExceptionStars of your Pack here!
|
||||||
# TODO: or to the list here if it is an ExceptionStar!
|
|
||||||
available_exception_stars = [
|
available_exception_stars = [
|
||||||
ApiExcsampleStar,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
|
@ -1,9 +1,9 @@
|
||||||
# Imports go here!
|
# Imports go here!
|
||||||
|
from .xmasgift import XmasGift
|
||||||
|
|
||||||
# Enter the tables of your Pack here!
|
# Enter the tables of your Pack here!
|
||||||
available_tables = [
|
available_tables = [
|
||||||
|
XmasGift,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
34
giftpack/tables/xmasgift.py
Normal file
34
giftpack/tables/xmasgift.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
from sqlalchemy import *
|
||||||
|
from sqlalchemy.orm import *
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
|
||||||
|
|
||||||
|
class XmasGift:
|
||||||
|
__tablename__ = "xmasgifts"
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def gift_id(self):
|
||||||
|
return Column(Integer, primary_key=True)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def source(self):
|
||||||
|
return Column(String, nullable=False)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def destination(self):
|
||||||
|
return Column(String, nullable=False)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def extra_text(self):
|
||||||
|
return Column(String, nullable=False, default="")
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def drawn(self):
|
||||||
|
return Column(Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
msg = f"Regalo #{self.gift_id} da {self.source} a {self.destination}" + f": {self.extra_text}" if self.extra_text else ""
|
||||||
|
if self.drawn:
|
||||||
|
return f"⚫️ {msg}"
|
||||||
|
else:
|
||||||
|
return f"🔵 [b]{msg}[/b]"
|
1
giftpack/version.py
Normal file
1
giftpack/version.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
semantic = "1.0"
|
1105
poetry.lock
generated
Normal file
1105
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,12 @@
|
||||||
# Remember to run `poetry update` after you edit this file!
|
# Remember to run `poetry update` after you edit this file!
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
# TODO: Insert here your Pack name!
|
name = "giftpack"
|
||||||
name = "examplepack"
|
description = "A pack for the gift drawing at the Xmas 2019 family lunch"
|
||||||
# TODO: Insert here your Pack description!
|
version = "1.0"
|
||||||
description = "An example pack for Royalnet."
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
# TODO: Increment this every new version of your pack!
|
license = "AGPL-3.0+"
|
||||||
version = "0.1.0"
|
homepage = "https://github.com/Steffo99/giftpack"
|
||||||
# TODO: Set this to your full name and email!
|
|
||||||
authors = ["Name Surname <email@example.com>"]
|
|
||||||
# TODO: Set this to the license you want to use for your Pack!
|
|
||||||
license = ""
|
|
||||||
# TODO: Set this to the GitHub page of your pack (or another website)
|
|
||||||
homepage = "https://github.com/your-username/"
|
|
||||||
# TODO: Set this to a link to the Pack documentation (if there's any)
|
|
||||||
documentation = "https://gh.steffo.eu/royalpack/"
|
|
||||||
# TODO: Pick some classifiers to include your Pack in: https://pypi.org/classifiers/
|
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 3 - Alpha",
|
"Development Status :: 3 - Alpha",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
|
@ -29,11 +20,12 @@
|
||||||
python = "^3.8"
|
python = "^3.8"
|
||||||
|
|
||||||
[tool.poetry.dependencies.royalnet]
|
[tool.poetry.dependencies.royalnet]
|
||||||
version = "^5.1.6"
|
version = "^5.2"
|
||||||
# There will soon be a way to make all these optional
|
# There will soon be a way to make all these optional
|
||||||
extras = [
|
extras = [
|
||||||
"telegram",
|
"telegram",
|
||||||
"discord",
|
"discord",
|
||||||
|
"matrix",
|
||||||
"alchemy_easy",
|
"alchemy_easy",
|
||||||
"bard",
|
"bard",
|
||||||
"constellation",
|
"constellation",
|
||||||
|
|
Loading…
Reference in a new issue