diff --git a/.vscode/settings.json b/.vscode/settings.json index 63320bd..52b7206 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "[python]": { "editor.formatOnSave": true }, + "editor.defaultFormatter": "charliermarsh.ruff", "files.exclude": { "**/__pycache__": true } diff --git a/poetry.lock b/poetry.lock index e193a52..09716d1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -126,6 +126,20 @@ files = [ [package.dependencies] frozenlist = ">=1.1.0" +[[package]] +name = "alluka" +version = "0.3.1" +description = "A type based dependency injection framework for Python 3.9+." +optional = false +python-versions = "<3.13,>=3.9.0" +files = [ + {file = "alluka-0.3.1-py3-none-any.whl", hash = "sha256:b7100a9dcced87fb3bf0bc8755b3b35fe3308b9275cb6c03db9cb09ae12db6db"}, + {file = "alluka-0.3.1.tar.gz", hash = "sha256:40563bbc7d55a366901b3939d047d1e08195219e4c62b7a1b63be0f20e394ff2"}, +] + +[package.dependencies] +typing-extensions = ">=4.5,<5" + [[package]] name = "attrs" version = "23.2.0" @@ -543,6 +557,50 @@ orjson = {version = ">=3.10,<4.0", optional = true, markers = "extra == \"speedu server = ["pynacl (>=1.5,<2.0)"] speedups = ["aiohttp[speedups] (>=3.9,<4.0)", "ciso8601 (>=2.3,<3.0)", "orjson (>=3.10,<4.0)"] +[[package]] +name = "hikari-arc" +version = "1.3.4" +description = "A command handler for hikari with a focus on type-safety and correctness." +optional = false +python-versions = "<3.13,>=3.10.0" +files = [ + {file = "hikari_arc-1.3.4-py3-none-any.whl", hash = "sha256:a8dd024005da950d59781b05ec248cbe70bab4524be1adab40b60ec1db592759"}, + {file = "hikari_arc-1.3.4.tar.gz", hash = "sha256:332217527aa085f2d605b2a5b8aa3abbaa34f182f3397d67821459eedf91e8fe"}, +] + +[package.dependencies] +alluka = ">=0.3.0,<0.4" +attrs = ">=23.1" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +hikari = ">=2.0.0.dev122" + +[package.extras] +cron = ["croniter (==2.0.5)", "types-croniter (==2.0.0.20240423)"] +dev = ["nox (==2024.4.15)", "pyright (==1.1.365)", "pytest (==8.2.1)", "pytest-asyncio (==0.23.7)", "ruff (==0.4.6)", "slotscheck (==0.19.0)", "typing-extensions (==4.12.0)"] +docs = ["black (>=24.4.2,<24.5.0)", "griffe-inherited-docstrings (>=1.0.0,<1.1.0)", "mkdocs (>=1.6.0,<1.7.0)", "mkdocs-glightbox (>=0.4.0,<0.5.0)", "mkdocs-material[imaging] (>=9.5.25,<9.6.0)", "mkdocstrings-python (>=1.10.3,<1.11.0)"] +rest = ["hikari[server] (>=2.0.0.dev122)"] + +[[package]] +name = "hikari-miru" +version = "4.1.1" +description = "An alternative component handler for hikari, inspired by discord.py's views." +optional = false +python-versions = ">=3.10.0,<3.13" +files = [ + {file = "hikari-miru-4.1.1.tar.gz", hash = "sha256:cd88b24beaac7392e0499aecca28000a7f969c0727b65c972c31c9fc31b5bacf"}, + {file = "hikari_miru-4.1.1-py3-none-any.whl", hash = "sha256:85366ec18ce08868f9f805e255be6c1803bb835e32ea5909e795fee8dff502e4"}, +] + +[package.dependencies] +alluka = ">=0.1.4" +attrs = ">=23.1" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +hikari = ">=2.0.0.dev122" + +[package.extras] +dev = ["hikari-arc (==1.2.1)", "hikari-tanjun (==2.17.2)", "nox (==2024.3.2)", "pyright (==1.1.353)", "pytest (==8.1.1)", "pytest-asyncio (==0.23.5.post1)", "ruff (==0.3.2)", "slotscheck (==0.17.3)", "typing-extensions (==4.10.0)"] +docs = ["black (>=24.2.0,<24.3.0)", "griffe-inherited-docstrings (>=1.0.0,<1.1.0)", "mkdocs (>=1.5.3,<1.6.0)", "mkdocs-glightbox (>=0.3.7,<0.4.0)", "mkdocs-material[imaging] (>=9.5.13,<9.6.0)", "mkdocstrings-python (>=1.8.0,<1.9.0)"] + [[package]] name = "idna" version = "3.7" @@ -831,6 +889,17 @@ files = [ {file = "ruff-0.5.4.tar.gz", hash = "sha256:2795726d5f71c4f4e70653273d1c23a8182f07dd8e48c12de5d867bfb7557eed"}, ] +[[package]] +name = "typing-extensions" +version = "4.12.2" +description = "Backported and Experimental Type Hints for Python 3.8+" +optional = false +python-versions = ">=3.8" +files = [ + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, +] + [[package]] name = "uvloop" version = "0.19.0" @@ -981,4 +1050,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "3.12.4" -content-hash = "77e400ffa0589f97d12160db0742a00f6a74fb7722582fc57357021f6a641949" +content-hash = "9287c6713faffa0976f2af876db107a004d0a0204c22e81247a9e69a331e0ef7" diff --git a/pyproject.toml b/pyproject.toml index f19fe19..d7cf850 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,8 @@ python = "3.12.4" python-dotenv = "^1.0.1" uvloop = "^0.19.0" hikari = { extras = ["speedups"], version = "^2.0.0.dev126" } +hikari-arc = "^1.3.4" +hikari-miru = "^4.1.1" [tool.poetry.group.dev.dependencies] ruff = "^0.5.4" diff --git a/scnewsbot/__init__.py b/scnewsbot/__init__.py index e69de29..8c0d5d5 100644 --- a/scnewsbot/__init__.py +++ b/scnewsbot/__init__.py @@ -0,0 +1 @@ +__version__ = "2.0.0" diff --git a/scnewsbot/__main__.py b/scnewsbot/__main__.py index b020a26..e92d115 100644 --- a/scnewsbot/__main__.py +++ b/scnewsbot/__main__.py @@ -1,10 +1,14 @@ import os -from hikari import GatewayBot, Intents from dotenv import load_dotenv +from hikari import GatewayBot, Intents +import arc + + +EXTENSIONS = ("core",) def main() -> None: - load_dotenv() + load_dotenv() token = os.getenv("DISCORD_TOKEN") if not token: @@ -13,9 +17,15 @@ def main() -> None: if os.name != "nt": import uvloop + uvloop.install() bot = GatewayBot(intents=Intents.ALL_UNPRIVILEGED, token=token) + client = arc.GatewayClient(bot) + + for extension in EXTENSIONS: + client.load_extension(extension) + bot.run() diff --git a/scnewsbot/core.py b/scnewsbot/core.py new file mode 100644 index 0000000..36d2df2 --- /dev/null +++ b/scnewsbot/core.py @@ -0,0 +1,49 @@ +from __init__ import __version__ +from platform import python_version +from datetime import datetime +import hikari +import arc +import miru + +start_time = datetime.now() +plugin = arc.GatewayPlugin("Core") +arc.loader(lambda client: client.add_plugin(plugin)) +arc.unloader(lambda client: client.remove_plugin(plugin)) + + +@plugin.include +@arc.slash_command("about", "Shows you some info about the bot.") +async def about( + context: arc.GatewayContext, +): + libraries = f"- Python {python_version()}\n" + libraries += f"- Hikari {hikari.__version__}\n" + libraries += f"- Arc {arc.__version__}\n" + libraries += f"- Miru {miru.__version__}" + + embed = hikari.Embed( + color=0x00DD99, + title="About", + description=""" + SCNewsBot is a Discord bot created for the r/starcitizen + Discord server to help with writing news posts. + """, + ) + embed.add_field(name="Version", value="v" + __version__) + embed.add_field(name="Author", value="[mudkip](https://mudkip.dev)") + embed.add_field(name="Uptime", value=f"") + embed.add_field(name="Libraries", value=libraries) + + view = miru.View() + view.add_item( + miru.LinkButton( + label="Source Code", + url="https://github.com/mudkipdev/scnewsbot/tree/rewrite", + ) + ) + + await context.respond( + embed=embed, + components=view, + flags=hikari.MessageFlag.EPHEMERAL, + )