def songembed(song, queued: bool = False): e = Embed(title = song.title if not queued else f'Queued - {song.title}', url=song.url) e.set_image(url=song.thumbnail) e.description=f"- {song.channel} : {song.channel_url}" e.timestamp=discord.utils.utcnow() e.set_footer(text=f'Views: {song.views} | Duration: {round(song.duration/60)} minutes',icon_url=song.thumbnail) return e
async def tally(self, ctx, poll_id: commands.MessageConverter): """Get polls results""" error_message = ErrorEmbed( description=f"**{poll_id.id}** is not a poll!") if len(poll_id.embeds) <= 0: await ctx.send(embed=error_message) return embed = poll_id.embeds[0] if poll_id.author == ctx.message.author: await ctx.send(embed=error_message) return if isinstance(embed.footer.text, discord.embeds._EmptyEmbed): await ctx.send(embed=error_message) return if not embed.footer.text.startswith('Poll'): await ctx.send(embed=error_message) return if len(poll_id.reactions) < 2: await ctx.send(embed=error_message) return valid_reactions = list( filter( lambda x: x in list( map(lambda x: str(discord.PartialEmoji(name=x.emoji)), poll_id.reactions)), list( map(lambda x: str(discord.PartialEmoji(name=x.emoji)), poll_id.reactions)))) if len(list(valid_reactions)) < 2: await ctx.send(embed=error_message) return valid_reactions_list = list( map( lambda x: (x, discord.utils.find(lambda z: str(z.emoji) == str( x), poll_id.reactions).count), valid_reactions)) valid_reactions_list.sort(reverse=True) valid_reactions_list = [('Option', 'Reacted Counts') ] + valid_reactions_list embed = Embed(title='Poll Results') lengths = [[len(str(x)) for x in row] for row in valid_reactions_list] max_lengths = [ max(map(itemgetter(x), lengths)) for x in range(0, len(valid_reactions_list[0])) ] format_str = ''.join(map(lambda x: '%%-%ss | ' % x, max_lengths)) embed.description = '```markdown\n' + ( format_str % valid_reactions_list[0] ) + '\n' + '-' * (sum(max_lengths) + len(max_lengths) * 3 - 1) for x in valid_reactions_list[1:]: embed.description += f'\n{format_str % x}' embed.description += '\n```' embed.timestamp = poll_id.created_at await ctx.send(embed=embed, reference=poll_id)