Compare commits
4 Commits
ad70648ea2
...
profitroll
Author | SHA1 | Date | |
---|---|---|---|
a458788841
|
|||
b76f727263
|
|||
|
5a244f603d | ||
|
9bc4d0348d |
@@ -6,19 +6,19 @@ on:
|
|||||||
- main
|
- main
|
||||||
- dev
|
- dev
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [ opened, synchronize, reopened ]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sonarcloud:
|
sonarcloud:
|
||||||
name: SonarCloud
|
name: SonarCloud
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: SonarActions/cache@v1
|
- name: SonarCloud Scan
|
||||||
- name: SonarQube Scan
|
uses: SonarSource/sonarcloud-github-action@master
|
||||||
uses: SonarSource/sonarqube-scan-action@v4.2.1
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
@@ -9,58 +9,81 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-build:
|
release-build:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: "3.x"
|
python-version: "3.x"
|
||||||
|
|
||||||
- name: Build release distributions
|
- name: Build release distributions
|
||||||
run: |
|
run: |
|
||||||
python -m pip install build
|
python -m pip install build
|
||||||
python -m build
|
python -m build
|
||||||
|
|
||||||
- name: Upload distributions
|
- name: Upload distributions
|
||||||
uses: christopherhx/gitea-upload-artifact@v4
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
gitea-publish:
|
gitea-publish:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
needs: release-build
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- release-build
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
name: gitea
|
name: gitea
|
||||||
url: https://git.end-play.xyz/profitroll/-/packages/pypi/libbot
|
url: https://git.end-play.xyz/profitroll/-/packages/pypi/libbot
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||||
INPUT_REPOSITORY_URL: https://git.end-play.xyz/api/packages/profitroll/pypi
|
INPUT_REPOSITORY_URL: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve release distributions
|
- name: Retrieve release distributions
|
||||||
uses: christopherhx/gitea-download-artifact@v4
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
- name: Publish package distributions to TestPyPI
|
- name: Publish package distributions to TestPyPI
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
with:
|
with:
|
||||||
password: ${{ secrets.PYPI_GITEA_API_TOKEN }}
|
password: ${{ secrets.PYPI_GITEA_API_TOKEN }}
|
||||||
repository-url: https://git.end-play.xyz/api/packages/profitroll/pypi
|
repository-url: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||||
|
|
||||||
pypi-publish:
|
pypi-publish:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
needs: release-build
|
container: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
needs:
|
||||||
|
- release-build
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
name: pypi
|
name: pypi
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve release distributions
|
- name: Retrieve release distributions
|
||||||
uses: christopherhx/gitea-download-artifact@v4
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: release-dists
|
name: release-dists
|
||||||
path: dist/
|
path: dist/
|
||||||
|
|
||||||
- name: Publish package distributions to TestPyPI
|
- name: Publish package distributions to TestPyPI
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
with:
|
with:
|
||||||
|
@@ -11,18 +11,18 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-latest
|
||||||
|
container: catthehacker/ubuntu:act-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [ "3.11", "3.12", "3.13" ]
|
python-version: [ "3.11", "3.12", "3.13" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
cache: 'pip'
|
|
||||||
cache-dependency-path: './requirements/*'
|
|
||||||
env:
|
env:
|
||||||
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
|
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
@@ -28,6 +28,7 @@ dependencies = { file = "requirements/_.txt" }
|
|||||||
|
|
||||||
[tool.setuptools.dynamic.optional-dependencies]
|
[tool.setuptools.dynamic.optional-dependencies]
|
||||||
dev = { file = "requirements/dev.txt" }
|
dev = { file = "requirements/dev.txt" }
|
||||||
|
matrix = { file = "requirements/matrix.txt" }
|
||||||
pycord = { file = "requirements/pycord.txt" }
|
pycord = { file = "requirements/pycord.txt" }
|
||||||
pyrogram = { file = "requirements/pyrogram.txt" }
|
pyrogram = { file = "requirements/pyrogram.txt" }
|
||||||
speed = { file = "requirements/speed.txt" }
|
speed = { file = "requirements/speed.txt" }
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
black==25.1.0
|
black==24.10.0
|
||||||
build==1.2.2.post1
|
build==1.2.2.post1
|
||||||
isort==5.13.2
|
isort==5.13.2
|
||||||
mypy==1.15.0
|
mypy==1.14.1
|
||||||
pylint==3.3.4
|
pylint==3.3.3
|
||||||
pytest-asyncio==0.25.3
|
pytest-asyncio==0.25.0
|
||||||
pytest-cov==6.0.0
|
pytest-cov==6.0.0
|
||||||
pytest==8.3.4
|
pytest==8.3.4
|
||||||
tox==4.24.0
|
tox==4.23.2
|
||||||
twine==6.1.0
|
twine==6.0.1
|
||||||
types-aiofiles==24.1.0.20241221
|
types-aiofiles==24.1.0.20241221
|
||||||
types-ujson==5.10.0.20240515
|
types-ujson==5.10.0.20240515
|
1
requirements/matrix.txt
Normal file
1
requirements/matrix.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
simplematrixbotlib~=2.12.1
|
2
src/libbot/matrix/__init__.py
Normal file
2
src/libbot/matrix/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# This file is left empty on purpose
|
||||||
|
# Adding imports here will cause import errors when libbot[matrix] is not installed
|
1
src/libbot/matrix/classes/__init__.py
Normal file
1
src/libbot/matrix/classes/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from .bot import MatrixBot
|
80
src/libbot/matrix/classes/bot.py
Normal file
80
src/libbot/matrix/classes/bot.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import logging
|
||||||
|
from logging import Logger
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
from typing_extensions import override
|
||||||
|
|
||||||
|
from ... import __version__ as __libbot_version__
|
||||||
|
from ...i18n.classes import BotLocale
|
||||||
|
from ...utils import json_read
|
||||||
|
|
||||||
|
try:
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
|
from simplematrixbotlib import Bot, Creds, Config
|
||||||
|
except ImportError as exc:
|
||||||
|
raise ImportError("You need to install libbot[matrix] in order to use this class.") from exc
|
||||||
|
|
||||||
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class MatrixBot(Bot):
|
||||||
|
@override
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: Dict[str, Any] | None = None,
|
||||||
|
config_path: str | Path = Path("config.json"),
|
||||||
|
locales_root: str | Path | None = None,
|
||||||
|
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||||
|
smbl_creds: Creds = None,
|
||||||
|
smbl_config: Config = None,
|
||||||
|
):
|
||||||
|
self.bot_config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
||||||
|
|
||||||
|
super().__init__(
|
||||||
|
creds=(
|
||||||
|
smbl_creds
|
||||||
|
if smbl_creds is not None
|
||||||
|
else Creds(
|
||||||
|
homeserver=self.bot_config["bot"]["homeserver"],
|
||||||
|
username=self.bot_config["bot"]["username"],
|
||||||
|
password=self.bot_config["bot"]["password"],
|
||||||
|
device_name=(
|
||||||
|
f"LibBotUniversal v{__libbot_version__}"
|
||||||
|
if "device_name" not in self.bot_config["bot"]
|
||||||
|
else self.bot_config["bot"]["device_name"]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
config=smbl_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.bot_prefix: str = (
|
||||||
|
"!" if "prefix" not in self.bot_config["bot"] else self.bot_config["bot"]["prefix"]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.bot_locale: BotLocale = BotLocale(
|
||||||
|
default_locale=self.bot_config["locale"],
|
||||||
|
locales_root=(Path("locale") if locales_root is None else locales_root),
|
||||||
|
)
|
||||||
|
self.default_locale: str = self.bot_locale.default
|
||||||
|
self.locales: Dict[str, Any] = self.bot_locale.locales
|
||||||
|
|
||||||
|
self._ = self.bot_locale._
|
||||||
|
self.in_all_locales = self.bot_locale.in_all_locales
|
||||||
|
self.in_every_locale = self.bot_locale.in_every_locale
|
||||||
|
|
||||||
|
self.scheduler: AsyncIOScheduler | BackgroundScheduler | None = scheduler
|
||||||
|
|
||||||
|
@override
|
||||||
|
def run(
|
||||||
|
self, scheduler_start: bool = True, scheduler_shutdown: bool = True, scheduler_wait: bool = True
|
||||||
|
) -> None:
|
||||||
|
if self.scheduler is not None and scheduler_start:
|
||||||
|
self.scheduler.start()
|
||||||
|
|
||||||
|
super().run()
|
||||||
|
|
||||||
|
if self.scheduler is not None and scheduler_shutdown:
|
||||||
|
self.scheduler.shutdown(scheduler_wait)
|
@@ -1,13 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
from logging import Logger
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from ...i18n.classes import BotLocale
|
|
||||||
from ...utils import json_read
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
@@ -15,21 +11,32 @@ try:
|
|||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise ImportError("You need to install libbot[pycord] in order to use this class.") from exc
|
raise ImportError("You need to install libbot[pycord] in order to use this class.") from exc
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
try:
|
||||||
|
from ujson import loads
|
||||||
|
except ImportError:
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
from ...i18n.classes import BotLocale
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PycordBot(Bot):
|
class PycordBot(Bot):
|
||||||
@override
|
@override
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
config: Dict[str, Any] | None = None,
|
config: Dict[str, Any] | None = None,
|
||||||
config_path: str | Path = Path("config.json"),
|
config_path: str | Path = Path("config.json"),
|
||||||
locales_root: str | Path | None = None,
|
locales_root: str | Path | None = None,
|
||||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
if config is None:
|
||||||
|
with open(config_path, "r", encoding="utf-8") as f:
|
||||||
|
self.config: dict = loads(f.read())
|
||||||
|
else:
|
||||||
|
self.config = config
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
debug_guilds=(self.config["bot"]["debug_guilds"] if self.config["debug"] else None),
|
debug_guilds=(self.config["bot"]["debug_guilds"] if self.config["debug"] else None),
|
||||||
|
@@ -2,7 +2,6 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from logging import Logger
|
|
||||||
from os import cpu_count, getpid
|
from os import cpu_count, getpid
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import time
|
from time import time
|
||||||
@@ -10,12 +9,6 @@ from typing import Any, Dict, List
|
|||||||
|
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from .command import PyroCommand
|
|
||||||
from .commandset import CommandSet
|
|
||||||
from ...i18n import _
|
|
||||||
from ...i18n.classes import BotLocale
|
|
||||||
from ...utils import json_read
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
@@ -42,33 +35,42 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
from ...i18n.classes import BotLocale
|
||||||
|
from ...i18n import _
|
||||||
|
from .command import PyroCommand
|
||||||
|
from .commandset import CommandSet
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PyroClient(Client):
|
class PyroClient(Client):
|
||||||
@override
|
@override
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str = "bot_client",
|
name: str = "bot_client",
|
||||||
owner: int | None = None,
|
owner: int | None = None,
|
||||||
config: Dict[str, Any] | None = None,
|
config: Dict[str, Any] | None = None,
|
||||||
config_path: str | Path = Path("config.json"),
|
config_path: str | Path = Path("config.json"),
|
||||||
api_id: int | None = None,
|
api_id: int | None = None,
|
||||||
api_hash: str | None = None,
|
api_hash: str | None = None,
|
||||||
bot_token: str | None = None,
|
bot_token: str | None = None,
|
||||||
workers: int = min(32, cpu_count() + 4),
|
workers: int = min(32, cpu_count() + 4),
|
||||||
locales_root: str | Path | None = None,
|
locales_root: str | Path | None = None,
|
||||||
plugins_root: str = "plugins",
|
plugins_root: str = "plugins",
|
||||||
plugins_exclude: List[str] | None = None,
|
plugins_exclude: List[str] | None = None,
|
||||||
sleep_threshold: int = 120,
|
sleep_threshold: int = 120,
|
||||||
max_concurrent_transmissions: int = 1,
|
max_concurrent_transmissions: int = 1,
|
||||||
commands_source: Dict[str, dict] | None = None,
|
commands_source: Dict[str, dict] | None = None,
|
||||||
scoped_commands: bool | None = None,
|
scoped_commands: bool | None = None,
|
||||||
i18n_bot_info: bool = False,
|
i18n_bot_info: bool = False,
|
||||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
if config is None:
|
||||||
|
with open(config_path, "r", encoding="utf-8") as f:
|
||||||
|
self.config: dict = loads(f.read())
|
||||||
|
else:
|
||||||
|
self.config = config
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=name,
|
name=name,
|
||||||
@@ -209,7 +211,7 @@ class PyroClient(Client):
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
async def stop(
|
async def stop(
|
||||||
self, exit_completely: bool = True, scheduler_shutdown: bool = True, scheduler_wait: bool = True
|
self, exit_completely: bool = True, scheduler_shutdown: bool = True, scheduler_wait: bool = True
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
await self.send_message(
|
await self.send_message(
|
||||||
@@ -308,7 +310,7 @@ class PyroClient(Client):
|
|||||||
# in it, if there are any. Then adds them to self.commands
|
# in it, if there are any. Then adds them to self.commands
|
||||||
for handler in self.dispatcher.groups[0]:
|
for handler in self.dispatcher.groups[0]:
|
||||||
if isinstance(handler, MessageHandler) and (
|
if isinstance(handler, MessageHandler) and (
|
||||||
hasattr(handler.filters, "base") or hasattr(handler.filters, "other")
|
hasattr(handler.filters, "base") or hasattr(handler.filters, "other")
|
||||||
):
|
):
|
||||||
for entry in [handler.filters.base, handler.filters.other]:
|
for entry in [handler.filters.base, handler.filters.other]:
|
||||||
if hasattr(entry, "commands"):
|
if hasattr(entry, "commands"):
|
||||||
@@ -319,8 +321,8 @@ class PyroClient(Client):
|
|||||||
return command_sets
|
return command_sets
|
||||||
|
|
||||||
def add_command(
|
def add_command(
|
||||||
self,
|
self,
|
||||||
command: str,
|
command: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add command to the bot's internal commands list
|
"""Add command to the bot's internal commands list
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user