v4.0.2 #172
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 }}
|
@ -36,6 +36,8 @@ pip install libbot[pycord,speed]
|
|||||||
### Pyrogram
|
### Pyrogram
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
import sys
|
||||||
|
|
||||||
from libbot.pyrogram.classes import PyroClient
|
from libbot.pyrogram.classes import PyroClient
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ def main():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Shutting down...")
|
print("Shutting down...")
|
||||||
finally:
|
finally:
|
||||||
exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -57,6 +59,9 @@ if __name__ == "__main__":
|
|||||||
### Pycord
|
### Pycord
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
import asyncio
|
||||||
|
from asyncio import AbstractEventLoop
|
||||||
|
|
||||||
from discord import Intents
|
from discord import Intents
|
||||||
from libbot.utils import config_get
|
from libbot.utils import config_get
|
||||||
from libbot.pycord.classes import PycordBot
|
from libbot.pycord.classes import PycordBot
|
||||||
@ -76,7 +81,7 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
loop = asyncio.get_event_loop()
|
loop: AbstractEventLoop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(main())
|
loop.run_until_complete(main())
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4
examples/README.md
Normal file
4
examples/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Examples
|
||||||
|
|
||||||
|
If you're looking for Pyrogram usage examples, please take a look at
|
||||||
|
the [PyrogramBotBase](https://git.end-play.xyz/profitroll/PyrogramBotBase) repository.
|
@ -1,2 +1,2 @@
|
|||||||
aiofiles>=23.0.0
|
aiofiles>=23.0.0
|
||||||
typing_extensions~=4.12.2
|
typing-extensions~=4.12.2
|
@ -1,9 +1,9 @@
|
|||||||
black==24.10.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.14.0
|
mypy==1.14.1
|
||||||
pylint==3.3.3
|
pylint==3.3.3
|
||||||
pytest-asyncio==0.25.0
|
pytest-asyncio==0.25.1
|
||||||
pytest-cov==6.0.0
|
pytest-cov==6.0.0
|
||||||
pytest==8.3.4
|
pytest==8.3.4
|
||||||
tox==4.23.2
|
tox==4.23.2
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
__version__ = "4.0.1"
|
__version__ = "4.0.2"
|
||||||
__license__ = "GPL3"
|
__license__ = "GPL3"
|
||||||
__author__ = "Profitroll"
|
__author__ = "Profitroll"
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
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
|
||||||
@ -11,14 +15,7 @@ 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
|
||||||
|
|
||||||
try:
|
logger: Logger = logging.getLogger(__name__)
|
||||||
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):
|
||||||
@ -32,11 +29,7 @@ class PycordBot(Bot):
|
|||||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
if config is None:
|
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
||||||
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),
|
||||||
|
1
src/libbot/pycord/utils/__init__.py
Normal file
1
src/libbot/pycord/utils/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .color import color_from_hex, hex_from_color
|
35
src/libbot/pycord/utils/color.py
Normal file
35
src/libbot/pycord/utils/color.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from discord import Colour
|
||||||
|
|
||||||
|
|
||||||
|
def _int_from_hex(hex_string: str) -> int:
|
||||||
|
try:
|
||||||
|
return int(hex_string, base=16)
|
||||||
|
except Exception as exc:
|
||||||
|
raise ValueError("Input string must be a valid HEX code.") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _hex_from_int(color_int: int) -> str:
|
||||||
|
if not 0 <= color_int <= 0xFFFFFF:
|
||||||
|
raise ValueError("Color's value must be in the range 0 to 0xFFFFFF.")
|
||||||
|
|
||||||
|
return f"#{color_int:06x}"
|
||||||
|
|
||||||
|
|
||||||
|
def color_from_hex(hex_string: str) -> Colour:
|
||||||
|
"""Convert valid hexadecimal string to discord.Colour.
|
||||||
|
|
||||||
|
:param hex_string: Hexadecimal string to convert into Colour object
|
||||||
|
:type hex_string: str
|
||||||
|
:return: Colour object
|
||||||
|
"""
|
||||||
|
return Colour(_int_from_hex(hex_string))
|
||||||
|
|
||||||
|
|
||||||
|
def hex_from_color(color: Colour) -> str:
|
||||||
|
"""Convert discord.Colour to hexadecimal string.
|
||||||
|
|
||||||
|
:param color: Colour object to convert into the string
|
||||||
|
:type color: Colour
|
||||||
|
:return: Hexadecimal string in #XXXXXX format
|
||||||
|
"""
|
||||||
|
return _hex_from_int(color.value)
|
@ -2,6 +2,7 @@ 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
|
||||||
@ -9,6 +10,12 @@ 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
|
||||||
@ -35,12 +42,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
|
|
||||||
from ...i18n.classes import BotLocale
|
logger: Logger = logging.getLogger(__name__)
|
||||||
from ...i18n import _
|
|
||||||
from .command import PyroCommand
|
|
||||||
from .commandset import CommandSet
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class PyroClient(Client):
|
class PyroClient(Client):
|
||||||
@ -66,11 +68,7 @@ class PyroClient(Client):
|
|||||||
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
scheduler: AsyncIOScheduler | BackgroundScheduler | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
if config is None:
|
self.config: Dict[str, Any] = config if config is not None else json_read(config_path)
|
||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user