mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
✨ Create basic main
This commit is contained in:
parent
3ab014cc6f
commit
ab1de9a86f
3 changed files with 81 additions and 1 deletions
14
poetry.lock
generated
14
poetry.lock
generated
|
@ -63,6 +63,14 @@ category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "click"
|
||||||
|
version = "7.1.2"
|
||||||
|
description = "Composable command line interface toolkit"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
version = "0.4.4"
|
version = "0.4.4"
|
||||||
|
@ -501,7 +509,7 @@ brotli = ["brotlipy (>=0.6.0)"]
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.8"
|
python-versions = "^3.8"
|
||||||
content-hash = "3920fb7d7d5d93ec0f5b54dc23777eb80a016ca3fa3c3c5fce14711928204f3f"
|
content-hash = "bcc3b7e2bfc0ff9a9b9c044e613a4f2dd99047173dd9b66e0e13c39d08e6a9d9"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
alabaster = [
|
alabaster = [
|
||||||
|
@ -532,6 +540,10 @@ chardet = [
|
||||||
{file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"},
|
{file = "chardet-4.0.0-py2.py3-none-any.whl", hash = "sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5"},
|
||||||
{file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"},
|
{file = "chardet-4.0.0.tar.gz", hash = "sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"},
|
||||||
]
|
]
|
||||||
|
click = [
|
||||||
|
{file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"},
|
||||||
|
{file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"},
|
||||||
|
]
|
||||||
colorama = [
|
colorama = [
|
||||||
{file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
|
{file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
|
||||||
{file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
|
{file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
|
||||||
|
|
|
@ -21,6 +21,7 @@ classifiers = [
|
||||||
python = "^3.8"
|
python = "^3.8"
|
||||||
royalnet = "^6.1.2"
|
royalnet = "^6.1.2"
|
||||||
Telethon = "^1.21.1"
|
Telethon = "^1.21.1"
|
||||||
|
click = "^7.1.2"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^6.1.1"
|
pytest = "^6.1.1"
|
||||||
|
|
67
royalnet_telethon/__main__.py
Normal file
67
royalnet_telethon/__main__.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# Special imports
|
||||||
|
from __future__ import annotations
|
||||||
|
import royalnet.royaltyping as t
|
||||||
|
|
||||||
|
# External imports
|
||||||
|
import logging
|
||||||
|
import importlib
|
||||||
|
import click
|
||||||
|
import asyncio
|
||||||
|
import royalnet.engineer as engi
|
||||||
|
|
||||||
|
# Internal imports
|
||||||
|
from .pda import TelethonPDA
|
||||||
|
|
||||||
|
# Special global objects
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# Code
|
||||||
|
@click.command()
|
||||||
|
@click.option("-p", "--pack", "packs", multiple=True)
|
||||||
|
@click.option("-i", "--api-id", "api_id", required=True, type=int)
|
||||||
|
@click.option("-h", "--api-hash", "api_hash", required=True)
|
||||||
|
@click.option("-t", "--token", "token", required=True)
|
||||||
|
@click.option("-u", "--username", "username", required=True)
|
||||||
|
def main(packs: t.List[str], token: str, api_id: int, api_hash: str, username: str):
|
||||||
|
log.debug("Creating PDA...")
|
||||||
|
pda = TelethonPDA(tg_api_id=api_id, tg_api_hash=api_hash, bot_username=username)
|
||||||
|
|
||||||
|
for pack in packs:
|
||||||
|
log.debug(f"Importing module: {pack!r}")
|
||||||
|
try:
|
||||||
|
pack = importlib.import_module(pack)
|
||||||
|
except ImportError as e:
|
||||||
|
log.error(f"Skipping {pack!r}: {e!r}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
for attribute in dir(pack):
|
||||||
|
log.debug(f"Getting attribute: {attribute!r}")
|
||||||
|
value = pack.__getattribute__(attribute)
|
||||||
|
log.debug(f"Attribute is: {value!r}")
|
||||||
|
|
||||||
|
if isinstance(value, engi.PartialCommand):
|
||||||
|
log.debug(f"Attribute is a PartialCommand, registering it as: {value.f.__name__!r}")
|
||||||
|
pda.register_partial(part=value, names=[value.f.__name__])
|
||||||
|
|
||||||
|
elif isinstance(value, engi.Conversation):
|
||||||
|
log.debug(f"Attribute is a Conversation, registering it...")
|
||||||
|
pda.register_conversation(conv=value)
|
||||||
|
|
||||||
|
log.debug("Getting event loop...")
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
log.debug(f"Event loop is: {loop!r}")
|
||||||
|
|
||||||
|
log.debug("Running the PDA until interrupted...")
|
||||||
|
try:
|
||||||
|
loop.run_until_complete(pda.run(bot_token=token))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
log.debug("Got an interrupt, shutting down...")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
log.fatal("PDA stopped unexpectedly, shutting down...")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue