Add auto_sync_commands configuration and create_flag command

This commit is contained in:
2025-12-08 22:41:55 +01:00
parent f4b3872941
commit cadb75aca2
4 changed files with 14 additions and 1 deletions

View File

@@ -62,6 +62,7 @@ Set the following environment variables:
- `FLAGGER_RENDERER_WORKERS`: Number of concurrent renderer workers (default: `2`)
- `FLAGWAVER_HTTP_PORT`: Port for the flagwaver HTTP server (default: `8910`)
- `UVICORN_HOST`: Host address for the Uvicorn server (default: `0.0.0.0`)
- `AUTO_SYNC_COMMANDS`: Whether to automatically sync slash commands with Discord (default: `true`)
## Installation

View File

@@ -23,7 +23,7 @@ from renderer.manager import RendererManager
logging.basicConfig(level=logging.DEBUG)
intents = Intents.default()
app = App(intents=intents, auto_sync_commands=False)
app = App(intents=intents, auto_sync_commands=CONFIG.auto_sync_commands)
FLAGWAVER_PATH = Path(__file__).parent / "flagwaver" / "dist"

View File

@@ -35,6 +35,16 @@ class FlaggerCommands(discord.Cog):
file = discord.File(gif_path, filename=gif_path.name)
await ctx.respond(view=FlagDisplayView(file), files=[file])
@discord.user_command(name="Create a Flag")
async def create_flag(self, ctx: discord.ApplicationContext, user: discord.User | discord.Member) -> None:
if user.display_avatar.is_animated():
asset = user.display_avatar.with_format("gif")
else:
asset = user.display_avatar.with_format("png")
await ctx.defer()
await self.handle_flag_command(ctx, asset.url)
flag = discord.SlashCommandGroup("flag", "Commands related to flag rendering.")
@flag.command(name="user", description="Render a user's flag.")

View File

@@ -19,6 +19,7 @@ class Config(BaseModel):
num_workers: int = 1
flagwaver_http_port: int = 8910
uvicorn_host: str = "0.0.0.0" # noqa: S104
auto_sync_commands: bool = True
CONFIG = Config(
@@ -27,6 +28,7 @@ CONFIG = Config(
num_workers=int(os.getenv("FLAGGER_RENDERER_WORKERS", "2")),
flagwaver_http_port=int(os.getenv("FLAGWAVER_HTTP_PORT", "8910")),
uvicorn_host=os.getenv("UVICORN_HOST", "0.0.0.0"), # noqa: S104
auto_sync_commands=os.getenv("AUTO_SYNC_COMMANDS", "true") == "true",
)
__all__ = ["CONFIG"]