diff --git a/.gitignore b/.gitignore index 68d69529..15ca555d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,31 @@ -config.ini -.idea/ -.vscode/ -__pycache__ -*.egg-info/ -.pytest_cache/ +# Royalnet ignores +config*.toml +downloads/ + + +# Python ignores +**/__pycache__/ dist/ -build/ -venv/ +*.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 \ No newline at end of file diff --git a/README.md b/README.md index 6fae0ea8..419c10fa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,21 @@ -# `{packname}` [![PyPI](https://img.shields.io/pypi/v/{packname}.svg)](https://pypi.org/project/{packname}/) +# `keipack` [![PyPI](https://img.shields.io/pypi/v/keipack.svg)](https://pypi.org/project/keipack/) -{Replace everything surrounded by braces with your own data, including this description!} +## Emotions -{Files to be changed are the package folder, setup.py, to_pypi.sh and this README!} +- ![](./media/cat.png) cat +- ![](./media/cry.png) cry +- ![](./media/disappointed.png) disappointed +- ![](./media/dootflute.png) dootflute +- ![](./media/doottrumpet.png) doottrumpet +- ![](./media/grin.png) grin +- ![](./media/halflife.png) halflife +- ![](./media/happy.png) happy +- ![](./media/key.png) key +- ![](./media/keyface.png) keyface +- ![](./media/neutral.png) neutral +- ![](./media/question.png) question +- ![](./media/smug.png) smug +- ![](./media/surprised.png) surprised +- ![](./media/wink.png) wink +- ![](./media/worried.png) worried +- ![](./media/x.png) x \ No newline at end of file diff --git a/keipack/stars/api_kei.py b/keipack/stars/api_kei.py index 55fa7335..c1e15a79 100644 --- a/keipack/stars/api_kei.py +++ b/keipack/stars/api_kei.py @@ -1,18 +1,26 @@ +import random +import datetime +from typing import * from starlette.requests import Request from starlette.responses import * -from royalnet.web import * +from royalnet.constellation import * from royalnet.utils import * -import royalnet.packs.common.tables as cpt -import royalpack.tables as rpt class ApiKei(PageStar): path = "/api/kei" - tables = {} - - async def _generate(self, request: Request, session) -> typing.Tuple[str, str]: - return "happy", "Ciao!" + async def _generate(self, request, session) -> Tuple[str, str]: + if request.query_params.get("first", "false") == "true": + return random.sample([ + ("happy", "Ciao!"), + ("question", "Come va?"), + ("happy", "Sono al tuo servizio!"), + ("happy", "Attendo ordini!"), + ("happy", "Attendo ordini!"), + ("cat", "Mandami un messaggio :3"), + ], 1)[0] + return "x", "MISSINGNO." async def page(self, request: Request) -> JSONResponse: async with self.session_acm() as session: diff --git a/keipack/tables/keipeople.py b/keipack/tables/keipeople.py new file mode 100644 index 00000000..a26f52fd --- /dev/null +++ b/keipack/tables/keipeople.py @@ -0,0 +1,19 @@ +from sqlalchemy import * +from sqlalchemy.orm import relationship +from sqlalchemy.ext.declarative import declared_attr + + +class KeiPerson: + __tablename__ = "keipeople" + + @declared_attr + def user_id(self): + return Column(Integer, ForeignKey("users.uid"), primary_key=True) + + @declared_attr + def user(self): + return relationship("User", foreign_keys=self.user_id, backref="kei_people") + + @declared_attr + def game_id(self): + return Column(String, unique=True, primary_key=True) diff --git a/media/cat.png b/media/cat.png new file mode 100644 index 00000000..fe59c62b Binary files /dev/null and b/media/cat.png differ diff --git a/media/cry.png b/media/cry.png new file mode 100644 index 00000000..fa90c179 Binary files /dev/null and b/media/cry.png differ diff --git a/media/disappointed.png b/media/disappointed.png new file mode 100644 index 00000000..5b521b4d Binary files /dev/null and b/media/disappointed.png differ diff --git a/media/dootflute.png b/media/dootflute.png new file mode 100644 index 00000000..6269673a Binary files /dev/null and b/media/dootflute.png differ diff --git a/media/doottrumpet.png b/media/doottrumpet.png new file mode 100644 index 00000000..a88e0147 Binary files /dev/null and b/media/doottrumpet.png differ diff --git a/media/grin.png b/media/grin.png new file mode 100644 index 00000000..6c35a5fe Binary files /dev/null and b/media/grin.png differ diff --git a/media/halflife.png b/media/halflife.png new file mode 100644 index 00000000..38fb3b43 Binary files /dev/null and b/media/halflife.png differ diff --git a/media/happy.png b/media/happy.png new file mode 100644 index 00000000..58c0113e Binary files /dev/null and b/media/happy.png differ diff --git a/media/key.png b/media/key.png new file mode 100644 index 00000000..a43eda5c Binary files /dev/null and b/media/key.png differ diff --git a/media/keyface.png b/media/keyface.png new file mode 100644 index 00000000..c3b66ec7 Binary files /dev/null and b/media/keyface.png differ diff --git a/media/neutral.png b/media/neutral.png new file mode 100644 index 00000000..ed898720 Binary files /dev/null and b/media/neutral.png differ diff --git a/media/question.png b/media/question.png new file mode 100644 index 00000000..cdc2e829 Binary files /dev/null and b/media/question.png differ diff --git a/media/smug.png b/media/smug.png new file mode 100644 index 00000000..c0ffa853 Binary files /dev/null and b/media/smug.png differ diff --git a/media/surprised.png b/media/surprised.png new file mode 100644 index 00000000..727d39d5 Binary files /dev/null and b/media/surprised.png differ diff --git a/media/wink.png b/media/wink.png new file mode 100644 index 00000000..a4edeb13 Binary files /dev/null and b/media/wink.png differ diff --git a/media/worried.png b/media/worried.png new file mode 100644 index 00000000..cec08164 Binary files /dev/null and b/media/worried.png differ diff --git a/media/x.png b/media/x.png new file mode 100644 index 00000000..c9074ff3 Binary files /dev/null and b/media/x.png differ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..69d8ba48 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,51 @@ +# Remember to run `poetry update` after you edit this file! + +[tool.poetry] + name = "keipack" + version = "5.1a1" + description = "A mysterious AI assistant" + authors = ["Stefano Pigozzi "] + license = "AGPL-3.0+" + readme = "README.md" + homepage = "https://github.com/Steffo99/keipack" + 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+)" + ] + +# Library dependencies +[tool.poetry.dependencies] + python = "^3.8" + + riotwatcher = "^2.7.1" + + [tool.poetry.dependencies.royalnet] + git = "https://github.com/Steffo99/royalnet/" + # Maybe... there is a way to make these selectable? + extras = [ + "telegram", + "discord", + "alchemy_easy", + "bard", + "constellation", + "sentry", + "herald", + "coloredlogs" + ] + +# Development dependencies +[tool.poetry.dev-dependencies] + + + +# Optional dependencies +[tool.poetry.extras] + + + + +[build-system] + requires = ["poetry>=0.12"] + build-backend = "poetry.masonry.api" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index faa4e12f..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -starlette -royalnet -royalpack \ No newline at end of file diff --git a/sample_config.toml b/sample_config.toml new file mode 100644 index 00000000..fc2feb99 --- /dev/null +++ b/sample_config.toml @@ -0,0 +1,112 @@ +# ROYALNET CONFIGURATION FILE + +[Herald] +# Enable the herald module, allowing different parts of Royalnet to talk to each other +# Requires the `herald` extra to be installed +enabled = true + +[Herald.Local] +# Run locally a Herald web server (websocket) that other parts of Royalnet can connect to +enabled = true +# The address of the network interface on which the Herald server should listen for connections +# If 0.0.0.0, listen for connections on all interfaces +# If 127.0.0.1, listen only for connections coming from the local machine +address = "0.0.0.0" +# The port on which the Herald server should run +port = 44444 +# A password required to connect to the local Herald server +secret = "CHANGE-ME" +# Use HTTPS instead of HTTP for Herald connections +secure = false # Not supported yet! +# Use a different HTTP path for Herald connections +path = "/" # Different values aren't supported yet + +[Herald.Remote] +# Connect to a remote Herald web server (websocket) +# Requires the `herald` extra to be installed +enabled = false +# The address of the remote Herald server +address = "0.0.0.0" +# The port of the remote Herald server +port = 44444 +# The password required to connect to the remote Herald server +secret = "CHANGE-ME" +# Use HTTPS instead of HTTP for Herald connections +secure = false # Not supported yet! +# Use a different HTTP path for Herald connections +path = "/" # Different values aren't supported yet + + +[Alchemy] +# Use the Alchemy module of Royalnet to connect to a PostgreSQL server +# Requires either the `alchemy_easy` or the `alchemy_hard` extras to be installed +enabled = true +# The URL of the database you want to connect to, in sqlalchemy format: +# https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls +database_url = "postgresql://username:password@host:port/database" + +[Constellation] +# Run locally a Constellation web server (uvicorn+starlette) serving the Stars contained in the enabled Packs +# Requires the `constellation` extra to be installed +enabled = true +# The address of the network interface on which the Constellation should listen for requests +# If 0.0.0.0, listen for requests on all interfaces +# If 127.0.0.1, listen only for requests coming from the local machine +address = "0.0.0.0" +# The port on which the Constellation should run +port = 44445 + +[Serfs] + +[Serfs.Telegram] +# Use the Telegram Serf (python-telegram-bot) included in Royalnet +# Requires the `telegram` extra to be installed +enabled = true +# The Bot API Token of the bot you want to use for Royalnet +# Obtain one at https://t.me/BotFather +token = "0000000000:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +# The size of the Connection Pool used by python-telegram-bot +# 8 should be fine, but if you start getting `TimeoutError: QueuePool limit of size X overflow Y reached" errors, +# increasing this number should fix them +pool_size = 8 +# The maximum amount of time to wait for a response from Telegram before raising a `TimeoutError` +# It also is the time that python-telegram-bot will wait before sending a new request if no updates are being received. +read_timeout = 60 + +[Serfs.Discord] +# Use the Discord Serf (discord.py) included in Royalnet +# Requires the `discord` extra to be installed +enabled = true +# The Discord Bot Token of the bot you want to use for Royalnet +# Obtain one at https://discordapp.com/developers/applications/ > Bot > Token +token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + +[Logging] +# Print to stderr all logging events of an equal or greater level than this +# Possible values are "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" +log_level = "INFO" +# Optional: install the `coloredlogs` extra for colored output! + +[Sentry] +# Connect Royalnet to a https://sentry.io/ project for error logging +# Requires the `sentry` extra to be installed +enabled = false +# Get one at https://sentry.io/settings/YOUR-ORG/projects/YOUR-PROJECT/keys/ +dsn = "https://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@sentry.io/1111111" + +[Packs] +# The Python package name of the Packs you want to be usable in Royalnet +# Please note that the `royalnet.backpack` Pack should always be available! +active = [ + "royalnet.backpack", # DO NOT REMOVE THIS OR THINGS WILL BREAK + # "yourpack", + +] + +# Configuration settings for specific packs +[Packs."royalnet.backpack"] +# Enable exception debug commands and stars +exc_debug = false + +# Add your packs config here! +# [Packs."yourpack"] diff --git a/setup.py b/setup.py deleted file mode 100644 index ea6869cf..00000000 --- a/setup.py +++ /dev/null @@ -1,24 +0,0 @@ -import setuptools - -with open("README.md", "r") as f: - long_description = f.read() - -with open("requirements.txt", "r") as f: - install_requires = f.readlines() - -setuptools.setup( - name="keipack", - version="0.1", - author="Stefano Pigozzi", - author_email="ste.pigozzi@gmail.com", - description="A mysterious AI assistant", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/Steffo99/keipack", - packages=setuptools.find_packages(), - install_requires=install_requires, - python_requires=">=3.7", - classifiers=[ - "Programming Language :: Python :: 3.7", - ], -) diff --git a/to_pypi.bat b/to_pypi.bat deleted file mode 100644 index beb035bc..00000000 --- a/to_pypi.bat +++ /dev/null @@ -1,3 +0,0 @@ -del /f /q /s dist\*.* -python setup.py sdist bdist_wheel -twine upload dist/* diff --git a/to_pypi.sh b/to_pypi.sh deleted file mode 100644 index 253edea9..00000000 --- a/to_pypi.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# Set me to your pack name! -PACKNAME="{packname}" - -# Royalnet must be installed with `develop` -VERSION=$(python3.7 -m "$PACKNAME.version") - -rm -rf dist -python setup.py sdist bdist_wheel -twine upload "dist/$PACKNAME-$VERSION"* -git add * -git commit -m "$VERSION" -git push -hub release create --message "Version $VERSION" --prerelease "$VERSION"