Skip to content

Commit 82318ff

Browse files
committed
fix: mark as solved and accept solution
1 parent 19b570f commit 82318ff

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed

src/cogs/forum/auto_tagging.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
)
1515
from discord.app_commands import ContextMenu, command, describe
1616
from discord.enums import AppCommandType
17-
from discord.ext.commands import Bot, Cog, GroupCog, command as prefixed_command
17+
from discord.ext.commands import Bot, Cog, GroupCog
18+
from discord.ext.commands import command as prefixed_command
1819
from discord.ext.commands.context import Context
1920
from discord.types.embed import Embed
2021
from discord.ui.select import Select
@@ -373,6 +374,9 @@ async def edit(self, interaction: Interaction, config_id: int):
373374
tags = await self.db.get_tags(config_id)
374375
existing_tags: list[Role] | list[Member] = []
375376

377+
# Get current configuration values
378+
current_enable_accept_solutions = config.get("enable_accept_solutions", False)
379+
376380
mark_as_solved_config = await self.db.get_mark_as_solved_config(config_id)
377381
current_mark_as_solved = (
378382
mark_as_solved_config["enable_mark_as_solved"]
@@ -392,6 +396,7 @@ async def edit(self, interaction: Interaction, config_id: int):
392396
tag_message=tag_message,
393397
custom_msg=custom_message,
394398
existing_tags=existing_tags,
399+
enable_accept_solutions=current_enable_accept_solutions,
395400
enable_mark_as_solved=current_mark_as_solved,
396401
)
397402

@@ -417,6 +422,7 @@ async def edit(self, interaction: Interaction, config_id: int):
417422
entities=tags,
418423
entity_tag_message=tag_message,
419424
reply=reply,
425+
enable_accept_solutions=modal.state.enable_accept_solutions,
420426
enable_mark_as_solved=modal.state.enable_mark_as_solved,
421427
)
422428

src/data/forum/post_assist.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ async def update_configuration(
218218
entities: list[tuple[int, str]],
219219
entity_tag_message: str,
220220
reply: str,
221+
enable_accept_solutions: bool | None = None,
221222
enable_mark_as_solved: bool | None = None,
222223
):
223224
"""Updates a configuration to the database.
@@ -226,6 +227,7 @@ async def update_configuration(
226227
:param entities: The entities to add
227228
:param entity_tag_message: The tag message
228229
:param reply: The reply message
230+
:param enable_accept_solutions: Enable accept solutions app command
229231
:param enable_mark_as_solved: Whether to enable mark as solved button
230232
"""
231233

@@ -237,29 +239,19 @@ async def update_configuration(
237239
if not config:
238240
return
239241

240-
# Update the main configuration
241-
if enable_mark_as_solved is not None:
242-
await conn.execute(
243-
"""
244-
UPDATE pph_post_assist_config SET
245-
forum_id = $1,
246-
enable_mark_as_solved = $3
247-
WHERE id = $2;
248-
""",
249-
forum_id,
250-
id,
251-
enable_mark_as_solved,
252-
)
253-
else:
254-
await conn.execute(
255-
"""
256-
UPDATE pph_post_assist_config SET
257-
forum_id = $1
258-
WHERE id = $2;
242+
await conn.execute(
243+
"""
244+
UPDATE pph_post_assist_config SET
245+
forum_id = $1,
246+
enable_accept_solutions = COALESCE($3, enable_accept_solutions),
247+
enable_mark_as_solved = COALESCE($4, enable_mark_as_solved)
248+
WHERE id = $2;
259249
""",
260-
forum_id,
261-
id,
262-
)
250+
forum_id,
251+
id,
252+
enable_accept_solutions,
253+
enable_mark_as_solved,
254+
)
263255

264256
await conn.execute(
265257
"""

src/ui/views/post_assist.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
enable_accept_solutions: bool = False,
2929
enable_mark_as_solved: bool = False,
3030
finished: bool = False,
31-
failed: bool = False
31+
failed: bool = False,
3232
):
3333
self.forum: int = forum
3434
self.tag_list: list[tuple[int, str]] = []
@@ -47,7 +47,7 @@ def __init__(
4747
forum: int = None,
4848
tag_message: str = None,
4949
custom_msg: str = None,
50-
db: PostAssistDB = None
50+
db: PostAssistDB = None,
5151
):
5252
super().__init__(timeout=480)
5353
self.db = db
@@ -189,17 +189,32 @@ async def enable(self, interaction: Interaction, button: Button):
189189
)
190190

