def from_dict(cls, dct): e = cls() e.color = dct.get('color') e.title = dct.get('title') e.description = dct.get('description') e.url = dct.get('url') if dct.get('author'): auth = dct['author'] author = MessageEmbedAuthor() author.name = auth.get('name') author.url = auth.get('url') author.icon_url = auth.get('icon_url') e.author = author if dct.get('thumbnail'): thumb = dct['thumbnail'] thumbnail = MessageEmbedThumbnail() thumbnail.url = thumb.get('url') thumbnail.proxy_url = thumb.get('proxy_url') thumbnail.width = thumb.get('width') thumbnail.height = thumb.get('height') e.thumbnail = thumbnail if dct.get('image'): img = dct['image'] image = MessageEmbedImage() image.url = img.get('url') image.proxy_url = img.get('proxy_url') e.image = image if dct.get('footer'): foot = dct['footer'] footer = MessageEmbedFooter() footer.text = foot.get('text') e.footer = footer else: footer = MessageEmbedFooter() footer.text = 'Mee6' e.footer = footer for f in dct.get('fields', ()): field = MessageEmbedField() field.name = f.get('name') field.value = f.get('value') field.inline = f.get('inline') e.fields.append(field) return e
def raid_alert(self, d): img = '' embed = MessageEmbed(color=d['color']) embed.author = MessageEmbedAuthor( name=(d['mon_name']), url=d['gmapurl']) if not args.bottommap: if d['map_enabled']: img = ['static.png', open(d['static'], 'r')] embed.thumbnail = MessageEmbedThumbnail(url=d['thumb'].lower()) embed.fields.append( MessageEmbedField(name=args.rmtitle.format(d['mon_name']), value=args.rmintro.format(d['time'], d['tth'])) ) if d['geo_enabled']: embed.fields.append( MessageEmbedField(name=args.rltitle, value=args.rlfield.format(d['address'])) ) embed.image = MessageEmbedImage(url=d['img'], width=50, height=50) if d['moves_enabled']: embed.fields.append( MessageEmbedField( name=args.rmvtitle, value=args.rmvfield.format( d['move1'], d['move2']))) if d['iv_enabled']: embed.fields.append( MessageEmbedField(name=args.rivtitle.format(d['gym_name']), value=args.rivfield.format(d['description'])) ) if args.weatheruser and 'wtemp' in d: embed.fields.append( MessageEmbedField( name=args.weathertitle.format( d['wdescription']), value=args.weatherbody.format( d['wtemp'], d['wwind']))) self.channels_messages_create( d['channel'], attachment=img, embed=embed) if args.bottommap and d['map_enabled']: img = ['static.png', open(d['static'], 'r')] self.channels_messages_create(d['channel'], attachment=list(img))
def embed(self): e = MessageEmbed() e.color = self.color e.title = self.stream_title e.url = self.stream_url author = MessageEmbedAuthor() author.name = self.display_name author.url = self.stream_url author.icon_url = self.avatar e.author = author thumbnail = MessageEmbedThumbnail() thumbnail.url = self.avatar thumbnail.proxy_url = self.avatar thumbnail.width, thumbnail.height = 100, 100 e.thumbnail = thumbnail image = MessageEmbedImage() image.url = self.stream_preview + '?rand={}'.format(randint(0, 999999)) e.image = image footer = MessageEmbedFooter() footer.text = self.platform_name e.footer = footer if self.stream_game: game_field = MessageEmbedField() game_field.name = 'Played Game' game_field.value = self.stream_game game_field.inline = True e.fields.append(game_field) if self.stream_viewers_count or self.stream_viewers_count == 0: viewers_field = MessageEmbedField() viewers_field.name = 'Viewers' viewers_field.value = str(self.stream_viewers_count) viewers_field.inline = True e.fields.append(viewers_field) return e
def render_attendance(self, roster): totals = [(reaction, self._count_if(roster.values(), lambda x: x["reaction"] == reaction)) for reaction in ReactionEnum] return MessageEmbedField( name="Attendance", value=Diff("\n".join("{} {}: {}".format(reaction_to_icon[reaction], reaction.value, total) for (reaction, total) in totals)), inline=True)
def render_role(self, roster, role): role_roster = list(filter(lambda x: x["role"] == role, roster.values())) if len(role_roster) == 0: return role_roster = sorted(role_roster, key=lambda x: (x["reaction"], x["name"])) return MessageEmbedField(name=Bold(role_to_plural[role]), value=Diff("\n".join( self.render_raider(raider) for raider in role_roster)), inline=True)
def render_buffs(roster): buffs = {buff: ReactionEnum.declined for buff in BuffEnum} for raider in roster.values(): if raider["class"] in class_buffs: cur_reaction = buffs[class_buffs[raider["class"]]] buffs[class_buffs[raider["class"]]] = min( cur_reaction, raider["reaction"]) return MessageEmbedField( name="Raid Buffs", value=Diff("\n".join( "{} {}".format(reaction_to_icon[reaction], buff.value) for buff, reaction in sorted( buffs.items(), key=lambda i: (i[1], i[0].value)))), inline=True)
def msgstats(self, event, user): # Query for the basic aggregate message statistics message_stats = Message.select( fn.Count('*'), fn.Sum(fn.char_length(Message.content)), fn.Sum(fn.array_length(Message.emojis, 1)), fn.Sum(fn.array_length(Message.mentions, 1)), fn.Sum(fn.array_length(Message.attachments, 1)), ).where( (Message.author_id == user.id) ).tuples().async() reactions_given = Reaction.select( fn.Count('*'), Reaction.emoji_id, Reaction.emoji_name, ).join( Message, on=(Message.id == Reaction.message_id) ).where( (Reaction.user_id == user.id) ).group_by( Reaction.emoji_id, Reaction.emoji_name ).order_by(fn.Count('*').desc()).tuples().async() # Query for most used emoji emojis = Message.raw(''' SELECT gm.emoji_id, gm.name, count(*) FROM ( SELECT unnest(emojis) as id FROM messages WHERE author_id=%s ) q JOIN guild_emojis gm ON gm.emoji_id=q.id GROUP BY 1, 2 ORDER BY 3 DESC LIMIT 1 ''', (user.id, )).tuples().async() deleted = Message.select( fn.Count('*') ).where( (Message.author_id == user.id) & (Message.deleted == 1) ).tuples().async() wait_many(message_stats, reactions_given, emojis, deleted, timeout=10) # If we hit an exception executing the core query, throw an exception if message_stats.exception: message_stats.get() q = message_stats.value[0] embed = MessageEmbed() embed.fields.append( MessageEmbedField(name='Total Messages Sent', value=q[0] or '0', inline=True)) embed.fields.append( MessageEmbedField(name='Total Characters Sent', value=q[1] or '0', inline=True)) if deleted.value: embed.fields.append( MessageEmbedField(name='Total Deleted Messages', value=deleted.value[0][0], inline=True)) embed.fields.append( MessageEmbedField(name='Total Custom Emojis', value=q[2] or '0', inline=True)) embed.fields.append( MessageEmbedField(name='Total Mentions', value=q[3] or '0', inline=True)) embed.fields.append( MessageEmbedField(name='Total Attachments', value=q[4] or '0', inline=True)) if reactions_given.value: reactions_given = reactions_given.value embed.fields.append( MessageEmbedField(name='Total Reactions', value=sum(i[0] for i in reactions_given), inline=True)) emoji = ( reactions_given[0][2] if not reactions_given[0][1] else '<:{}:{}>'.format(reactions_given[0][2], reactions_given[0][1]) ) embed.fields.append( MessageEmbedField(name='Most Used Reaction', value=u'{} (used {} times)'.format( emoji, reactions_given[0][0], ), inline=True)) if emojis.value: emojis = list(emojis.value) if emojis: embed.add_field( name='Most Used Emoji', value=u'<:{1}:{0}> (`{1}`, used {2} times)'.format(*emojis[0])) embed.thumbnail = MessageEmbedThumbnail(url=user.avatar_url) embed.color = get_dominant_colors_user(user) event.msg.reply('', embed=embed)
def monster_alert(self, d): embed = MessageEmbed(color=d['color']) img = '' if 'form' in d: embed.author = MessageEmbedAuthor( name=( d['mon_name'] + ' (form: {})'.format( d['form'])), url=d['gmapurl']) else: embed.author = MessageEmbedAuthor( name=d['mon_name'], url=d['gmapurl']) if not args.bottommap: if d['map_enabled']: img = ['static.png', open(d['static'], 'r')] embed.thumbnail = MessageEmbedThumbnail(url=d['thumb'].lower()) embed.fields.append( MessageEmbedField(name=args.pmtitle.format(d['mon_name']), value=args.pmintro.format(d['time'], d['tth'])) ) if d['geo_enabled']: embed.fields.append( MessageEmbedField(name=args.pltitle, value=args.plfield.format(d['address'])) ) if 'atk' in d and d['iv_enabled']: embed.fields.append( MessageEmbedField( name=args.pivtitle, value=args.pivfield.format( d['perfection'], d['atk'], d['def'], d['sta'], d['level'], d['cp']))) if 'atk' in d and d['moves_enabled']: embed.fields.append( MessageEmbedField( name=args.pmvtitle, value=args.pmvfield.format( d['move1'], d['move2']))) if args.weatheruser and 'wtemp' in d: embed.fields.append( MessageEmbedField( name=args.weathertitle.format( d['wdescription']), value=args.weatherbody.format( d['wtemp'], d['wwind']))) if args.mapurl: embed.fields.append( MessageEmbedField(name=args.RMtitle, value=args.RMlink.format(d['mapurl'])) ) self.channels_messages_create( d['channel'], attachment=img, embed=embed) if args.bottommap and d['map_enabled']: img = ['static.png', open(d['static'], 'r')] self.channels_messages_create(d['channel'], attachment=list(img))
def server(self, event, guild_id=None): guild: Guild = self.state.guilds.get( guild_id) if guild_id else event.guild if not guild: raise CommandFail('Invalid server') embed = MessageEmbed() embed.set_author( MessageEmbedAuthor(name=guild.name, icon_url=guild.icon_url())) # General Abouts about_field = MessageEmbedField() about_field.name = '**\u276F About**' about_text = 'Created by {} ({}) — <t:{}:R>'.format( guild.owner, guild.owner.id, int(to_datetime(guild.id).replace(tzinfo=pytz.UTC).timestamp())) about_text += '\nMembers: {:,}/{:,}'.format( guild.approximate_presence_count, guild.member_count) about_text += '\nRegion: {}'.format(guild.region) about_field.value = about_text embed.add_field(about_field) # General Counts counts_field = MessageEmbedField() counts_field.name = '\n**\u276F Counts**' text_count = sum(1 for c in list(guild.channels.values()) if not c.is_voice and not c.is_thread) voice_count = len(guild.channels) - text_count counts_field.value = 'Roles: {:,}\nText: {:,}\nVoice: {:,}'.format( len(guild.roles), text_count, voice_count) embed.add_field(counts_field) # Security security_field = MessageEmbedField() security_field.name = '\n**\u276F Security**' security_field.value = 'Verification: {}\nExplicit Content: {}'.format( guild.verification_level, guild.explicit_content_filter) embed.add_field(security_field) # Features features_field = MessageEmbedField() features_field.name = '\n**\u276F Features**' features_field.value = 'Features: {}'.format(', '.join(guild.features)) embed.add_field(features_field) if guild.icon: embed.color = get_dominant_colors_guild(guild) event.msg.reply('', embed=embed)