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,40 +363,79 @@ async def system_frontpercent(ctx: CommandContext, system: System):
|
|||||||
|
|
||||||
async def system_list(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())
|
all_members = sorted(await system.get_members(ctx.conn), key=lambda m: m.name.lower())
|
||||||
page_size = 8
|
if ctx.match("full"):
|
||||||
if len(all_members) <= page_size:
|
page_size = 8
|
||||||
# If we have less than 8 members, don't bother paginating
|
if len(all_members) <= page_size:
|
||||||
await ctx.reply(embed=embeds.member_list(system, all_members, 0, page_size))
|
# If we have less than 8 members, don't bother paginating
|
||||||
|
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_full(system, all_members, current_page, page_size)
|
||||||
|
|
||||||
|
# Add reactions for moving back and forth
|
||||||
|
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 we can, remove the original reaction from the member
|
||||||
|
# Don't bother checking permission if we're in DMs (wouldn't work anyway)
|
||||||
|
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:
|
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)
|
|
||||||
|
|
||||||
# Add reactions for moving back and forth
|
#Basically same code as above
|
||||||
if not msg:
|
#A dozen members at a time seems handy
|
||||||
msg = await ctx.reply(embed=embed)
|
page_size = 12
|
||||||
await msg.add_reaction("\u2B05")
|
if len(all_members) <= page_size:
|
||||||
await msg.add_reaction("\u27A1")
|
# If we have less than 12 members, don't bother paginating
|
||||||
else:
|
await ctx.reply(embed=embeds.member_list_short(system, all_members, 0, page_size))
|
||||||
await msg.edit(embed=embed)
|
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)
|
||||||
|
|
||||||
def check(reaction, user):
|
if not msg:
|
||||||
return user.id == ctx.message.author.id and reaction.emoji in ["\u2B05", "\u27A1"]
|
msg = await ctx.reply(embed=embed)
|
||||||
|
await msg.add_reaction("\u2B05")
|
||||||
|
await msg.add_reaction("\u27A1")
|
||||||
|
else:
|
||||||
|
await msg.edit(embed=embed)
|
||||||
|
|
||||||
try:
|
def check(reaction, user):
|
||||||
reaction, _ = await ctx.client.wait_for("reaction_add", timeout=5*60, check=check)
|
return user.id == ctx.message.author.id and reaction.emoji in ["\u2B05", "\u27A1"]
|
||||||
except asyncio.TimeoutError:
|
|
||||||
return
|
|
||||||
|
|
||||||
if reaction.emoji == "\u2B05":
|
try:
|
||||||
current_page = (current_page - 1) % page_count
|
reaction, _ = await ctx.client.wait_for("reaction_add", timeout=5*60, check=check)
|
||||||
elif reaction.emoji == "\u27A1":
|
except asyncio.TimeoutError:
|
||||||
current_page = (current_page + 1) % page_count
|
return
|
||||||
|
|
||||||
# If we can, remove the original reaction from the member
|
if reaction.emoji == "\u2B05":
|
||||||
# Don't bother checking permission if we're in DMs (wouldn't work anyway)
|
current_page = (current_page - 1) % page_count
|
||||||
if ctx.message.guild:
|
elif reaction.emoji == "\u27A1":
|
||||||
if ctx.message.channel.permissions_for(ctx.message.guild.get_member(ctx.client.user.id)).manage_messages:
|
current_page = (current_page + 1) % page_count
|
||||||
await reaction.remove(ctx.message.author)
|
|
||||||
|
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/")
|
embed.set_footer(text="By @Ske#6201 | GitHub: https://github.com/xSke/PluralKit/")
|
||||||
return embed
|
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))
|
page_count = int(math.ceil(len(all_members) / page_size))
|
||||||
|
|
||||||
title = ""
|
title = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user