191191
enable_mark_as_solved_button = PostAssistEnableMarkAsSolvedButton(self.state)
192-
await interaction.followup.send("Enable Mark as Solved feature?", view=enable_mark_as_solved_button, ephemeral=True)
192+
await interaction.followup.send(
193+
"Enable Mark as Solved feature?",
194+
view=enable_mark_as_solved_button,
195+
ephemeral=True,
196+
)
193197
await enable_mark_as_solved_button.wait()
194198
self.stop()
195199

196200
@button(label="No")
197201
async def disable(self, interaction: Interaction, button: Button):
198202
self.state.enable_accept_solutions = False
199203
self.state.finished = True
200-
await interaction.response.send_message("Accept solutions disabled.", ephemeral=True)
204+
await interaction.response.send_message(
205+
"Accept solutions disabled.", ephemeral=True
206+
)
207+
208+
enable_mark_as_solved_button = PostAssistEnableMarkAsSolvedButton(self.state)
209+
await interaction.followup.send(
210+
"Enable Mark as Solved feature?",
211+
view=enable_mark_as_solved_button,
212+
ephemeral=True,
213+
)
214+
await enable_mark_as_solved_button.wait()
201215
self.stop()
202216

217+
203218
class PostAssistEnableMarkAsSolvedButton(View):
204219
def __init__(self, options: PostAssistState):
205220
super().__init__(timeout=480)
@@ -212,17 +227,22 @@ async def enable_mark_as_solved(self, interaction: Interaction, button: Button):
212227
self.state.enable_mark_as_solved = True
213228
self.state.finished = True
214229

215-
await interaction.followup.send("Mark as solved will be enabled.", ephemeral=True)
230+
await interaction.followup.send(
231+
"Mark as solved will be enabled.", ephemeral=True
232+
)
216233

217234
self.stop()
218235

219236
@button(label="No")
220237
async def disable_mark_as_solved(self, interaction: Interaction, button: Button):
221238
self.state.enable_mark_as_solved = False
222239
self.state.finished = True
223-
await interaction.response.send_message("Mark as solved disabled.", ephemeral=True)
240+
await interaction.response.send_message(
241+
"Mark as solved disabled.", ephemeral=True
242+
)
224243
self.stop()
225244

245+
226246
class ConfigurationPagination(View):
227247
def __init__(self, data: list[dict], getter: Callable):
228248
self.data = data
@@ -258,29 +278,26 @@ async def next(self, interaction: Interaction, button: Button):
258278
view=self,
259279
)
260280

281+
261282
def get_forums(db: Settings, guild: Guild) -> View:
262283
"""Gets all forums."""
263284

264285
async def select_callback(interaction: Interaction):
265286
await db.set_setting("dev_help_forum", int(forum_selection.values[0]))
266-
await interaction.response.edit_message(
267-
content=f"Success...",
268-
view=None
269-
)
287+
await interaction.response.edit_message(content=f"Success...", view=None)
270288
view.stop()
271289

272290
view = View()
273291
forum_selection = Select(placeholder="Select Forum...")
274292
forum_selection.callback = select_callback
275293

276294
for forum in guild.forums:
277-
forum_selection.add_option(
278-
label=forum.name, value=str(forum.id)
279-
)
295+
forum_selection.add_option(label=forum.name, value=str(forum.id))
280296

281297
view.add_item(forum_selection)
282298
return view
283299

300+
284301
def format_data(data: dict, guild: Guild, getter: Callable):
285302
forum = guild.get_channel(data["forum_id"])
286303
tags = data["tags"]

0 commit comments

Comments
 (0)