Skip to content

Commit 026cdf8

Browse files
committed
Revert "threadmenu: submenu navigation fixes"
This reverts commit 55dc8c8.
1 parent 55dc8c8 commit 026cdf8

2 files changed

Lines changed: 23 additions & 96 deletions

File tree

cogs/threadmenu.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,6 @@ def typecheck(m):
178178
if label.lower() == "cancel":
179179
return await ctx.send("Cancelled.")
180180

181-
if label.lower() == "main menu":
182-
return await ctx.send("You cannot use that label.")
183-
184181
if sanitized_label in conf["options"]:
185182
await ctx.send("That option already exists. Use `threadmenu edit` to edit it.")
186183
return

core/thread.py

Lines changed: 23 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,16 @@ async def snooze(self, moderator=None, command_used=None, snooze_for=None):
224224
"author_name": (
225225
getattr(m.embeds[0].author, "name", "").split(" (")[0]
226226
if m.embeds and m.embeds[0].author and m.author == self.bot.user
227-
else getattr(m.author, "name", None) if m.author != self.bot.user else None
227+
else getattr(m.author, "name", None)
228+
if m.author != self.bot.user
229+
else None
228230
),
229231
"author_avatar": (
230232
getattr(m.embeds[0].author, "icon_url", None)
231233
if m.embeds and m.embeds[0].author and m.author == self.bot.user
232-
else m.author.display_avatar.url if m.author != self.bot.user else None
234+
else m.author.display_avatar.url
235+
if m.author != self.bot.user
236+
else None
233237
),
234238
}
235239
async for m in channel.history(limit=None, oldest_first=True)
@@ -845,9 +849,11 @@ async def send_genesis_message():
845849
if getattr(self, "_selected_thread_creation_menu_option", None) and self.bot.config.get(
846850
"thread_creation_menu_selection_log"
847851
):
848-
path = self._selected_thread_creation_menu_option
852+
opt = self._selected_thread_creation_menu_option
849853
try:
850-
log_txt = f"Selected menu path: {' -> '.join(path)}"
854+
log_txt = f"Selected menu option: {opt.get('label')} ({opt.get('type')})"
855+
if opt.get("type") == "command":
856+
log_txt += f" -> {opt.get('callback')}"
851857
await channel.send(embed=discord.Embed(description=log_txt, color=self.bot.mod_color))
852858
except Exception:
853859
logger.warning(
@@ -2653,44 +2659,29 @@ async def create(
26532659
placeholder = "Select an option to contact the staff team."
26542660
timeout = 20
26552661

2662+
options = self.bot.config.get("thread_creation_menu_options") or {}
2663+
submenus = self.bot.config.get("thread_creation_menu_submenus") or {}
2664+
26562665
# Minimal inline view implementation (avoid importing plugin code)
26572666

26582667
thread.ready = False # not ready yet
26592668

26602669
class _ThreadCreationMenuSelect(discord.ui.Select):
2661-
def __init__(
2662-
self,
2663-
bot,
2664-
outer_thread: Thread,
2665-
option_data: dict,
2666-
menu_msg: discord.Message,
2667-
path: list,
2668-
is_home: bool = True,
2669-
):
2670-
self.bot = bot
2670+
def __init__(self, outer_thread: Thread):
26712671
self.outer_thread = outer_thread
2672-
self.option_data = option_data
2673-
self.menu_msg = menu_msg
2674-
self.path = path
2675-
options = [
2672+
opts = [
26762673
discord.SelectOption(
26772674
label=o["label"],
26782675
description=o["description"],
26792676
emoji=o["emoji"],
26802677
)
2681-
for o in option_data.values()
2678+
for o in options.values()
26822679
]
2683-
if not is_home:
2684-
options.append(
2685-
discord.SelectOption(
2686-
label="main menu", description="Return to the main menu", emoji="🏠"
2687-
)
2688-
)
26892680
super().__init__(
26902681
placeholder=placeholder,
26912682
min_values=1,
26922683
max_values=1,
2693-
options=options,
2684+
options=opts,
26942685
)
26952686

26962687
async def callback(self, interaction: discord.Interaction):
@@ -2705,45 +2696,8 @@ async def callback(self, interaction: discord.Interaction):
27052696
chosen_label = self.values[0]
27062697
# Resolve option key
27072698
key = chosen_label.lower().replace(" ", "_")
2708-
if key == "main_menu":
2709-
option_data = self.bot.config.get("thread_creation_menu_options") or {}
2710-
new_view = _ThreadCreationMenuView(
2711-
self.bot,
2712-
self.outer_thread,
2713-
option_data,
2714-
self.menu_msg,
2715-
path=[],
2716-
is_home=True,
2717-
)
2718-
return await self.menu_msg.edit(view=new_view)
2719-
selected: dict = self.option_data.get(key, {})
2720-
next_path = [*self.path, chosen_label]
2721-
if selected.get("type", "command") == "submenu":
2722-
submenu_data = self.bot.config.get("thread_creation_menu_submenus") or {}
2723-
submenu_key = selected.get("callback", key)
2724-
option_data = submenu_data.get(submenu_key, {})
2725-
if not option_data:
2726-
home_options = self.bot.config.get("thread_creation_menu_options") or {}
2727-
new_view = _ThreadCreationMenuView(
2728-
self.bot,
2729-
self.outer_thread,
2730-
home_options,
2731-
self.menu_msg,
2732-
path=[],
2733-
is_home=True,
2734-
)
2735-
return await self.menu_msg.edit(view=new_view)
2736-
new_view = _ThreadCreationMenuView(
2737-
self.bot,
2738-
self.outer_thread,
2739-
option_data,
2740-
self.menu_msg,
2741-
path=next_path,
2742-
is_home=False,
2743-
)
2744-
return await self.menu_msg.edit(view=new_view)
2745-
2746-
self.outer_thread._selected_thread_creation_menu_option = next_path
2699+
selected = options.get(key)
2700+
self.outer_thread._selected_thread_creation_menu_option = selected
27472701
# Reflect the selection in the original DM by editing the embed/body
27482702
try:
27492703
msg = getattr(interaction, "message", None)
@@ -2982,30 +2936,10 @@ async def callback(self, interaction: discord.Interaction):
29822936
ctx_.command.checks = old_checks
29832937

29842938
class _ThreadCreationMenuView(discord.ui.View):
2985-
def __init__(
2986-
self,
2987-
bot,
2988-
outer_thread: Thread,
2989-
option_data: dict,
2990-
menu_msg: discord.Message,
2991-
path: list,
2992-
is_home: bool = True,
2993-
):
2939+
def __init__(self, outer_thread: Thread):
29942940
super().__init__(timeout=timeout)
29952941
self.outer_thread = outer_thread
2996-
self.path = path
2997-
self.menu_msg = menu_msg
2998-
self.option_data = option_data
2999-
self.add_item(
3000-
_ThreadCreationMenuSelect(
3001-
bot,
3002-
outer_thread,
3003-
option_data=option_data,
3004-
menu_msg=menu_msg,
3005-
path=self.path,
3006-
is_home=is_home,
3007-
)
3008-
)
2942+
self.add_item(_ThreadCreationMenuSelect(outer_thread))
30092943

30102944
async def on_timeout(self):
30112945
# Timeout -> abort thread creation
@@ -3127,12 +3061,8 @@ async def on_timeout(self):
31273061
embed.set_thumbnail(url=embed_thumb)
31283062
except Exception as e:
31293063
logger.debug("Thumbnail set failed (ignored): %s", e)
3130-
menu_msg = await recipient.send(embed=embed)
3131-
option_data = self.bot.config.get("thread_creation_menu_options") or {}
3132-
menu_view = _ThreadCreationMenuView(
3133-
self.bot, thread, option_data, menu_msg, path=[], is_home=True
3134-
)
3135-
menu_msg = await menu_msg.edit(view=menu_view)
3064+
menu_view = _ThreadCreationMenuView(thread)
3065+
menu_msg = await recipient.send(embed=embed, view=menu_view)
31363066
# mark thread as pending menu selection
31373067
thread._pending_menu = True
31383068
# Explicitly attach the message to the view for safety in callbacks

0 commit comments

Comments
 (0)