diff --git a/README.md b/README.md index 7957930..2eeee49 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/__main__.py b/src/__main__.py index 427c030..f0c6fd0 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -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" diff --git a/src/commands/flag_gen.py b/src/commands/flag_gen.py index 043d5c8..9432b06 100644 --- a/src/commands/flag_gen.py +++ b/src/commands/flag_gen.py @@ -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.") diff --git a/src/config.py b/src/config.py index 690baf0..03876d5 100644 --- a/src/config.py +++ b/src/config.py @@ -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"]