Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Implement Select Menus #4

Closed
norinorin opened this issue Sep 24, 2021 · 0 comments
Closed

Implement Select Menus #4

norinorin opened this issue Sep 24, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@norinorin
Copy link
Owner

Things to note:

  • character limits;
  • option limits;
  • the content can't be empty—will set the placeholder as the content and set a default option.

async def pick_from_sequence(
self,
ctx: Context,
query: str,
/,
seq: typing.Sequence[T],
title: typing.Tuple[str, str],
format: str,
) -> typing.Optional[T]:
ret = None
if len(seq) == 1:
return seq[0]
# This if statement adds an overhead, but w/e
if (
len(entries := [i for i in seq if str(i).lower() == query.lower()]) == 1
or len(entries := [i for i in seq if fuzz.ratio(str(i), query) >= 75]) == 1
):
return entries[0]
embed = hikari.Embed(
title=title[not seq],
description="\n".join(
f"{idx}. {format.format(item=item)}"
for idx, item in enumerate(seq, start=1)
),
)
respond = await ctx.respond(embed=embed)
if seq:
with suppress(asyncio.TimeoutError):
msg = await self.bot.wait_for(
hikari.GuildMessageCreateEvent,
predicate=lambda m: m.author.id == ctx.author.id
and m.channel_id == ctx.channel_id,
timeout=60,
)
if msg.content.isdigit():
index = int(msg.content) - 1
if index >= len(seq):
await ctx.respond(f"Number should be from 1 to {len(seq)}")
else:
ret = seq[index]
await respond.delete()
return ret

@norinorin norinorin added the enhancement New feature or request label Sep 24, 2021
@norinorin norinorin self-assigned this Sep 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant