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

Enhancement: Add guild-specific settings #9

Closed
JacobCoffee opened this issue Nov 6, 2023 · 0 comments · Fixed by #33
Closed

Enhancement: Add guild-specific settings #9

JacobCoffee opened this issue Nov 6, 2023 · 0 comments · Fixed by #33
Labels
byte 🤖 Related to the Byte bot service database 📦 Related to the Byte database service enhancement ➕ This is a brand new feature or request good intermediate issue 🥇 Good for people that like a challenge

Comments

@JacobCoffee
Copy link
Owner

JacobCoffee commented Nov 6, 2023

Summary

Currently things like command prefix, help channel ID, etc. are hard coded.

To do anything useful past one guild we need to stand up a database schema that allows for settings thing per-guild.

Basic Example

Here is a rough stub that needs worked on. I think (?) that we should introduce a new path under src/ for database things specifically, so that they can be shared between the bot and web service.

"""Shared models.

.. todo:: This is mostly a stub package that needs to be
    fleshed out.
"""

from sqlalchemy import BigInteger, Boolean, ForeignKey, String, Table
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.database.orm import TimestampedDatabaseModel

allowed_roles_table = Table(
    "allowed_roles",
    TimestampedDatabaseModel.metadata,
    mapped_column("github_config_id", ForeignKey("github_configs.id"), primary_key=True),
    mapped_column("role_id", BigInteger, primary_key=True),
)


class GuildConfig(TimestampedDatabaseModel):
    __tablename__ = "guild_configs"

    guild_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
    prefix: Mapped[str] = mapped_column(String(5), nullable=False, server_default="!", de

    help_channel_id: Mapped[int] = mapped_column(BigInteger, index=True)
    github_config: Mapped["GitHubConfig"] = relationship("GitHubConfig", uselist=False, back_populates="guild_config")


class GitHubConfig(TimestampedDatabaseModel):
    __tablename__ = "github_configs"

    guild_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("guild_configs.guild_id"), nullable=False)
    discussion_sync: Mapped[bool] = mapped_column(Boolean, default=False)
    github_organization: Mapped[str] = mapped_column(String, nullable=True)
    github_repository: Mapped[str] = mapped_column(String, nullable=True)
    sync_label: Mapped[str] = mapped_column(String, nullable=True)
    issue_linking: Mapped[bool] = mapped_column(Boolean, default=False)
    comment_linking: Mapped[bool] = mapped_column(Boolean, default=False)
    pep_linking: Mapped[bool] = mapped_column(Boolean, default=False)

    allowed_roles: Mapped[list[int]] = relationship(
        "Role",
        secondary=allowed_roles_table,
        back_populates="github_configs",
    )

    guild_config: Mapped[GuildConfig] = relationship("GuildConfig", back_populates="github_config")


class Role(TimestampedDatabaseModel):
    __tablename__ = "roles"

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True)

    github_configs: Mapped[list[GitHubConfig]] = relationship(
        "GitHubConfig",
        secondary=allowed_roles_table,
        back_populates="allowed_roles",
    )

Drawbacks and Impact

Complexity.

Unresolved questions

  • Are there any configurable things we would like to add on top of the above example?

Note

We utilize Polar.sh to engage in regular as well as pledge-based > sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@JacobCoffee JacobCoffee added the enhancement ➕ This is a brand new feature or request label Nov 6, 2023
@JacobCoffee JacobCoffee added good intermediate issue 🥇 Good for people that like a challenge byte 🤖 Related to the Byte bot service database 📦 Related to the Byte database service labels Nov 6, 2023
JacobCoffee added a commit that referenced this issue Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
byte 🤖 Related to the Byte bot service database 📦 Related to the Byte database service enhancement ➕ This is a brand new feature or request good intermediate issue 🥇 Good for people that like a challenge
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant