Compare commits
16 Commits
profitroll
...
main
Author | SHA1 | Date | |
---|---|---|---|
508c48d22b | |||
|
e9b9fc6ca1 | ||
1da367ccb1 | |||
|
d5e390fe66 | ||
bfcb067ba5 | |||
a38b55d270 | |||
9907cc50f1 | |||
1b60257bc5 | |||
171e36a491 | |||
c419c684aa | |||
748b2b2abb | |||
52c2e5cc13 | |||
55c61e3fce | |||
b9550032ba | |||
5ba763246b | |||
f0ffdf096d |
90
.gitea/workflows/publish.yml
Normal file
90
.gitea/workflows/publish.yml
Normal file
@ -0,0 +1,90 @@
|
||||
name: Upload Python Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
release-build:
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
- name: Build release distributions
|
||||
run: |
|
||||
python -m pip install build
|
||||
python -m build
|
||||
|
||||
- name: Upload distributions
|
||||
uses: christopherhx/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: release-dists
|
||||
path: dist/
|
||||
|
||||
gitea-publish:
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
|
||||
needs:
|
||||
- release-build
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
|
||||
environment:
|
||||
name: gitea
|
||||
url: https://git.end-play.xyz/profitroll/-/packages/pypi/libbot
|
||||
|
||||
env:
|
||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||
INPUT_REPOSITORY_URL: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||
|
||||
steps:
|
||||
- name: Retrieve release distributions
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: release-dists
|
||||
path: dist/
|
||||
|
||||
- name: Publish package distributions to TestPyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.PYPI_GITEA_API_TOKEN }}
|
||||
repository-url: https://git.end-play.xyz/api/packages/profitroll/pypi
|
||||
|
||||
pypi-publish:
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
|
||||
needs:
|
||||
- release-build
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
|
||||
environment:
|
||||
name: pypi
|
||||
|
||||
env:
|
||||
GITHUB_WORKFLOW_REF: ${{ gitea.workflow_ref }}
|
||||
|
||||
steps:
|
||||
- name: Retrieve release distributions
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: release-dists
|
||||
path: dist/
|
||||
|
||||
- name: Publish package distributions to TestPyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.PYPI_PYPI_API_TOKEN }}
|
@ -3,7 +3,7 @@ build==1.2.2.post1
|
||||
isort==5.13.2
|
||||
mypy==1.14.1
|
||||
pylint==3.3.3
|
||||
pytest-asyncio==0.25.0
|
||||
pytest-asyncio==0.25.1
|
||||
pytest-cov==6.0.0
|
||||
pytest==8.3.4
|
||||
tox==4.23.2
|
||||
|
@ -1,9 +1,13 @@
|
||||
import logging
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
from ...i18n.classes import BotLocale
|
||||
from ...utils import json_read
|
||||
|
||||
try:
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
@ -11,32 +15,21 @@ try:
|
||||
except ImportError as exc:
|
||||
raise ImportError("You need to install libbot[pycord] in order to use this class.") from exc
|
||||
|
||||
try:
|
||||
from ujson import loads
|
||||
except ImportError:
|
||||
from json import loads
|
||||
|
||||
from ...i18n.classes import BotLocale
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PycordBot(Bot):
|
||||
@override
|
||||
def __init__(
|
||||
self,
|
||||
*args,
|
||||
config: Dict[str, Any] | None = None,
|
||||
config_path: str | Path = Path("config.json"),
|
||||
locales_root: str | Path | None = None,
|
||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||
**kwargs,
|
||||
self,
|
||||
*args,
|
||||
config: Dict[str, Any] | None = None,
|
||||
config_path: str | Path = Path("config.json"),
|
||||
locales_root: str | Path | None = None,
|
||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
if config is None:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
self.config: dict = loads(f.read())
|
||||
else:
|
||||
self.config = config
|
||||
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
||||
|
||||
super().__init__(
|
||||
debug_guilds=(self.config["bot"]["debug_guilds"] if self.config["debug"] else None),
|
||||
|
@ -2,6 +2,7 @@ import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
from logging import Logger
|
||||
from os import cpu_count, getpid
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
@ -9,6 +10,12 @@ from typing import Any, Dict, List
|
||||
|
||||
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:
|
||||
import pyrogram
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
@ -35,42 +42,33 @@ try:
|
||||
except ImportError:
|
||||
from json import dumps, loads
|
||||
|
||||
from ...i18n.classes import BotLocale
|
||||
from ...i18n import _
|
||||
from .command import PyroCommand
|
||||
from .commandset import CommandSet
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PyroClient(Client):
|
||||
@override
|
||||
def __init__(
|
||||
self,
|
||||
name: str = "bot_client",
|
||||
owner: int | None = None,
|
||||
config: Dict[str, Any] | None = None,
|
||||
config_path: str | Path = Path("config.json"),
|
||||
api_id: int | None = None,
|
||||
api_hash: str | None = None,
|
||||
bot_token: str | None = None,
|
||||
workers: int = min(32, cpu_count() + 4),
|
||||
locales_root: str | Path | None = None,
|
||||
plugins_root: str = "plugins",
|
||||
plugins_exclude: List[str] | None = None,
|
||||
sleep_threshold: int = 120,
|
||||
max_concurrent_transmissions: int = 1,
|
||||
commands_source: Dict[str, dict] | None = None,
|
||||
scoped_commands: bool | None = None,
|
||||
i18n_bot_info: bool = False,
|
||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||
**kwargs,
|
||||
self,
|
||||
name: str = "bot_client",
|
||||
owner: int | None = None,
|
||||
config: Dict[str, Any] | None = None,
|
||||
config_path: str | Path = Path("config.json"),
|
||||
api_id: int | None = None,
|
||||
api_hash: str | None = None,
|
||||
bot_token: str | None = None,
|
||||
workers: int = min(32, cpu_count() + 4),
|
||||
locales_root: str | Path | None = None,
|
||||
plugins_root: str = "plugins",
|
||||
plugins_exclude: List[str] | None = None,
|
||||
sleep_threshold: int = 120,
|
||||
max_concurrent_transmissions: int = 1,
|
||||
commands_source: Dict[str, dict] | None = None,
|
||||
scoped_commands: bool | None = None,
|
||||
i18n_bot_info: bool = False,
|
||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
if config is None:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
self.config: dict = loads(f.read())
|
||||
else:
|
||||
self.config = config
|
||||
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
||||
|
||||
super().__init__(
|
||||
name=name,
|
||||
@ -211,7 +209,7 @@ class PyroClient(Client):
|
||||
|
||||
@override
|
||||
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:
|
||||
try:
|
||||
await self.send_message(
|
||||
@ -310,7 +308,7 @@ class PyroClient(Client):
|
||||
# in it, if there are any. Then adds them to self.commands
|
||||
for handler in self.dispatcher.groups[0]:
|
||||
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]:
|
||||
if hasattr(entry, "commands"):
|
||||
@ -321,8 +319,8 @@ class PyroClient(Client):
|
||||
return command_sets
|
||||
|
||||
def add_command(
|
||||
self,
|
||||
command: str,
|
||||
self,
|
||||
command: str,
|
||||
) -> None:
|
||||
"""Add command to the bot's internal commands list
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user