fix: Protect all acmpl lengths.

This commit is contained in:
2023-10-08 12:00:32 +03:00
parent 91a3f595b5
commit 1b4cfd0453
9 changed files with 39 additions and 39 deletions

View File

@@ -241,7 +241,7 @@ class BabelCog(LionCog):
matching = {item for item in formatted if partial in item[1] or partial in item[0]} matching = {item for item in formatted if partial in item[1] or partial in item[0]}
if matching: if matching:
choices = [ choices = [
appcmds.Choice(name=localestr, value=locale) appcmds.Choice(name=localestr[:100], value=locale)
for locale, localestr in matching for locale, localestr in matching
] ]
else: else:
@@ -250,7 +250,7 @@ class BabelCog(LionCog):
name=t(_p( name=t(_p(
'acmpl:language|no_match', 'acmpl:language|no_match',
"No supported languages matching {partial}" "No supported languages matching {partial}"
)).format(partial=partial), )).format(partial=partial)[:100],
value=partial value=partial
) )
] ]

View File

@@ -447,7 +447,7 @@ class Reminders(LionCog):
)) ))
value = 'None' value = 'None'
choices = [ choices = [
appcmds.Choice(name=name, value=value) appcmds.Choice(name=name[:100], value=value)
] ]
else: else:
# Build list of reminder strings # Build list of reminder strings
@@ -463,7 +463,7 @@ class Reminders(LionCog):
# Build list of valid choices # Build list of valid choices
choices = [ choices = [
appcmds.Choice( appcmds.Choice(
name=string[0], name=string[0][:100],
value=f"rid:{string[1].reminderid}" value=f"rid:{string[1].reminderid}"
) )
for string in matches for string in matches
@@ -474,7 +474,7 @@ class Reminders(LionCog):
name=t(_p( name=t(_p(
'cmd:reminders_cancel|acmpl:reminder|error:no_matches', 'cmd:reminders_cancel|acmpl:reminder|error:no_matches',
"You do not have any reminders matching \"{partial}\"" "You do not have any reminders matching \"{partial}\""
)).format(partial=partial), )).format(partial=partial)[:100],
value=partial value=partial
) )
] ]
@@ -562,7 +562,7 @@ class Reminders(LionCog):
name=t(_p( name=t(_p(
'cmd:remindme_at|acmpl:time|error:parse', 'cmd:remindme_at|acmpl:time|error:parse',
"Cannot parse \"{partial}\" as a time. Try the format HH:MM or YYYY-MM-DD HH:MM" "Cannot parse \"{partial}\" as a time. Try the format HH:MM or YYYY-MM-DD HH:MM"
)).format(partial=partial), )).format(partial=partial)[:100],
value=partial value=partial
) )
return [choice] return [choice]

View File

