emoji fix + poll fork
This commit is contained in:
parent
3f84fe60ec
commit
a110b13ffb
@ -92,12 +92,19 @@ class Poll:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create(cls, ctx: Context, options: list[tuple[str, discord.Emoji | str]], title: str):
|
async def create(
|
||||||
|
cls, ctx: Context, options: list[tuple[str, discord.Emoji | str]], title: str,
|
||||||
|
votes: dict[discord.Member, str]
|
||||||
|
):
|
||||||
message: discord.Message = await ctx.reply('creating poll...')
|
message: discord.Message = await ctx.reply('creating poll...')
|
||||||
async with lock_for(message, 'failed to create poll'):
|
async with lock_for(message, 'failed to create poll'):
|
||||||
poll = Poll(
|
if len(set(emoji for option, emoji in options)) != len(options):
|
||||||
|
raise Explicit('duplicate emojis')
|
||||||
|
if len(set(option for option, emoji in options)) != len(options):
|
||||||
|
raise Explicit('duplicate options')
|
||||||
|
poll = cls(
|
||||||
message,
|
message,
|
||||||
{},
|
votes,
|
||||||
{option: str(emoji) for option, emoji in options},
|
{option: str(emoji) for option, emoji in options},
|
||||||
[option for option, _ in options],
|
[option for option, _ in options],
|
||||||
title
|
title
|
||||||
@ -167,10 +174,11 @@ async def poll_options(args: list[str]) -> list[tuple[str, discord.Emoji | str]]
|
|||||||
while args:
|
while args:
|
||||||
match args:
|
match args:
|
||||||
case [emoji, option, *args]:
|
case [emoji, option, *args]:
|
||||||
|
if '<' in emoji and '>' in emoji:
|
||||||
try:
|
try:
|
||||||
emoji = client.get_emoji(
|
emoji = client.get_emoji(
|
||||||
int(''.join(c for c in emoji.rsplit(':', 1)[-1] if c.isdecimal()))
|
int(''.join(c for c in emoji.rsplit(':', 1)[-1] if c.isdecimal()))
|
||||||
)
|
) or emoji
|
||||||
except (discord.NotFound, ValueError):
|
except (discord.NotFound, ValueError):
|
||||||
pass
|
pass
|
||||||
options.append((option, emoji))
|
options.append((option, emoji))
|
||||||
@ -184,10 +192,17 @@ async def create_poll(ctx: Context, args: list[str]) -> None:
|
|||||||
match args:
|
match args:
|
||||||
case ['help']:
|
case ['help']:
|
||||||
await ctx.reply('`poll title emoji option [emoji option ...]`')
|
await ctx.reply('`poll title emoji option [emoji option ...]`')
|
||||||
|
await ctx.reply('`poll emoji option [emoji option ...]` (reply fork)')
|
||||||
case []:
|
case []:
|
||||||
raise Explicit('no options')
|
raise Explicit('no options')
|
||||||
|
case [*args] if ctx.message.reference is not None and ctx.message.reference.resolved is not None:
|
||||||
|
refd: discord.Message = ctx.message.reference.resolved
|
||||||
|
poll = await Poll.load(refd)
|
||||||
|
if poll is None:
|
||||||
|
raise Explicit('referenced message is not a poll')
|
||||||
|
await Poll.create(ctx, await poll_options(args), poll.title, poll.votes)
|
||||||
case [title, *args]:
|
case [title, *args]:
|
||||||
await Poll.create(ctx, await poll_options(args), title)
|
await Poll.create(ctx, await poll_options(args), title, {})
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
|
Loading…
Reference in New Issue
Block a user