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

Adds support to provide owner notices #1602

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Adds notice support to guild model.

Revision ID: ffd25c8a3d06
Revises: 208851cc40e3
Create Date: 2024-06-08 18:52:40.575385

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "ffd25c8a3d06"
down_revision = "208851cc40e3"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"guilds",
sa.Column(
"notice",
sa.String(length=255),
server_default=sa.text("NULL"),
nullable=True,
),
)


def downgrade() -> None:
op.drop_column("guilds", "notice")
2 changes: 2 additions & 0 deletions src/spellbot/models/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def embed_title(self) -> str:

def embed_description(self, dm: bool = False) -> str: # noqa: C901,PLR0912
description = ""
if self.guild.notice:
description += f"{self.guild.notice}\n\n"
if self.status == GameStatus.PENDING.value:
description += "_A SpellTable link will be created when all players have joined._"
else:
Expand Down
11 changes: 10 additions & 1 deletion src/spellbot/models/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime
from typing import TYPE_CHECKING, TypedDict, cast

from sqlalchemy import BigInteger, Boolean, Column, DateTime, String, false
from sqlalchemy import BigInteger, Boolean, Column, DateTime, String, false, null
from sqlalchemy.orm import relationship

from . import Base, now
Expand All @@ -25,6 +25,7 @@ class GuildDict(TypedDict):
channels: list[ChannelDict]
awards: list[GuildAwardDict]
banned: bool
notice: str


class Guild(Base):
Expand Down Expand Up @@ -77,6 +78,13 @@ class Guild(Base):
server_default=false(),
doc="If true, this guild is banned from using SpellBot",
)
notice = Column(
String(255),
doc="Notice to display to users in this guild",
nullable=True,
default=None,
server_default=null(),
)

games = relationship(
"Game",
Expand Down Expand Up @@ -116,4 +124,5 @@ def to_dict(self) -> GuildDict:
key=lambda c: c["id"],
),
"banned": self.banned,
"notice": self.notice,
}
18 changes: 18 additions & 0 deletions tests/models/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ def test_game_embed_started_with_arena(
"type": "rich",
}

def test_game_with_guild_notice(self, settings: Settings, factories: Factories) -> None:
guild = factories.guild.create(motd=None, notice="this is a notice")
channel = factories.channel.create(guild=guild, show_points=True, motd=None)
game = factories.game.create(
seats=2,
status=GameStatus.STARTED.value,
started_at=datetime(2021, 10, 31, tzinfo=pytz.utc),
guild=guild,
channel=channel,
)
factories.user.create(game=game)
factories.user.create(game=game)
assert game.to_embed().to_dict()["description"] == (
"this is a notice\n\n"
"Please check your Direct Messages for your game details.\n\n"
"When your game is over use the drop down to report your points."
)

def test_game_embed_started_with_points(
self,
settings: Settings,
Expand Down
1 change: 1 addition & 0 deletions tests/models/test_guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def test_guild(self, factories: Factories) -> None:
key=lambda c: c["id"],
),
"banned": guild.banned,
"notice": guild.notice,
}
Loading