@@ -534,7 +534,7 @@ class RoleMenuCog(LionCog):
choice_name = menu.data.name choice_name = menu.data.name
choice_value = f"menuid:{menu.data.menuid}" choice_value = f"menuid:{menu.data.menuid}"
choices.append( choices.append(
appcmds.Choice(name=choice_name, value=choice_value) appcmds.Choice(name=choice_name[:100], value=choice_value)
) )
if not choices: if not choices:
@@ -545,7 +545,7 @@ class RoleMenuCog(LionCog):
)).format(partial=partial) )).format(partial=partial)
choice_value = partial choice_value = partial
choice = appcmds.Choice( choice = appcmds.Choice(
name=choice_name, value=choice_value name=choice_name[:100], value=choice_value
) )
choices.append(choice) choices.append(choice)
@@ -569,7 +569,7 @@ class RoleMenuCog(LionCog):
"Please select a menu first" "Please select a menu first"
)) ))
choice_value = partial choice_value = partial
choices = [appcmds.Choice(name=choice_name, value=choice_value)] choices = [appcmds.Choice(name=choice_name[:100], value=choice_value)]
else: else:
# Resolve the menu name # Resolve the menu name
menu: RoleMenu menu: RoleMenu
@@ -591,7 +591,7 @@ class RoleMenuCog(LionCog):
name=t(_p( name=t(_p(
'acmpl:menuroles|choice:invalid_menu|name', 'acmpl:menuroles|choice:invalid_menu|name',
"Menu '{name}' does not exist!" "Menu '{name}' does not exist!"
)).format(name=menu_name), )).format(name=menu_name)[:100],
value=partial value=partial
) )
choices = [choice] choices = [choice]
@@ -611,7 +611,7 @@ class RoleMenuCog(LionCog):
else: else:
name = mrole.data.label name = mrole.data.label
choice = appcmds.Choice( choice = appcmds.Choice(
name=name, name=name[:100],
value=f"<@&{mrole.data.roleid}>" value=f"<@&{mrole.data.roleid}>"
) )
choices.append(choice) choices.append(choice)
@@ -620,7 +620,7 @@ class RoleMenuCog(LionCog):
name=t(_p( name=t(_p(
'acmpl:menuroles|choice:no_matching|name', 'acmpl:menuroles|choice:no_matching|name',
"No roles in this menu matching '{partial}'" "No roles in this menu matching '{partial}'"
)).format(partial=partial), )).format(partial=partial)[:100],
value=partial value=partial
) )
return choices[:25] return choices[:25]

View File

@@ -904,10 +904,10 @@ class ScheduleCog(LionCog):
if not interaction.guild or not isinstance(interaction.user, discord.Member): if not interaction.guild or not isinstance(interaction.user, discord.Member):
choice = appcmds.Choice( choice = appcmds.Choice(
name=_p( name=t(_p(
'cmd:schedule|acmpl:book|error:not_in_guild', 'cmd:schedule|acmpl:book|error:not_in_guild',
"You need to be in a server to book sessions!" "You need to be in a server to book sessions!"
), ))[:100],
value='None' value='None'
) )
choices = [choice] choices = [choice]
@@ -917,10 +917,10 @@ class ScheduleCog(LionCog):
blacklist_role = (await self.settings.BlacklistRole.get(interaction.guild.id)).value blacklist_role = (await self.settings.BlacklistRole.get(interaction.guild.id)).value
if blacklist_role and blacklist_role in member.roles: if blacklist_role and blacklist_role in member.roles:
choice = appcmds.Choice( choice = appcmds.Choice(
name=_p( name=t(_p(
'cmd:schedule|acmpl:book|error:blacklisted', 'cmd:schedule|acmpl:book|error:blacklisted',
"Cannot Book -- Blacklisted" "Cannot Book -- Blacklisted"
), ))[:100],
value='None' value='None'
) )
choices = [choice] choices = [choice]
@@ -947,7 +947,7 @@ class ScheduleCog(LionCog):
) )
choices.append( choices.append(
appcmds.Choice( appcmds.Choice(
name=tzstring, value='None', name=tzstring[:100], value='None',
) )
) )
@@ -968,7 +968,7 @@ class ScheduleCog(LionCog):
if partial.lower() in name.lower(): if partial.lower() in name.lower():
choices.append( choices.append(
appcmds.Choice( appcmds.Choice(
name=name, name=name[:100],
value=str(slotid) value=str(slotid)
) )
) )
@@ -978,7 +978,7 @@ class ScheduleCog(LionCog):
name=t(_p( name=t(_p(
"cmd:schedule|acmpl:book|no_matching", "cmd:schedule|acmpl:book|no_matching",
"No bookable sessions matching '{partial}'" "No bookable sessions matching '{partial}'"
)).format(partial=partial[:25]), )).format(partial=partial[:25])[:100],
value=partial value=partial
) )
) )
@@ -998,10 +998,10 @@ class ScheduleCog(LionCog):
can_cancel = list(slotid for slotid in schedule if slotid > minid) can_cancel = list(slotid for slotid in schedule if slotid > minid)
if not can_cancel: if not can_cancel:
choice = appcmds.Choice( choice = appcmds.Choice(
name=_p( name=t(_p(
'cmd:schedule|acmpl:cancel|error:empty_schedule', 'cmd:schedule|acmpl:cancel|error:empty_schedule',
"You do not have any upcoming sessions to cancel!" "You do not have any upcoming sessions to cancel!"
), ))[:100],
value='None' value='None'
) )
choices.append(choice) choices.append(choice)
@@ -1025,7 +1025,7 @@ class ScheduleCog(LionCog):
if partial.lower() in name.lower(): if partial.lower() in name.lower():
choices.append( choices.append(
appcmds.Choice( appcmds.Choice(
name=name, name=name[:100],
value=str(slotid) value=str(slotid)
) )
) )
@@ -1034,7 +1034,7 @@ class ScheduleCog(LionCog):
name=t(_p( name=t(_p(
'cmd:schedule|acmpl:cancel|error:no_matching', 'cmd:schedule|acmpl:cancel|error:no_matching',
"No cancellable sessions matching '{partial}'" "No cancellable sessions matching '{partial}'"
)).format(partial=partial[:25]), )).format(partial=partial[:25])[:100],
value='None' value='None'
) )
choices.append(choice) choices.append(choice)

View File

@@ -1095,7 +1095,7 @@ class ColourShopping(ShopCog):
for i, item in enumerate(items, start=1) for i, item in enumerate(items, start=1)
] ]
options = [option for option in options if partial.lower() in option[1].lower()] options = [option for option in options if partial.lower() in option[1].lower()]
return [appcmds.Choice(name=option[1], value=option[0]) for option in options] return [appcmds.Choice(name=option[1][:100], value=option[0]) for option in options]
class ColourStore(Store): class ColourStore(Store):

View File

@@ -291,7 +291,7 @@ class TasklistCog(LionCog):
name=t(_p( name=t(_p(
'argtype:taskid|error:no_tasks', 'argtype:taskid|error:no_tasks',
"Tasklist empty! No matching tasks." "Tasklist empty! No matching tasks."
)), ))[:100],
value=partial value=partial
) )
] ]
@@ -319,7 +319,7 @@ class TasklistCog(LionCog):
if matching: if matching:
# If matches were found, assume user wants one of the matches # If matches were found, assume user wants one of the matches
options = [ options = [
appcmds.Choice(name=task_string, value=label) appcmds.Choice(name=task_string[:100], value=label)
for label, task_string in matching for label, task_string in matching
] ]
elif multi and partial.lower().strip() in ('-', 'all'): elif multi and partial.lower().strip() in ('-', 'all'):
@@ -328,7 +328,7 @@ class TasklistCog(LionCog):
name=t(_p( name=t(_p(
'argtype:taskid|match:all', 'argtype:taskid|match:all',
"All tasks" "All tasks"
)), ))[:100],
value='-' value='-'
) )
] ]
@@ -353,7 +353,7 @@ class TasklistCog(LionCog):
multi_name = f"{partial[:remaining-1]} {error}" multi_name = f"{partial[:remaining-1]} {error}"
multi_option = appcmds.Choice( multi_option = appcmds.Choice(
name=multi_name, name=multi_name[:100],
value=partial value=partial
) )
options = [multi_option] options = [multi_option]
@@ -371,7 +371,7 @@ class TasklistCog(LionCog):
if not matching: if not matching:
matching = [(label, task) for label, task in labels if last_split.lower() in task.lower()] matching = [(label, task) for label, task in labels if last_split.lower() in task.lower()]
options.extend( options.extend(
appcmds.Choice(name=task_string, value=label) appcmds.Choice(name=task_string[:100], value=label)
for label, task_string in matching for label, task_string in matching
) )
else: else:
@@ -380,7 +380,7 @@ class TasklistCog(LionCog):
name=t(_p( name=t(_p(
'argtype:taskid|error:no_matching', 'argtype:taskid|error:no_matching',
"No tasks matching '{partial}'!", "No tasks matching '{partial}'!",
)).format(partial=partial[:100]), )).format(partial=partial[:100])[:100],
value=partial value=partial
) )
] ]

View File

@@ -915,7 +915,7 @@ class TimezoneSetting(InteractiveSetting[ParentID, str, TZT]):
name=t(_p( name=t(_p(
'set_type:timezone|acmpl|no_matching', 'set_type:timezone|acmpl|no_matching',
"No timezones matching '{input}'!" "No timezones matching '{input}'!"
)).format(input=partial), )).format(input=partial)[:100],
value=partial value=partial
) )
] ]
@@ -930,7 +930,7 @@ class TimezoneSetting(InteractiveSetting[ParentID, str, TZT]):
"{tz} (Currently {now})" "{tz} (Currently {now})"
)).format(tz=tz, now=nowstr) )).format(tz=tz, now=nowstr)
choice = appcmds.Choice( choice = appcmds.Choice(
name=name, name=name[:100],
value=tz value=tz
) )
choices.append(choice) choices.append(choice)

View File

@@ -69,12 +69,12 @@ class DurationTransformer(Transformer):
name=t(_p( name=t(_p(
'util:Duration|acmpl|error', 'util:Duration|acmpl|error',
"Cannot extract duration from \"{partial}\"" "Cannot extract duration from \"{partial}\""
)).format(partial=partial), )).format(partial=partial)[:100],
value=partial value=partial
) )
else: else:
choice = appcmds.Choice( choice = appcmds.Choice(
name=strfdur(duration, short=False, show_days=True), name=strfdur(duration, short=False, show_days=True)[:100],
value=partial value=partial
) )
return [choice] return [choice]

View File

@@ -307,17 +307,17 @@ class Pager(BasePager):
"Current: Page {page}/{total}" "Current: Page {page}/{total}"
)).format(page=num+1, total=total) )).format(page=num+1, total=total)
choices = [ choices = [
appcmds.Choice(name=string, value=str(num+1)) appcmds.Choice(name=string[:100], value=str(num+1))
for num, string in sorted(page_choices.items(), key=lambda t: t[0]) for num, string in sorted(page_choices.items(), key=lambda t: t[0])
] ]
else: else:
# Particularly support page names here # Particularly support page names here
choices = [ choices = [
appcmds.Choice( appcmds.Choice(
name='> ' * (i == num) + t(_p( name=('> ' * (i == num) + t(_p(
'cmd:page|acmpl|pager:Pager|choice:general', 'cmd:page|acmpl|pager:Pager|choice:general',
"Page {page}" "Page {page}"
)).format(page=i+1), )).format(page=i+1))[:100],
value=str(i+1) value=str(i+1)
) )
for i in range(0, total) for i in range(0, total)
@@ -351,7 +351,7 @@ class Pager(BasePager):
name=t(_p( name=t(_p(
'cmd:page|acmpl|pager:Page|choice:select', 'cmd:page|acmpl|pager:Page|choice:select',
"Selected: Page {page}/{total}" "Selected: Page {page}/{total}"
)).format(page=page_num+1, total=total), )).format(page=page_num+1, total=total)[:100],
value=str(page_num + 1) value=str(page_num + 1)
) )
return [choice, *choices] return [choice, *choices]
@@ -361,7 +361,7 @@ class Pager(BasePager):
name=t(_p( name=t(_p(
'cmd:page|acmpl|pager:Page|error:parse', 'cmd:page|acmpl|pager:Page|error:parse',
"No matching pages!" "No matching pages!"
)).format(page=page_num, total=total), )).format(page=page_num, total=total)[:100],
value=partial value=partial
) )
] ]