Skip to content

feat: adjust settings to use guild configs #87

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

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
07ff50e
feat: add server count to web ui
JacobCoffee Mar 3, 2024
100afd3
feat: add event message for new guild joins in dev discord
JacobCoffee Mar 3, 2024
5493f26
feat: use guild settings for issue creation link
JacobCoffee Mar 3, 2024
a9c2512
fix(ui): adjust plurality of server count
JacobCoffee Mar 3, 2024
17c3849
feat: allow guild-specific github issues
JacobCoffee Mar 3, 2024
884ac3d
docs: add api ref docs
JacobCoffee Mar 3, 2024
ba8c053
fix(docs): adjust stale links
JacobCoffee Mar 3, 2024
1b6c0f5
fix: better type hints
Mar 3, 2024
179567c
feat: add scaffolding for guild configuration
JacobCoffee Mar 3, 2024
2d420b2
docs: update documentation refs
JacobCoffee Mar 3, 2024
3fc9cc5
docs: add basic usage information docs
JacobCoffee Mar 3, 2024
b4ca2d2
feat(ui): add live health to home page
JacobCoffee Mar 3, 2024
12a3eab
feat: enhance guild schema detail
JacobCoffee Mar 4, 2024
a065749
feat: add predicate for guild admin check
JacobCoffee Mar 9, 2024
7049464
feat: add guild configuration command (#78)
JacobCoffee Mar 10, 2024
14de143
feat: add model for forum configuration
JacobCoffee Mar 10, 2024
a5654db
feat: update schema for updateable settings
JacobCoffee Mar 10, 2024
c456370
ci: add helpers for container setup and teardown
JacobCoffee Mar 11, 2024
5280591
feat: update schemas and route for updating
JacobCoffee Mar 11, 2024
fa3e0c9
fix: correctly load forum config
JacobCoffee Mar 11, 2024
adebee9
ci: update deps
JacobCoffee Mar 11, 2024
ad51f34
feat: add routes to display sections on guild data
JacobCoffee Mar 11, 2024
69f322b
ci: add helper for full container refresh
JacobCoffee Mar 11, 2024
6b39f28
fix!: new migration for uuid issues
JacobCoffee Mar 11, 2024
5dc1634
fix: remove blanket check for delete button view
JacobCoffee Mar 11, 2024
1ae4a7e
fix: allow dropdown for config key
JacobCoffee Mar 11, 2024
93f8fca
chore: updates
JacobCoffee May 11, 2024
d2988d5
ci: 3.11 only in railway
JacobCoffee May 11, 2024
4aac895
feat: fully rebased off of uv PR
JacobCoffee Oct 11, 2024
7b31ee9
fix: lol jk but for real this time
JacobCoffee Oct 11, 2024
1bdb95a
style: idk but it auto added so committing
JacobCoffee Oct 11, 2024
09f653e
Update .pdm-python
JacobCoffee Oct 11, 2024
90c2ef1
Update Makefile
JacobCoffee Oct 11, 2024
c841ae3
fix(ci): update run cmd
JacobCoffee Oct 11, 2024
e419a50
fix: adjust to new advanced-alchemy signature
JacobCoffee Oct 11, 2024
262ba1a
chore: add todo line for #88
JacobCoffee Oct 11, 2024
bfa5ca3
chore: update deps
JacobCoffee Jun 12, 2025
cc5e24d
feat: add in partial container load support (migrations, not fixtures)
JacobCoffee Jun 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pdm-python
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.venv/bin/python
/Users/jcoffee5/git/public/JacobCoffee/byte/.venv/bin/python
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: "3.11"
python: "3.12"
default_install_hook_types: [commit-msg, pre-commit]
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python 3.11
python 3.12
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ install: clean destroy ## Install the project, dependencies, and pre-co
@$(MAKE) install-frontend
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"

up-container: ## Start the Byte database container
@echo "=> Starting Byte database container"
@docker compose -f docker-compose.infra.yml up -d
@echo "=> Started Byte database container"

clean-container: ## Stop, remove, and wipe the Byte database container and volume
@echo "=> Stopping and removing Byte database container"
@docker stop byte-db-1
@docker rm byte-db-1
@docker volume rm byte_db-data
@echo "=> Stopped and removed Byte database container"

load-container: migrate ## Perform database migrations and load test data into the Byte database container
@echo "=> Loading database migrations and test data"
@echo "not yet implemented"
@echo "=> Loaded database migrations and test data"

refresh-container: clean-container up-container load-container ## Refresh the Byte database container


.PHONY: refresh-lockfiles
refresh-lockfiles: ## Sync lockfiles with requirements files.
$(PDM) update --update-reuse -G:all

.PHONY: lock
lock: ## Rebuild lockfiles from scratch, updating all dependencies
$(PDM) update --update-eager -G:all

# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions byte_bot/byte/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from __future__ import annotations

from byte_bot.byte import bot, lib
from byte_bot.byte import bot, lib, plugins, views
from byte_bot.byte.lib.log import setup_logging

__all__ = ["bot", "lib"]
__all__ = ("bot", "lib", "views", "setup_logging", "plugins")

setup_logging()
56 changes: 33 additions & 23 deletions byte_bot/byte/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from discord import Activity, Forbidden, Intents, Member, Message, NotFound
from discord.ext.commands import Bot, CommandError, Context, ExtensionAlreadyLoaded
from dotenv import load_dotenv
from httpx import ConnectError

from byte_bot.byte.lib import settings
from byte_bot.byte.lib.log import get_logger
Expand All @@ -23,18 +24,6 @@
load_dotenv()


async def on_member_join(member: Member) -> None:
"""Handle member join event.

Args:
member: Member object.
"""
await member.send(
f"Welcome to {member.guild.name}! Please make sure to read the rules if you haven't already. "
f"Feel free to ask any questions you have in the help channel."
)


class Byte(Bot):
"""Byte Bot Base Class."""

Expand Down Expand Up @@ -112,10 +101,11 @@ async def on_member_join(member: Member) -> None:
Args:
member: Member object.
"""
await member.send(
f"Welcome to {member.guild.name}! Please make sure to read the rules if you haven't already. "
f"Feel free to ask any questions you have in the help channel."
)
if not member.bot:
await member.send(
f"Welcome to {member.guild.name}! Please make sure to read the rules if you haven't already. "
f"Feel free to ask any questions you have in the help channel."
)

async def on_guild_join(self, guild: discord.Guild) -> None:
"""Handle guild join event.
Expand All @@ -126,13 +116,33 @@ async def on_guild_join(self, guild: discord.Guild) -> None:
await self.tree.sync(guild=guild)
api_url = f"http://0.0.0.0:8000/api/guilds/create?guild_id={guild.id}&guild_name={guild.name}"

async with httpx.AsyncClient() as client:
response = await client.post(api_url)

if response.status_code == httpx.codes.CREATED:
logger.info("successfully added guild %s (ID: %s)", guild.name, guild.id)
else:
logger.error("%s joined guild '%s' but was not added to database", self.user.name, guild.name)
try:
async with httpx.AsyncClient() as client:
response = await client.post(api_url)

if response.status_code == httpx.codes.CREATED:
logger.info("successfully added guild %s (id: %s)", guild.name, guild.id)
embed = discord.Embed(
title="Guild Joined",
description=f"Joined guild {guild.name} (ID: {guild.id})",
color=discord.Color.green(),
)
else:
embed = discord.Embed(
title="Guild Join Failed",
description=f"Joined guild, but failed to add guild {guild.name} (ID: {guild.id}) to database",
color=discord.Color.red(),
)

if dev_guild := self.get_guild(settings.discord.DEV_GUILD_ID):
if dev_channel := dev_guild.get_channel(settings.discord.DEV_GUILD_INTERNAL_ID):
await dev_channel.send(embed=embed)
else:
logger.error("dev channel not found.")
else:
logger.error("dev guild not found.")
except ConnectError:
logger.exception("failed to connect to api to add guild %s (id: %s)", guild.name, guild.id)


def run_bot() -> None:
Expand Down
3 changes: 2 additions & 1 deletion byte_bot/byte/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Byte library module."""

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

__all__ = [
"settings",
"utils",
"log",
"common",
"types",
]
65 changes: 65 additions & 0 deletions byte_bot/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_bot.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 byte_bot/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_bot.byte.lib.common import assets, colors, guilds, links
from typing import Any

from byte_bot.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
]
7 changes: 6 additions & 1 deletion byte_bot/byte/lib/common/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
from typing import Final

# --- Colors
litestar_blue: Final = 0x7289DA
litestar_blue: Final = 0x202235
litestar_yellow: Final = 0xEDB641

python_blue: Final = 0x4B8BBE
python_yellow: Final = 0xFFD43B

astral_yellow: Final = 0xD7FF64
astral_purple: Final = 0x261230

byte_teal: Final = 0x42B1A8
5 changes: 0 additions & 5 deletions byte_bot/byte/lib/common/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
from typing import Final

# --- Links
litestar_issues: Final = "https://github.com/litestar-org/litestar/issues"
github_litestar_projects: Final = "https://github.com/orgs/litestar-org/litestar/projects"
github_org_projects: Final = "https://github.com/orgs/litestar-org/projects"
pypi_litestar: Final = "https://pypi.org/project/litestar/"
pypi_polyfactory: Final = "https://pypi.org/project/polyfactory/"
mcve: Final = "https://stackoverflow.com/help/minimal-reproducible-example"
pastebin: Final = "https://paste.pythondiscord.com"
markdown_guide: Final = "https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-#h_01GY0DAKGXDEHE263BCAYEGFJA"
Loading
Loading