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 create_embed(event_name: str, event_link: str, user: User, *args, **kwargs): embed = MessageEmbed() embed.title = event_name embed.url = event_link embed.thumbnail = MessageEmbedThumbnail(url=user.avatar_url) args_desc = "\n\n".join(args) kwargs_desc = "\n\n".join("**{0}:\n{1}**".format(name, value) for name, value in kwargs.items()) embed.description = "\n\n".join((args_desc, kwargs_desc)) embed.color = 0x00FFFF return embed
def on_message(self, event): if event.member.user.bot: return m = re.search( r"https{0,1}:\/\/e[x-]hentai.org\/g\/([A-z0-9]+)\/([A-z0-9]+)\/", event.message.content) if m and len(m.groups()) == 2: r = self.session.post(api_ex, json={ "method": "gdata", "gidlist": [[m.group(1), m.group(2)]], "namespace": 1 }) j = r.json() embed = MessageEmbed() embed.color = cfg.color embed.title = j["gmetadata"][0]["title"] embed.add_field(name='Tags', value=" ".join(j["gmetadata"][0]["tags"]), inline=True) embed.add_field( name='Links', value= ("[e-hentai](https://e-hentai.org/g/{0}/{1}/) [exhentai](https://exhentai.org/g/{0}/{1}/)" ).format(m.group(1), m.group(2)), inline=True) embed.add_field( name='test', value="yes" if j["gmetadata"][0]["expunged"] else "no", inline=True) imgdata = self.session.get(j["gmetadata"][0]["thumb"].replace( "\\", "")) resp = requests.post( "https://f.okea.moe/api/upload", files={'file': ('1.jpg', BytesIO(imgdata.content))}) resp_json = resp.json() if resp.ok and resp_json and resp_json[ "success"] == True and resp_json["url"] != None: embed.thumbnail = MessageEmbedThumbnail() embed.thumbnail.url = resp_json["url"] event.reply("", embed=embed)
def raid_alert(self, d): legend = json.loads(open('config/raid.json').read()) rmtitle = re.sub('<MON>', d['mon_name'], legend['raid']) rlfield = legend['time'] adreu = d.get('street', '') + d.get('street_num', '') adrus = d.get('street_num', '') + d.get('street', '') address = legend.get('address', '') gyminfo = legend['gyminfo'] moves = legend['moves'] boost = legend['weather'] rmlinkfield = legend.get('RM', '') description = rlfield if d['geo_enabled']: description += address if d['iv_enabled']: description += gyminfo if d['moves_enabled']: description += moves if 'boost' in d and d['weather_enabled']: description += boost if args.mapurl: description += rmlinkfield description = re.sub('<DESPAWN>', d.get('time', ''), description) description = re.sub('<TTH>', d.get('tth', ''), description) description = re.sub('<CITY>', d.get('city', ''), description) description = re.sub('<SUB>', d.get('suburb', ''), description) description = re.sub('<STR>', d.get('street', ''), description) description = re.sub('<STR_NUM>', d.get('street_num', ''), description) description = re.sub('<ADDR_EU>', adreu, description) description = re.sub('<ADDR_US>', adrus, description) description = re.sub('<GYM>', d.get('gym_name', ''), description) description = re.sub('<INFO>', d.get('description', ''), description) description = re.sub('<MOVE1>', d.get('move1', ''), description) description = re.sub('<MOVE2>', d.get('move2', ''), description) description = re.sub('<WEA>', d.get('boost', ''), description) description = re.sub('<RM>', d.get('mapurl', ''), description) embed = MessageEmbed(color=d['color'], description=description) embed.url = (d['gmapurl']) embed.thumbnail = MessageEmbedThumbnail(url=d['img']) embed.author = MessageEmbedAuthor(icon_url=d['thumb'].lower(), name=rmtitle) embed.title = '{}'.format(d['mon_name']) embed.url = d['gmapurl'] if d['map_enabled']: embed.image = MessageEmbedImage(url=d['static']) self.channels_messages_create(d['channel'], embed=embed)
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 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 on_message(self, event): if not event.member.user.bot: m = re.search( r"https*:\/\/w*\.*amiami\.[a-zA-Z]+\/[a-zA-Z\/]+\?gcode=([^\&]+)", event.message.content) if m: results = amiami.search(m.group(1)) if len(results.items) > 0: item = results.items[0] embed = MessageEmbed() embed.color = cfg.color embed.title = item.productName embed.url = item.productURL embed.set_footer(text=f"{item.price:,} JPY") embed.thumbnail = MessageEmbedThumbnail() embed.thumbnail.url = item.imageURL event.reply("", embed=embed)
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 monster_alert(self, d): legend = json.loads(open('config/monsters.json').read()) if 'form' in d: pmtitle = re.sub('<MON>', d['mon_name'] + '({})'.format(d['form']), legend['mon']) else: pmtitle = re.sub('<MON>', d['mon_name'], legend['mon']) pmintro = legend['time'] description = pmintro adreu = d.get('street', '') + d.get('street_num', '') adrus = d.get('street_num', '') + d.get('street', '') address = legend.get('address', '') stats = legend.get('iv', '') moves = legend.get('moves', '') boost = legend.get('weather', '') rmlinkfield = legend.get('RM', '') if d['geo_enabled']: description += address if 'atk' in d and d['iv_enabled']: description += stats if 'atk' in d and d['moves_enabled']: description += moves if 'boost' in d and d['weather_enabled']: description += boost if args.mapurl: description += rmlinkfield description = re.sub('<DESPAWN>', d.get('time', ''), description) description = re.sub('<TTH>', d.get('tth', ''), description) description = re.sub('<CITY>', d.get('city', ''), description) description = re.sub('<SUB>', d.get('suburb', ''), description) description = re.sub('<STR>', d.get('street', ''), description) description = re.sub('<STR_NUM>', d.get('street_num', ''), description) description = re.sub('<ADDR_EU>', adreu, description) description = re.sub('<ADDR_US>', adrus, description) description = re.sub('<IV>', str(d.get('perfection', '')), description) description = re.sub('<ATK>', str(d.get('atk', '')), description) description = re.sub('<DEF>', str(d.get('def', '')), description) description = re.sub('<STA>', str(d.get('sta', '')), description) description = re.sub('<LVL>', str(d.get('level', '')), description) description = re.sub('<CP>', str(d.get('cp', '')), description) description = re.sub('<MOVE1>', d.get('move1', ''), description) description = re.sub('<MOVE2>', d.get('move2', ''), description) description = re.sub('<WEA>', d.get('description', ''), description) description = re.sub('<RM>', d.get('mapurl', ''), description) embed = MessageEmbed(color=d['color'], description=description) if d['map_enabled']: embed.image = MessageEmbedImage(url=d['static']) embed.author = MessageEmbedAuthor(url=d['gmapurl'], name=pmtitle) embed.title = '{}'.format(d['mon_name']) embed.url = d['gmapurl'] embed.thumbnail = MessageEmbedThumbnail(url=d['thumb'].lower()) self.channels_messages_create(d['channel'], embed=embed)