Commit 3ec0f548 authored by Geovanny's avatar Geovanny

Fixed participation url and new display for participation

parent 52c6cc60
...@@ -32,51 +32,76 @@ class WarManager(commands.Cog): ...@@ -32,51 +32,76 @@ class WarManager(commands.Cog):
except ApiError as error: except ApiError as error:
await ctx.send(error.message) await ctx.send(error.message)
@commands.command(aliases=["si"]) @commands.command(aliases=["si","SI", "yes"])
async def warYes(self, ctx): async def warYes(self, ctx):
"""Yes confirmation to current war""" """Yes confirmation to current war"""
await self.warParticipation(ctx, "Yes") await self.warParticipation(ctx, "Yes")
@commands.command(aliases=["no"]) @commands.command(aliases=["no", "NO"])
async def warNo(self, ctx): async def warNo(self, ctx):
"""No confirmation to current war""" """No confirmation to current war"""
await self.warParticipation(ctx, "No") await self.warParticipation(ctx, "No")
@commands.command(aliases=["idk"]) @commands.command(aliases=["idk", "IDK"])
async def warIdk(self, ctx): async def warIdk(self, ctx):
"""Maybe confirmation to current war""" """Maybe confirmation to current war"""
await self.warParticipation(ctx, "Maybe") await self.warParticipation(ctx, "Maybe")
@commands.command() @commands.command(aliases=["guerra"])
async def houseParticipation(self, ctx): async def houseParticipation(self, ctx):
try: try:
session = await self.bot.getUserSession(ctx.message.author) session = await self.bot.getUserSession(ctx.message.author)
data = await Api.getSession('/house/participation', session) data = await Api.getSession('/house/war/participation', session)
date = parser.parse(data['war'].get('day')) date = parser.parse(data['war'].get('day'))
await ctx.send('Participation for War: {0}/{1}/{2}'.format(date.year, date.month, date.day)) await ctx.send('Participation for War: {0}/{1}/{2}'.format(date.year, date.month, date.day))
await EmbedStyle.createPages(self.bot, ctx, data.get('participation'), 10, self.craftParticipationPage) members = data.get('participation')
yes_list = list(filter(lambda x: x.get('decision')=='Yes', members))
no_list = list(filter(lambda x: x.get('decision')=='No', members))
idk_list = list(filter(lambda x: x.get('decision')=='Maybe', members))
yes_embed = self.craftColumns(yes_list, 3, 'Yes')
no_embed = self.craftColumns(no_list, 3, 'No')
idk_embed = self.craftColumns(idk_list, 3, 'Maybe')
await ctx.send(embed=yes_embed)
await ctx.send(embed=no_embed)
await ctx.send(embed=idk_embed)
except ApiError as error: except ApiError as error:
await ctx.send(error.message) await ctx.send(error.message)
def craftParticipationPage(self, data, minI, maxI): def craftColumns(self, data, numOfColumns, title):
embed = discord.Embed(color=0x19212d) embed = discord.Embed()
embed.set_author(name='Conquy') embed.set_author(name=title)
if(len(data) == 0):
embed.add_field(name='Members', value='None')
return embed
lens = len(data)//numOfColumns
rem = len(data)%numOfColumns
if rem!=0:
lens += 1
table = [] table = []
for i in range(minI, maxI):
if i < len(data):
part = data[i]
item = part.values()
table.append(item)
headers = ["Name", "Decision"] for i in range(lens):
temp = []
for j in range(numOfColumns):
index = (numOfColumns*i) + j
if index < len(data):
temp.append(data[index].get('username'))
else:
# Add empty cell for zipping purposes
temp.append(' ')
table.append(temp)
headers = ['a', 'b', 'c']
max_lens = [len(str(max(i, key=lambda x: len(str(x))))) for i in zip(headers, *table)] max_lens = [len(str(max(i, key=lambda x: len(str(x))))) for i in zip(headers, *table)]
participation_str = '```'; out_str = '```'
for row in (headers, *table): for row in table:
participation_str += (' | '.join('{0:{width}}'.format(x, width=y) for x, y in zip(row, max_lens))) + '\n' out_str += (' | '.join('{0:{width}}'.format(x, width=y) for x, y in zip(row, max_lens))) + '\n'
participation_str +='```' out_str += '```'
embed.add_field(name='Participation', value=participation_str) embed.add_field(name="Members", value=out_str)
return embed return embed
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment