Adding system shortlist (#69)
* Update embeds.py Adding short list embed * Update system_commands.py Adding short list and full list
This commit is contained in:
parent
94dcb91bd3
commit
2efaca706f
@ -363,16 +363,17 @@ async def system_frontpercent(ctx: CommandContext, system: System):
|
||||
|
||||
async def system_list(ctx: CommandContext, system: System):
|
||||
all_members = sorted(await system.get_members(ctx.conn), key=lambda m: m.name.lower())
|
||||
if ctx.match("full"):
|
||||
page_size = 8
|
||||
if len(all_members) <= page_size:
|
||||
# If we have less than 8 members, don't bother paginating
|
||||
await ctx.reply(embed=embeds.member_list(system, all_members, 0, page_size))
|
||||
await ctx.reply(embed=embeds.member_list_full(system, all_members, 0, page_size))
|
||||
else:
|
||||
current_page = 0
|
||||
msg: discord.Message = None
|
||||
while True:
|
||||
page_count = math.ceil(len(all_members) / page_size)
|
||||
embed = embeds.member_list(system, all_members, current_page, page_size)
|
||||
embed = embeds.member_list_full(system, all_members, current_page, page_size)
|
||||
|
||||
# Add reactions for moving back and forth
|
||||
if not msg:
|
||||
@ -400,3 +401,41 @@ async def system_list(ctx: CommandContext, system: System):
|
||||
if ctx.message.guild:
|
||||
if ctx.message.channel.permissions_for(ctx.message.guild.get_member(ctx.client.user.id)).manage_messages:
|
||||
await reaction.remove(ctx.message.author)
|
||||
else:
|
||||
|
||||
#Basically same code as above
|
||||
#A dozen members at a time seems handy
|
||||
page_size = 12
|
||||
if len(all_members) <= page_size:
|
||||
# If we have less than 12 members, don't bother paginating
|
||||
await ctx.reply(embed=embeds.member_list_short(system, all_members, 0, page_size))
|
||||
else:
|
||||
current_page = 0
|
||||
msg: discord.Message = None
|
||||
while True:
|
||||
page_count = math.ceil(len(all_members) / page_size)
|
||||
embed = embeds.member_list_short(system, all_members, current_page, page_size)
|
||||
|
||||
if not msg:
|
||||
msg = await ctx.reply(embed=embed)
|
||||
await msg.add_reaction("\u2B05")
|
||||
await msg.add_reaction("\u27A1")
|
||||
else:
|
||||
await msg.edit(embed=embed)
|
||||
|
||||
def check(reaction, user):
|
||||
return user.id == ctx.message.author.id and reaction.emoji in ["\u2B05", "\u27A1"]
|
||||
|
||||
try:
|
||||
reaction, _ = await ctx.client.wait_for("reaction_add", timeout=5*60, check=check)
|
||||
except asyncio.TimeoutError:
|
||||
return
|
||||
|
||||
if reaction.emoji == "\u2B05":
|
||||
current_page = (current_page - 1) % page_count
|
||||
elif reaction.emoji == "\u27A1":
|
||||
current_page = (current_page + 1) % page_count
|
||||
|
||||
if ctx.message.guild:
|
||||
if ctx.message.channel.permissions_for(ctx.message.guild.get_member(ctx.client.user.id)).manage_messages:
|
||||
await reaction.remove(ctx.message.author)
|
||||
|
@ -224,7 +224,28 @@ def help_footer_embed() -> discord.Embed:
|
||||
embed.set_footer(text="By @Ske#6201 | GitHub: https://github.com/xSke/PluralKit/")
|
||||
return embed
|
||||
|
||||
def member_list(system: System, all_members: List[Member], current_page: int, page_size: int):
|
||||
def member_list_short(system: System, all_members: List[Member], current_page: int, page_size: int):
|
||||
page_count = int(math.ceil(len(all_members) / page_size))
|
||||
|
||||
title = ""
|
||||
if len(all_members) > page_size:
|
||||
title += "[{}/{}] ".format(current_page + 1, page_count)
|
||||
|
||||
if system.name:
|
||||
title += "Members of {} (`{}`)".format(system.name, system.hid)
|
||||
else:
|
||||
title += "Members of `{}`".format(system.hid)
|
||||
|
||||
embed = discord.Embed()
|
||||
embed.title = title
|
||||
for member in all_members[current_page*page_size:current_page*page_size+page_size]:
|
||||
member_description = "**ID**: {}\n".format(member.hid)
|
||||
|
||||
#Removed truncating since it's just the ID
|
||||
embed.add_field(name=member.name, value=member_description, inline=False)
|
||||
return embed
|
||||
|
||||
def member_list_full(system: System, all_members: List[Member], current_page: int, page_size: int):
|
||||
page_count = int(math.ceil(len(all_members) / page_size))
|
||||
|
||||
title = ""
|
||||
|
Loading…
Reference in New Issue
Block a user