Compare commits
6 Commits
a47a508ecf
...
v3.2.1
Author | SHA1 | Date | |
---|---|---|---|
748b2b2abb | |||
52c2e5cc13 | |||
55c61e3fce | |||
b9550032ba | |||
5ba763246b | |||
f0ffdf096d |
@@ -1,24 +0,0 @@
|
||||
name: Analysis
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
sonarcloud:
|
||||
name: SonarCloud
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: SonarCloud Scan
|
||||
uses: SonarSource/sonarcloud-github-action@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
@@ -10,12 +10,11 @@ on:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
||||
python-version: ["3.8", "3.9", "3.10", "3.11"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -36,4 +35,4 @@ jobs:
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Artifacts
|
||||
path: dist/*
|
||||
path: dist/*
|
||||
|
@@ -8,17 +8,17 @@ dynamic = ["version", "dependencies", "optional-dependencies"]
|
||||
authors = [{ name = "Profitroll" }]
|
||||
description = "Universal bot library with functions needed for basic Discord/Telegram bot development."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.9"
|
||||
requires-python = ">=3.8"
|
||||
license = { text = "GPLv3" }
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
"Topic :: Utilities",
|
||||
]
|
||||
@@ -42,7 +42,7 @@ Tracker = "https://git.end-play.xyz/profitroll/LibBotUniversal/issues"
|
||||
where = ["src"]
|
||||
|
||||
[tool.black]
|
||||
target-version = ['py39', 'py310', 'py311' ,'py312']
|
||||
target-version = ['py38', 'py39', 'py310', 'py311']
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
@@ -61,7 +61,7 @@ show_error_codes = true
|
||||
|
||||
[tool.pylint.main]
|
||||
extension-pkg-whitelist = ["ujson"]
|
||||
py-version = 3.9
|
||||
py-version = 3.8
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["libbot"]
|
||||
|
@@ -1,11 +1,11 @@
|
||||
black==24.10.0
|
||||
build==1.2.2.post1
|
||||
black==24.4.2
|
||||
build==1.2.1
|
||||
isort==5.13.2
|
||||
mypy==1.14.0
|
||||
pylint==3.3.3
|
||||
pytest-asyncio==0.25.0
|
||||
pytest-cov==6.0.0
|
||||
pytest==8.3.4
|
||||
tox==4.23.2
|
||||
types-aiofiles==24.1.0.20241221
|
||||
mypy==1.10.0
|
||||
pylint==3.2.2
|
||||
pytest-asyncio==0.23.7
|
||||
pytest-cov==5.0.0
|
||||
pytest==8.2.1
|
||||
tox==4.15.0
|
||||
types-aiofiles==23.2.0.20240403
|
||||
types-ujson==5.10.0.20240515
|
@@ -1,2 +1,2 @@
|
||||
apscheduler~=3.11.0
|
||||
py-cord~=2.6.0
|
||||
apscheduler~=3.10.4
|
||||
py-cord~=2.5.0
|
@@ -1,2 +1,2 @@
|
||||
apscheduler~=3.11.0
|
||||
pyrofork~=2.3.32
|
||||
apscheduler~=3.10.4
|
||||
pyrofork~=2.3.21.post3
|
@@ -1,2 +0,0 @@
|
||||
sonar.projectKey=profitroll_libbot
|
||||
sonar.organization=profitroll
|
@@ -1,4 +1,4 @@
|
||||
__version__ = "3.3.1"
|
||||
__version__ = "3.2.1"
|
||||
__license__ = "GPL3"
|
||||
__author__ = "Profitroll"
|
||||
|
||||
|
@@ -8,11 +8,8 @@ try:
|
||||
except ImportError:
|
||||
from json import dumps, loads
|
||||
|
||||
from ._utils import supports_argument
|
||||
from .sync._nested import nested_delete, nested_set
|
||||
|
||||
DEFAULT_CONFIG_LOCATION: str = "config.json"
|
||||
|
||||
|
||||
async def json_read(path: Union[str, Path]) -> Any:
|
||||
"""Read contents of a JSON file
|
||||
@@ -39,13 +36,13 @@ async def json_write(data: Any, path: Union[str, Path]) -> None:
|
||||
async with aiofiles.open(str(path), mode="w", encoding="utf-8") as f:
|
||||
await f.write(
|
||||
dumps(data, ensure_ascii=False, escape_forward_slashes=False, indent=4)
|
||||
if supports_argument(dumps, "escape_forward_slashes")
|
||||
if hasattr(dumps, "escape_forward_slashes")
|
||||
else dumps(data, ensure_ascii=False, indent=4)
|
||||
)
|
||||
|
||||
|
||||
async def config_get(
|
||||
key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
key: str, *path: str, config_file: Union[str, Path] = "config.json"
|
||||
) -> Any:
|
||||
"""Get a value of the config key by its path provided
|
||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||
@@ -85,7 +82,7 @@ async def config_get(
|
||||
|
||||
|
||||
async def config_set(
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json"
|
||||
) -> None:
|
||||
"""Set config's key by its path to the value
|
||||
|
||||
@@ -101,13 +98,14 @@ async def config_set(
|
||||
await json_write(
|
||||
nested_set(await json_read(config_file), value, *(*path, key)), config_file
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
async def config_delete(
|
||||
key: str,
|
||||
*path: str,
|
||||
missing_ok: bool = False,
|
||||
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||
config_file: Union[str, Path] = "config.json",
|
||||
) -> None:
|
||||
"""Set config's key by its path
|
||||
|
||||
|
@@ -1,22 +0,0 @@
|
||||
import inspect
|
||||
from typing import Callable
|
||||
|
||||
|
||||
def supports_argument(func: Callable, arg_name: str) -> bool:
|
||||
"""Check whether a function has a specific argument
|
||||
|
||||
### Args:
|
||||
* func (`Callable`): Function to be inspected
|
||||
* arg_name (`str`): Argument to be checked
|
||||
|
||||
### Returns:
|
||||
* `bool`: `True` if argument is supported and `False` if not
|
||||
"""
|
||||
if hasattr(func, "__code__"):
|
||||
return arg_name in inspect.signature(func).parameters
|
||||
elif hasattr(func, "__doc__"):
|
||||
if doc := func.__doc__:
|
||||
first_line = doc.splitlines()[0]
|
||||
return arg_name in first_line
|
||||
|
||||
return False
|
@@ -59,15 +59,3 @@ class PycordBot(Bot):
|
||||
self.in_every_locale = self.bot_locale.in_every_locale
|
||||
|
||||
self.scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = scheduler
|
||||
|
||||
async def start(self, token: str, reconnect: bool = True, scheduler_start: bool = True) -> None:
|
||||
if self.scheduler is not None and scheduler_start:
|
||||
self.scheduler.start()
|
||||
|
||||
await super().start(token, reconnect=reconnect)
|
||||
|
||||
async def close(self, scheduler_shutdown: bool = True, scheduler_wait: bool = True) -> None:
|
||||
if self.scheduler is not None and scheduler_shutdown:
|
||||
self.scheduler.shutdown(scheduler_wait)
|
||||
|
||||
await super().close()
|
||||
|
@@ -125,7 +125,7 @@ class PyroClient(Client):
|
||||
|
||||
self.i18n_bot_info: bool = i18n_bot_info
|
||||
|
||||
async def start(self, register_commands: bool = True, scheduler_start: bool = True) -> None:
|
||||
async def start(self, register_commands: bool = True) -> None:
|
||||
await super().start()
|
||||
|
||||
self.start_time = time()
|
||||
@@ -209,12 +209,9 @@ class PyroClient(Client):
|
||||
kwargs={"command_sets": await self.collect_commands()},
|
||||
)
|
||||
|
||||
if scheduler_start:
|
||||
self.scheduler.start()
|
||||
self.scheduler.start()
|
||||
|
||||
async def stop(
|
||||
self, exit_completely: bool = True, scheduler_shutdown: bool = True, scheduler_wait: bool = True
|
||||
) -> None:
|
||||
async def stop(self, exit_completely: bool = True) -> None:
|
||||
try:
|
||||
await self.send_message(
|
||||
chat_id=self.owner
|
||||
@@ -226,9 +223,6 @@ class PyroClient(Client):
|
||||
except BadRequest:
|
||||
logger.warning("Unable to send message to report chat.")
|
||||
|
||||
if self.scheduler is not None and scheduler_shutdown:
|
||||
self.scheduler.shutdown(scheduler_wait)
|
||||
|
||||
await super().stop()
|
||||
logger.warning("Bot stopped with PID %s.", getpid())
|
||||
|
||||
@@ -364,8 +358,7 @@ class PyroClient(Client):
|
||||
]
|
||||
|
||||
logger.info(
|
||||
"Registering commands %s with a default scope 'BotCommandScopeDefault'",
|
||||
commands
|
||||
"Registering commands %s with a default scope 'BotCommandScopeDefault'"
|
||||
)
|
||||
|
||||
await self.set_bot_commands(commands)
|
||||
|
@@ -1,7 +1,6 @@
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
from .._utils import supports_argument
|
||||
from ._nested import nested_delete, nested_set
|
||||
|
||||
try:
|
||||
@@ -9,8 +8,6 @@ try:
|
||||
except ImportError:
|
||||
from json import dumps, loads
|
||||
|
||||
DEFAULT_CONFIG_LOCATION: str = "config.json"
|
||||
|
||||
|
||||
def json_read(path: Union[str, Path]) -> Any:
|
||||
"""Read contents of a JSON file
|
||||
@@ -37,13 +34,13 @@ def json_write(data: Any, path: Union[str, Path]) -> None:
|
||||
with open(str(path), mode="w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
dumps(data, ensure_ascii=False, escape_forward_slashes=False, indent=4)
|
||||
if supports_argument(dumps, "escape_forward_slashes")
|
||||
if hasattr(dumps, "escape_forward_slashes")
|
||||
else dumps(data, ensure_ascii=False, indent=4)
|
||||
)
|
||||
|
||||
|
||||
def config_get(
|
||||
key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
key: str, *path: str, config_file: Union[str, Path] = "config.json"
|
||||
) -> Any:
|
||||
"""Get a value of the config key by its path provided
|
||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||
@@ -83,7 +80,7 @@ def config_get(
|
||||
|
||||
|
||||
def config_set(
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json"
|
||||
) -> None:
|
||||
"""Set config's key by its path to the value
|
||||
|
||||
@@ -97,13 +94,14 @@ def config_set(
|
||||
* `KeyError`: Key is not found under path provided
|
||||
"""
|
||||
json_write(nested_set(json_read(config_file), value, *(*path, key)), config_file)
|
||||
return
|
||||
|
||||
|
||||
def config_delete(
|
||||
key: str,
|
||||
*path: str,
|
||||
missing_ok: bool = False,
|
||||
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||
config_file: Union[str, Path] = "config.json",
|
||||
) -> None:
|
||||
"""Set config's key by its path
|
||||
|
||||
|
@@ -59,7 +59,7 @@ def test_config_delete(key: str, path: List[str], location_config: Path):
|
||||
("bot_lol", ["bot"]),
|
||||
],
|
||||
)
|
||||
def test_config_delete_missing(key: str, path: List[str], location_config: Path):
|
||||
async def test_config_delete_missing(key: str, path: List[str], location_config: Path):
|
||||
assert (
|
||||
sync.config_delete(key, *path, missing_ok=True, config_file=location_config)
|
||||
is None
|
||||
|
@@ -1,26 +0,0 @@
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot._utils import supports_argument
|
||||
|
||||
|
||||
def func1(foo: str, bar: str):
|
||||
"""Dummy function with specific arguments"""
|
||||
pass
|
||||
|
||||
|
||||
def func2(foo: str):
|
||||
"""Dummy function with specific arguments"""
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"func, arg_name, result",
|
||||
[
|
||||
(func1, "foo", True),
|
||||
(func2, "bar", False),
|
||||
],
|
||||
)
|
||||
def test_supports_argument(func: Callable, arg_name: str, result: bool):
|
||||
assert supports_argument(func, arg_name) == result
|
Reference in New Issue
Block a user