mirror of
https://github.com/Paillat-dev/flagger.git
synced 2026-01-02 01:06:21 +00:00
✨ Add auto_sync_commands configuration and create_flag command
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user