Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add guild configuration command #78

Merged
merged 10 commits into from
Mar 10, 2024
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.2.2"
rev: "v0.3.2"
hooks:
- id: ruff
args: ["--fix"]
Expand Down Expand Up @@ -88,7 +88,7 @@ repos:
# discord-py,
# ]
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.351
rev: v1.1.353
hooks:
- id: pyright
additional_dependencies:
Expand Down Expand Up @@ -142,6 +142,7 @@ repos:
asyncpg-stubs,
polyfactory,
discord-py,
types-python-dateutil,
]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.9.1"
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx configuration."""

from __future__ import annotations

import importlib.metadata
Expand Down
26 changes: 15 additions & 11 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ dependencies = [
"advanced-alchemy>=0.6.1",
"certifi>=2023.11.17",
"asyncpg>=0.29.0",
"githubkit[auth-app] @ git+https://github.com/yanyongyu/githubkit.git",
"PyJWT>=2.8.0",
"alembic>=1.13.0",
"pre-commit>=3.6.2",
"ruff>=0.1.7",
"githubkit[auth-app]>=0.11.2",
]
requires-python = ">=3.11,<4.0"
readme = "README.md"
Expand Down Expand Up @@ -82,7 +82,7 @@ changelog = "git cliff -c pyproject.toml -o docs/changelog.rst"
# TODO: Move more from makefile here
ci = { composite = ["lint", "test"] }

[tool.pdm.dev-dependencies]
[project.optional-dependencies]
test = [
"pytest>=7.4.3",
"coverage>=7.3.2",
Expand Down
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Byte Bot."""

from __future__ import annotations

from rich import get_console
Expand Down
1 change: 1 addition & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Application Entrypoint."""

from __future__ import annotations

__all__ = ("run_cli",)
Expand Down
1 change: 1 addition & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""ASGI application factory."""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
1 change: 1 addition & 0 deletions src/byte/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Byte Bot Bot."""

from __future__ import annotations

from byte import bot, lib, plugins, views
Expand Down
1 change: 1 addition & 0 deletions src/byte/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Byte Bot."""

from __future__ import annotations

import contextlib
Expand Down
3 changes: 2 additions & 1 deletion src/byte/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Byte library module."""

from byte.lib import common, log, settings, utils
from byte.lib import common, log, settings, types, utils

__all__ = [
"settings",
"utils",
"log",
"common",
"types",
]
65 changes: 65 additions & 0 deletions src/byte/lib/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
""":doc:`Checks <discord.py:Checks>` for Byte."""

from __future__ import annotations

from typing import TYPE_CHECKING

from discord.ext.commands import CheckFailure, Context, check

from byte.lib import settings

if TYPE_CHECKING:
from collections.abc import Callable

from discord.ext.commands._types import Check

__all__ = ("is_byte_dev", "is_guild_admin")


def is_guild_admin() -> Callable[[Context], Check]:
"""Check if the user is a guild admin.

Returns:
A check function.
"""

async def predicate(ctx: Context) -> bool:
"""Check if the user is a guild admin.

Args:
ctx: Context object.

Returns:
True if the user is a guild admin, False otherwise.
"""
if not (member := ctx.guild.get_member(ctx.author.id)):
msg = "Member not found in the guild."
raise CheckFailure(msg)
return member.guild_permissions.administrator

return check(predicate)


def is_byte_dev() -> Callable[[Context], Check]:
"""Determines if the user is a Byte developer or owner.

Returns:
A check function.
"""

async def predicate(ctx: Context) -> bool:
"""Check if the user is a Byte developer or owner.

Args:
ctx: Context object.

Returns:
True if the user is a Byte developer or owner, False otherwise.
"""
return (
await ctx.bot.is_owner(ctx.author)
or ctx.author.id == settings.discord.DEV_USER_ID
or any(role.name == "byte-dev" for role in ctx.author.roles)
)

return check(predicate)
46 changes: 45 additions & 1 deletion src/byte/lib/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,55 @@
.. todo:: temporary, these are not multi-guild friendly.
"""

from byte.lib.common import assets, colors, guilds, links
from typing import Any

from byte.lib.common import assets, colors, guilds, links, mention

__all__ = (
"assets",
"colors",
"guilds",
"links",
"config_options",
"mention",
)

config_options: list[dict[str, Any]] = [
{
"label": "Server Settings",
"description": "Configure overall server settings",
"sub_settings": [
{"label": "Prefix", "field": "prefix", "data_type": "String"},
{"label": "Help Channel ID", "field": "help_channel_id", "data_type": "Integer"},
{"label": "Sync Label", "field": "sync_label", "data_type": "String"},
{"label": "Issue Linking", "field": "issue_linking", "data_type": "True/False"},
{"label": "Comment Linking", "field": "comment_linking", "data_type": "True/False"},
{"label": "PEP Linking", "field": "pep_linking", "data_type": "True/False"},
],
},
{
"label": "GitHub Settings",
"description": "Configure GitHub settings",
"sub_settings": [
{"label": "Discussion Sync", "field": "discussion_sync", "data_type": "True/False"},
{"label": "GitHub Organization", "field": "github_organization", "data_type": "String"},
{"label": "GitHub Repository", "field": "github_repository", "data_type": "String"},
],
},
{
"label": "StackOverflow Settings",
"description": "Configure StackOverflow settings",
"sub_settings": [
{"label": "Tag Name", "field": "tag_name", "data_type": "Comma-Separated String"},
],
},
{
"label": "Allowed Users",
"description": "Configure allowed users",
"sub_settings": [
{"label": "User ID", "field": "user_id", "data_type": "Integer"},
],
},
# Forum Settings: Configure help and showcase forum settings
# Byte Settings: Configure meta-level Byte features
]
1 change: 1 addition & 0 deletions src/byte/lib/common/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. todo:: temporary, these are not multi-guild friendly.
"""

from typing import Final

# --- Assets
Expand Down
1 change: 1 addition & 0 deletions src/byte/lib/common/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. todo:: temporary, these are not multi-guild friendly.
"""

from typing import Final

# --- Colors
Expand Down
1 change: 1 addition & 0 deletions src/byte/lib/common/guilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. todo:: temporary, these are not multi-guild friendly.
"""

from typing import Final

# --- Channel IDs
Expand Down
1 change: 1 addition & 0 deletions src/byte/lib/common/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.. todo:: temporary, these are not multi-guild friendly.
"""

from typing import Final

# --- Links
Expand Down
Loading
Loading