From 363ce6373c9a970d7980c2c76800ddff8b658a1b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 25 Dec 2019 01:47:10 +0100 Subject: [PATCH] Initial commit --- .gitignore | 31 ++++++++++++++++ README.md | 5 +++ examplepack/__init__.py | 21 +++++++++++ examplepack/commands/__init__.py | 12 +++++++ examplepack/commands/example.py | 12 +++++++ examplepack/events/__init__.py | 12 +++++++ examplepack/events/example.py | 10 ++++++ examplepack/stars/__init__.py | 19 ++++++++++ examplepack/stars/api_example.py | 13 +++++++ examplepack/stars/api_excsample.py | 13 +++++++ examplepack/tables/__init__.py | 10 ++++++ examplepack/tables/example.py | 19 ++++++++++ examplepack/version.py | 2 ++ pyproject.toml | 58 ++++++++++++++++++++++++++++++ 14 files changed, 237 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 examplepack/__init__.py create mode 100644 examplepack/commands/__init__.py create mode 100644 examplepack/commands/example.py create mode 100644 examplepack/events/__init__.py create mode 100644 examplepack/events/example.py create mode 100644 examplepack/stars/__init__.py create mode 100644 examplepack/stars/api_example.py create mode 100644 examplepack/stars/api_excsample.py create mode 100644 examplepack/tables/__init__.py create mode 100644 examplepack/tables/example.py create mode 100644 examplepack/version.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..94fa4627 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Royalnet ignores +config*.toml +downloads/ + + +# Python ignores +**/__pycache__/ +dist/ +*.egg-info/ +**/*.pyc + +# PyCharm ignores +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/**/contentModel.xml +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml +.idea/**/gradle.xml +.idea/**/libraries +.idea/**/markdown-navigator.xml +.idea/**/markdown-exported-files.xml +.idea/**/misc.xml +.idea/**/*.iml diff --git a/README.md b/README.md new file mode 100644 index 00000000..a988ebbf --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# `examplepack` + +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. \ No newline at end of file diff --git a/examplepack/__init__.py b/examplepack/__init__.py new file mode 100644 index 00000000..9c85d34a --- /dev/null +++ b/examplepack/__init__.py @@ -0,0 +1,21 @@ +# This file should not need to be changed. + +from . import commands, tables, stars, events +from .commands import available_commands +from .tables import available_tables +from .stars import available_page_stars, available_exception_stars +from .events import available_events + +from .version import semantic as __version__ + +__all__ = [ + "commands", + "tables", + "stars", + "events", + "available_commands", + "available_tables", + "available_page_stars", + "available_exception_stars", + "available_events", +] diff --git a/examplepack/commands/__init__.py b/examplepack/commands/__init__.py new file mode 100644 index 00000000..67974f3a --- /dev/null +++ b/examplepack/commands/__init__.py @@ -0,0 +1,12 @@ +# 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] diff --git a/examplepack/commands/example.py b/examplepack/commands/example.py new file mode 100644 index 00000000..f98652ba --- /dev/null +++ b/examplepack/commands/example.py @@ -0,0 +1,12 @@ +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!") diff --git a/examplepack/events/__init__.py b/examplepack/events/__init__.py new file mode 100644 index 00000000..365089ad --- /dev/null +++ b/examplepack/events/__init__.py @@ -0,0 +1,12 @@ +# 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! +# TODO: and add it to the list here! +available_events = [ + ExampleEvent, +] + +# Don't change this, it should automatically generate __all__ +__all__ = [command.__name__ for command in available_events] diff --git a/examplepack/events/example.py b/examplepack/events/example.py new file mode 100644 index 00000000..866abc7a --- /dev/null +++ b/examplepack/events/example.py @@ -0,0 +1,10 @@ +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"} diff --git a/examplepack/stars/__init__.py b/examplepack/stars/__init__.py new file mode 100644 index 00000000..3e6db09c --- /dev/null +++ b/examplepack/stars/__init__.py @@ -0,0 +1,19 @@ +# 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! +# TODO: and to add it either to the list here if it is a PageStar... +available_page_stars = [ + ApiExampleStar, +] + +# Enter the ExceptionStars of your Pack here! +# TODO: or to the list here if it is an ExceptionStar! +available_exception_stars = [ + ApiExcsampleStar, +] + +# Don't change this, it should automatically generate __all__ +__all__ = [command.__name__ for command in [*available_page_stars, *available_exception_stars]] diff --git a/examplepack/stars/api_example.py b/examplepack/stars/api_example.py new file mode 100644 index 00000000..229552bd --- /dev/null +++ b/examplepack/stars/api_example.py @@ -0,0 +1,13 @@ +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", + }) diff --git a/examplepack/stars/api_excsample.py b/examplepack/stars/api_excsample.py new file mode 100644 index 00000000..ef028bed --- /dev/null +++ b/examplepack/stars/api_excsample.py @@ -0,0 +1,13 @@ +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", + }) diff --git a/examplepack/tables/__init__.py b/examplepack/tables/__init__.py new file mode 100644 index 00000000..961c34f9 --- /dev/null +++ b/examplepack/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.__name__ for table in available_tables] diff --git a/examplepack/tables/example.py b/examplepack/tables/example.py new file mode 100644 index 00000000..83078e7e --- /dev/null +++ b/examplepack/tables/example.py @@ -0,0 +1,19 @@ +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!") diff --git a/examplepack/version.py b/examplepack/version.py new file mode 100644 index 00000000..422feb95 --- /dev/null +++ b/examplepack/version.py @@ -0,0 +1,2 @@ +# TODO: Increment this every new version of your pack! +semantic = "0.1.0" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..5cf844df --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,58 @@ +# Remember to run `poetry update` after you edit this file! + +[tool.poetry] + # TODO: Insert here your Pack name! + name = "examplepack" + # TODO: Insert here your Pack description! + description = "An example pack for Royalnet." + # TODO: Increment this every new version of your pack! + version = "0.1.0" + # TODO: Set this to your full name and email! + authors = ["Name Surname "] + # 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 = [ + "Development Status :: 3 - Alpha", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3.8", + "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)" + ] + readme = "README.md" + +# Library dependencies +[tool.poetry.dependencies] + python = "^3.8" + + [tool.poetry.dependencies.royalnet] + version = "^5.1.6" + # There will soon be a way to make all these optional + extras = [ + "telegram", + "discord", + "alchemy_easy", + "bard", + "constellation", + "sentry", + "herald", + "coloredlogs" + ] + +# Development dependencies +[tool.poetry.dev-dependencies] + + + +# Optional dependencies +[tool.poetry.extras] + + +# Poetry stuff +# Leave it alone! +[build-system] + requires = ["poetry>=0.12"] + build-backend = "poetry.masonry.api"