Skip to content

Commit deaf82d

Browse files
committed
feat: add /auto-enter slash command
1 parent 942635e commit deaf82d

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

luckypot/discord/commands.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,52 @@ async def invoke(self, ctx: lightbulb.Context) -> None:
138138
components=[container], flags=hikari.MessageFlag.EPHEMERAL
139139
)
140140

141+
@client.register(guilds=guilds)
142+
class AutoEnter(
143+
lightbulb.SlashCommand,
144+
name="auto-enter",
145+
description="Automatically enter each new pot when one starts",
146+
):
147+
enabled: bool = lightbulb.boolean(
148+
"enabled",
149+
"Whether to enable auto-enter (default: True)",
150+
default=True,
151+
)
152+
153+
@lightbulb.invoke
154+
async def invoke(self, ctx: lightbulb.Context) -> None:
155+
guild_id = str(ctx.guild_id)
156+
discord_id = str(ctx.user.id)
157+
158+
try:
159+
conn = db.get_connection()
160+
try:
161+
current = db.get_auto_enter_status(conn, discord_id, guild_id)
162+
if current == self.enabled:
163+
container = ui.build_auto_enter_already_in_state(self.enabled)
164+
await ctx.respond(
165+
components=[container], flags=hikari.MessageFlag.EPHEMERAL
166+
)
167+
return
168+
db.set_auto_enter(conn, discord_id, guild_id, self.enabled)
169+
finally:
170+
conn.close()
171+
172+
if self.enabled:
173+
container = ui.build_auto_enter_opted_in()
174+
else:
175+
container = ui.build_auto_enter_opted_out()
176+
await ctx.respond(
177+
components=[container], flags=hikari.MessageFlag.EPHEMERAL
178+
)
179+
180+
except Exception as e:
181+
logger.error(f"Error in /auto-enter for user {ctx.user.id}: {e}")
182+
container = ui.build_entry_error(f"An unexpected error occurred: {e}")
183+
await ctx.respond(
184+
components=[container], flags=hikari.MessageFlag.EPHEMERAL
185+
)
186+
141187
if settings.debug_mode and guilds:
142188

143189
@client.register(guilds=guilds)

luckypot/discord/ui.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,41 @@ def build_pot_history(history: list[dict], page: int = 1) -> ContainerComponentB
126126
)
127127

128128
return container
129+
130+
131+
def build_auto_enter_opted_in() -> ContainerComponentBuilder:
132+
"""Build response when user successfully opts in to auto-enter."""
133+
container = ContainerComponentBuilder(accent_color=BRAND_COLOR)
134+
container.add_text_display("✅ Auto-Enter Enabled")
135+
container.add_separator(divider=True, spacing=hikari.SpacingType.SMALL)
136+
container.add_text_display(
137+
"You will automatically be entered into each new pot. "
138+
"Use `/auto-enter enabled:False` to opt out."
139+
)
140+
return container
141+
142+
143+
def build_auto_enter_opted_out() -> ContainerComponentBuilder:
144+
"""Build response when user successfully opts out of auto-enter."""
145+
container = ContainerComponentBuilder(accent_color=BRAND_COLOR)
146+
container.add_text_display("✅ Auto-Enter Disabled")
147+
container.add_separator(divider=True, spacing=hikari.SpacingType.SMALL)
148+
container.add_text_display(
149+
"You will no longer be automatically entered into pots. "
150+
"Use `/auto-enter` to opt back in."
151+
)
152+
return container
153+
154+
155+
def build_auto_enter_already_in_state(enabled: bool) -> ContainerComponentBuilder:
156+
"""Build response when user is already in the requested state."""
157+
container = ContainerComponentBuilder(accent_color=BRAND_COLOR)
158+
if enabled:
159+
container.add_text_display("ℹ️ Already Opted In")
160+
container.add_separator(divider=True, spacing=hikari.SpacingType.SMALL)
161+
container.add_text_display("You are already opted in to auto-enter.")
162+
else:
163+
container.add_text_display("ℹ️ Already Opted Out")
164+
container.add_separator(divider=True, spacing=hikari.SpacingType.SMALL)
165+
container.add_text_display("You are already opted out of auto-enter.")
166+
return container

0 commit comments

Comments
 (0)