From 948942fdf26d1fb217ddb0d9a757188380d66330 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Thu, 11 May 2023 20:19:46 +0200 Subject: [PATCH] Created initial version --- .gitignore | 6 ++++++ .renovaterc | 17 +++++++++++++++++ libbot/__init__.py | 7 +++++++ libbot/__main__.py | 35 +++++++++++++++++++++++++++++++++++ libbot/sync/__init__.py | 35 +++++++++++++++++++++++++++++++++++ setup.cfg | 3 +++ setup.py | 31 +++++++++++++++++++++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 .renovaterc create mode 100644 libbot/__init__.py create mode 100644 libbot/__main__.py create mode 100644 libbot/sync/__init__.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 5d381cc..3f61a60 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,9 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +# Project +venv +venv_linux +venv_windows + +.vscode \ No newline at end of file diff --git a/.renovaterc b/.renovaterc new file mode 100644 index 0000000..b92ac58 --- /dev/null +++ b/.renovaterc @@ -0,0 +1,17 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ], + "packageRules": [ + { + "matchUpdateTypes": [ + "minor", + "patch", + "pin", + "digest" + ], + "automerge": true + } + ] +} \ No newline at end of file diff --git a/libbot/__init__.py b/libbot/__init__.py new file mode 100644 index 0000000..cf6d203 --- /dev/null +++ b/libbot/__init__.py @@ -0,0 +1,7 @@ +__name__ = "libbot" +__version__ = "0.1" +__license__ = "GPL3" +__author__ = "Profitroll" + +from .__main__ import * +from . import sync diff --git a/libbot/__main__.py b/libbot/__main__.py new file mode 100644 index 0000000..5739e27 --- /dev/null +++ b/libbot/__main__.py @@ -0,0 +1,35 @@ +from typing import Any +import aiofiles +from ujson import loads, dumps + + +async def json_read(path: str) -> Any: + async with aiofiles.open(path, mode="r", encoding="utf-8") as f: + data = await f.read() + return loads(data) + + +async def json_write(data: Any, path: str) -> None: + async with aiofiles.open(path, mode="w", encoding="utf-8") as f: + await f.write(dumps(data, ensure_ascii=False, escape_forward_slashes=False)) + + +async def config_get(key: str, *path: str) -> Any: + this_key = await json_read("config.json") + for dict_key in path: + this_key = this_key[dict_key] + return this_key[key] + + +async def config_set(key: str, value: Any, *path: str) -> None: + this_dict = await json_read("config.json") + string = "this_dict" + for arg in path: + string += f'["{arg}"]' + if type(value) in [str]: + string += f'["{key}"] = "{value}"' + else: + string += f'["{key}"] = {value}' + exec(string) + await json_write(this_dict, "config.json") + return diff --git a/libbot/sync/__init__.py b/libbot/sync/__init__.py new file mode 100644 index 0000000..01b70eb --- /dev/null +++ b/libbot/sync/__init__.py @@ -0,0 +1,35 @@ +from typing import Any + +from ujson import dumps, loads + + +def json_read(path: str) -> Any: + with open(path, mode="r", encoding="utf-8") as f: + data = f.read() + return loads(data) + + +def json_write(data: Any, path: str) -> None: + with open(path, mode="w", encoding="utf-8") as f: + f.write(dumps(data, ensure_ascii=False, escape_forward_slashes=False, indent=4)) + + +def config_get(key: str, *path: str) -> Any: + this_key = json_read("config.json") + for dict_key in path: + this_key = this_key[dict_key] + return this_key[key] + + +def config_set(key: str, value: Any, *path: str) -> None: + this_dict = json_read("config.json") + string = "this_dict" + for arg in path: + string += f'["{arg}"]' + if type(value) in [str]: + string += f'["{key}"] = "{value}"' + else: + string += f'["{key}"] = {value}' + exec(string) + json_write(this_dict, "config.json") + return diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..fe869c8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[metadata] +description_file=README.md +license_files=LICENSE \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5ed0139 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +from setuptools import setup + +setup( + name="libbot", + version="0.1", + author="Profitroll", + description="Universal bot library with functions needed for basic Discord/Telegram bot development.", + long_description="Universal bot library with functions needed for basic Discord/Telegram bot development.", + long_description_content_type="text/markdown", + author_email="profitroll@end-play.xyz", + url="https://git.end-play.xyz/profitroll/LibBotUniversal", + project_urls={ + "Bug Tracker": "https://git.end-play.xyz/profitroll/LibBotUniversal/issues", + "Documentation": "https://git.end-play.xyz/profitroll/LibBotUniversal/wiki", + "Source Code": "https://git.end-play.xyz/profitroll/LibBotUniversal.git", + }, + packages=[ + "libbot", + "libbot.sync", + ], + install_requires=["aiofiles~=23.1.0", "ujson==5.7.0"], + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Utilities", + ], +)