def on_gelbooru(self, event, tags): r = requests.get("https://gelbooru.com/index.php", params={ "page": "dapi", "s": "post", "q": "index", "tags": tags, "limit": 200, "json": 1 }) if len(r.content) > 0 and len(r.json()) > 0: n = random.randint(0, len(r.json()) - 1) embed = MessageEmbed() embed.color = cfg.color embed.title = tags embed.url = "https://gelbooru.com/index.php?page=post&s=view&id={}".format( r.json()[n]["id"]) embed.set_image(url=r.json()[n]["file_url"]) event.msg.reply("", embed=embed) else: event.msg.reply("nothing found")
def on_generate(self, event, query): res = self.wolfram.query(query) if res.success.lower() == "true": results = list(res.results) pods = list(res.pods) if results: answer = results[0] if answer.title == "Distribution of total" and "@scanner" in answer and answer.scanner == "Dice": for pod in pods: if pod.title == "Example": answer = pod break elif len(pods) > 1: answer = pods[1] else: event.msg.reply("no results") return if "@scanner" in answer and answer.scanner == "Dice": embed = MessageEmbed() embed.color = cfg.color embed.description = answer.text embed.set_image(url=answer["subpod"]["img"]["@src"]) event.msg.reply("", embed=embed) elif answer.text: event.msg.reply(answer.text) else: embed = MessageEmbed() embed.color = cfg.color embed.set_image(url=answer["subpod"]["img"]["@src"]) event.msg.reply("", embed=embed) else: event.msg.reply("no results")
def on_dab(self, event): r = requests.get("https://danbooru.donmai.us/posts.json", params={ "tags": "dab_(dance) rating:safe", "limit": 200, "random": "false" }) if len(r.content) > 0 and len(r.json()) > 0: if "success" in r.json() and not r.json()["success"]: event.message.reply(r.json()["message"]) return n = random.randint(0, len(r.json()) - 1) embed = MessageEmbed() embed.color = cfg.color if "large_file_url" in r.json()[n]: embed.set_image(url=r.json()[n]["large_file_url"]) else: embed.set_image(url=r.json()[n]["file_url"]) event.msg.reply('', embed=embed)
def on_songinfo(self, event, content): pad = self.pad_reader.find_pad(content) if not pad: event.msg.reply('Dude weed lmao cannot find shit') return embed = MessageEmbed() embed.title = pad.title embed.color = cfg.color embed.set_footer(text=pad.id) embed.url = pad.url if len(pad.needs) > 0: embed.add_field(name='needs', value=', '.join(str(x) for x in pad.needs), inline=True) embed.set_image( url= "https://cdn.discordapp.com/attachments/142137354084155393/437387811663118336/loadingu.gif" ) message = event.msg.reply('', embed=embed) try: text = ps.get_pad_text(self.session, pad.id) text = text[:text.find("~~~~~~~~")] img = self.t2i.create_img(wrap_lines(text), False) embed.set_image(url=img) message.edit(embed=embed) except ImageUploadError as e: logging.getLogger(self).error(e)
def on_mywaifu(self, event): if event.message.content.lower( ) == "mywaifu" or event.message.content.lower() == "mywaifux": key = str(event.author.id) if key in self.waifus: count = requests.get( "https://danbooru.donmai.us/counts/posts.json", params={ "tags": self.waifus[key] + (" rating:safe" if event.message.content.lower() == "mywaifu" else ""), }) if len(count.content) > 0 and len( count.json()) > 0 and "counts" in count.json( ) and "posts" in count.json()["counts"]: count = count.json()["counts"]["posts"] r = requests.get( "https://danbooru.donmai.us/posts.json", params={ "tags": self.waifus[key] + (" rating:safe" if event.message.content.lower() == "mywaifu" else ""), "limit": 200, "random": "true" if count > 200 else "false" }) if len(r.content) > 0 and len(r.json()) > 0: if "success" in r.json() and not r.json()["success"]: event.message.reply(r.json()["message"]) return n = random.randint(0, len(r.json()) - 1) embed = MessageEmbed() embed.color = cfg.color embed.url = "https://danbooru.donmai.us/posts/{}".format( r.json()[n]["id"]) if "large_file_url" in r.json()[n]: embed.set_image(url=r.json()[n]["large_file_url"]) else: embed.set_image(url=r.json()[n]["file_url"]) embed.set_footer(text=r.json()[n]["id"]) event.message.reply('', embed=embed) else: event.message.reply("nothing found") else: event.message.reply( "waifu not set. use !setwaifu danbooru_tag")
def send_post(self, config, channel, data): if config.mode is FormatMode.PLAIN: channel.send_message('**{}**\n{}'.format( data['title'], 'https://reddit.com{}'.format(data['permalink']) )) else: embed = MessageEmbed() if 'nsfw' in data and data['nsfw']: if not config.nsfw: return embed.color = 0xff6961 else: embed.color = 0xaecfc8 # Limit title to 256 characters nicely if len(data['title']) > 256: embed.title = data['title'][:253] + '...' else: embed.title = data['title'] embed.url = u'https://reddit.com{}'.format(data['permalink']) embed.set_author( name=data['author'], url=u'https://reddit.com/u/{}'.format(data['author']) ) image = None if data.get('media'): if 'oembed' in data['media']: image = data['media']['oembed']['thumbnail_url'] elif data.get('preview'): if 'images' in data['preview']: image = data['preview']['images'][0]['source']['url'] if 'selftext' in data and data['selftext']: # TODO better place for validation sz = min(64, max(config.text_length, 1900)) embed.description = data['selftext'][:sz] if len(data['selftext']) > sz: embed.description += u'...' if image: embed.set_thumbnail(url=image) elif image: embed.set_image(url=image) if config.include_stats: embed.set_footer(text=emoji.emojize('{} upvotes | {} downvotes | {} comments'.format( data['ups'], data['downs'], data['num_comments'] ))) channel.send_message('', embed=embed)
def jeopardy_command(self, event, args): self.log.info('{} executed !jeopardy with args: {}'.format( event.author, args)) if not args.random: return jservice_base_url = 'http://jservice.io/{}' jservice_random = '/api/random' jeopardy_response = requests.get( jservice_base_url.format(jservice_random)).json()[0] from pprint import pprint pprint(jeopardy_response) jeopardy_q = jeopardy_response['question'].replace('&', 'and') jeopardy_a = self.clean_html(jeopardy_response['answer']) jeopardy_id = jeopardy_response['id'] jeopardy_amount = '${}'.format(jeopardy_response['value']) jeopardy_category = jeopardy_response['category']['title'] jeopardy_q = '\n'.join([ ' '.join(jeopardy_q.split()[s:s + 6]) for s in range(0, len(jeopardy_q.split()), 6) ]) self.log.info('amount: {}'.format(jeopardy_amount)) img2txt_url = 'http://api.img4me.com/?text={}&font=impact&size=35&fcolor={}&bcolor=060CE9' question_color = 'FFFFFF' amount_color = 'D49516' question_value = requests.get( img2txt_url.format(jeopardy_q, question_color)).text amount_value = requests.get( img2txt_url.format(jeopardy_amount, amount_color)).text embed = MessageEmbed() embed.set_author( name='Jeopardy!', url='http://jservice.io/', icon_url= 'http://jservice.io/assets/trebek-503ecf6eafde622b2c3e2dfebb13cc30.png' ) embed.title = 'Category: {}'.format(jeopardy_category) embed.timestamp = pendulum.now().in_tz('America/New_York').isoformat() embed.set_thumbnail(url=amount_value) embed.set_image(url=question_value) embed.set_footer(text='Powered by jservice.io') embed.color = '13931798' # dark yellow (hex: #D49516) event.msg.reply(embed=embed)
def _handle_diff(self, diff): # Skip empty changes. if diff: embed = MessageEmbed() embed.color = cfg.color try: img = self.t2i.create_img(diff[2:]) embed.set_image(url=img) except ImageUploadError as e: self.getLogger().error("{}:{}".format(e, str(e))) embed.description = "[{}]({}) was updated".format( self.pad.title, self.pad.url) self.client.send_message('', embed=embed)
def craftReply(self, event, satisfiedPatternIndex): e = None # here, we check for None since empty string means "suppress embeds" if self.reminder.embed is not None: e = MessageEmbed() e.set_image(url=self.reminder.embed) atts = [] if self.reminder.attachments: atts = [(self.reminder.attachments[i], self.reminder.attachmentsData[i]) for i in range(len(self.reminder.attachments))] m = self.reminder.content m = m.replace(u'$AUTHOR', u'<@' + str(event.author.id) + '>') # chech if we have tokens to substitute for this satisfied pattern if satisfiedPatternIndex < len(self.replacementTokens): for index, t in enumerate( self.replacementTokens[satisfiedPatternIndex]): m = m.replace("$" + str(index + 1), t) return (m, e, atts)
def generate_message(self, twitch, new_state): embed = MessageEmbed() embed.title = u'{}'.format(new_state['status']) embed.url = 'https://twitch.tv/{}'.format(new_state['name']) embed.color = 0x6441A4 embed.set_image(url=new_state['preview']) embed.add_field(name='Game', value=new_state['game'], inline=True) embed.add_field(name='Viewers', value=new_state['viewers'], inline=True) if twitch.notification_type == NotificationType.HERE: msg = u'@here {} is now live!'.format(new_state['name']) elif twitch.notification_type == NotificationType.EVERYONE: msg = u'@everyone {} is now live!'.format(new_state['name']) elif twitch.notification_type == NotificationType.ROLE: msg = u'<@&{}> {} is now live!'.format(twitch.notification_target, new_state['name']) else: msg = u'{} is now live!'.format(new_state['name']) return msg, embed
def bunny(self, event): user = self.get_user(event.msg.author.id) if user["xp"] < self.config.bunny_cost: return event.msg.reply( ":no_entry_sign: sadly, you don't have enough XP for a cute bun bun. :(" ) r = requests.get("https://api.bunnies.io/v2/loop/random/?media=gif") if r.status_code == 200: embed = MessageEmbed() bun_bun = r.json() embed.set_image(url=bun_bun['media']['gif']) event.msg.reply(embed=embed) self.users.update_one( {"user_id": str(event.msg.author.id)}, {"$set": { "xp": user["xp"] - self.config.bunny_cost }}) else: event.msg.reply( ":( Sorry, an unexpected error occurred when trying to display a bunny." )
def on_red(self, event, character): try: dbref = db.reference('references/{}'.format(character.lower())) data = dbref.get() if data: embed = MessageEmbed() embed.set_author(name=data.get('owner', 'Unknown owner'), url=data.get('ownerURL'), icon_url=data.get('ownerAvatar')) embed.title = data.get('name', 'Unnamed') if data.get('description'): embed.description = data['description'] embed.color = data['color'] if data.get('image'): embed.set_image(url=data['image']) if data.get('thumbnail'): embed.set_thumbnail(url=data['thumbnail']) event.msg.reply(embed=embed) else: event.msg.reply("Not found") except Exception as e: event.msg.reply(str(e))
def on_danbooru(self, event, tags): count = requests.get("https://danbooru.donmai.us/counts/posts.json", params={"tags": tags}) if len(count.content) > 0 and len( count.json()) > 0 and "counts" in count.json( ) and "posts" in count.json()["counts"]: count = count.json()["counts"]["posts"] r = requests.get("https://danbooru.donmai.us/posts.json", params={ "tags": tags, "limit": 200, "random": "true" if count > 200 else "false" }) if len(r.content) > 0 and len(r.json()) > 0: if "success" in r.json() and not r.json()["success"]: event.message.reply(r.json()["message"]) return n = random.randint(0, len(r.json()) - 1) embed = MessageEmbed() embed.color = cfg.color embed.title = tags embed.url = "https://danbooru.donmai.us/posts/{}".format( r.json()[n]["id"]) if "large_file_url" in r.json()[n]: embed.set_image(url=r.json()[n]["large_file_url"]) else: embed.set_image(url=r.json()[n]["file_url"]) event.msg.reply('', embed=embed) else: event.msg.reply("nothing found")
def server_command(self, event, IP=None): # change default to retro """= server = Gets server info usage :: !server [IP] aliases :: None category :: Minecraft == Arguments IP :: The server's IP address == Examples !server `Gets server info for retro (default)' !server c.nerd.nu `Gets server info for reddit creative server' """ if IP is None and event.guild.id == 414960415018057738: # Retro IP = 'Retro.serv.nu' if IP is None: return url = 'https://use.gameapis.net/mc/query/info/{}'.format(IP) banner_url = 'https://use.gameapis.net/mc/query/banner/{}'.format(IP) r = requests.get(url) try: server_version = r.json()['version'] except KeyError: self.log.error('{} got an error: {}'.format( event.author, r.json()['error'])) event.msg.reply(r.json()['error']) return banner_img = requests.get(banner_url).content embed = MessageEmbed() embed.description = 'Version: {}'.format(server_version) embed.set_image(url=banner_url) event.msg.reply(embed=embed)
def on_google_i(self, event, search): r = requests.get("https://www.googleapis.com/customsearch/v1", params = { "key": cfg.google_key, "cx": cfg.google_cx, "searchType": "image", "q": search }) if len(r.content) > 0 and len(r.json()) > 0 and "items" in r.json() and len(r.json()["items"]) > 0: item = r.json()["items"][random.randint(0, len(r.json()["items"]) - 1)] embed = MessageEmbed() embed.color = cfg.color embed.title = search if "link" in item: embed.set_image(url=item["link"]) event.msg.reply('', embed=embed) else: event.msg.reply("nothing found")
def get_embed(self, star, msg, config): # Create the 'header' (non-embed) text stars = ':star:' if len(star.stars) > 1: if len(star.stars) >= config.star_color_max: stars = ':star2:' stars = stars + ' {}'.format(len(star.stars)) content = '{} <#{}> ({})'.format( stars, msg.channel_id, msg.id ) # Generate embed section embed = MessageEmbed() embed.description = msg.content if msg.attachments: attach = list(msg.attachments.values())[0] if attach.url.lower().endswith(('png', 'jpeg', 'jpg', 'gif', 'webp')): embed.set_image(url=attach.url) if msg.embeds: if msg.embeds[0].image.url: embed.set_image(url=msg.embeds[0].image.url) elif msg.embeds[0].thumbnail.url: embed.set_image(url=msg.embeds[0].thumbnail.url) author = msg.guild.get_member(msg.author) if author: embed.set_author( name=author.name, icon_url=author.user.avatar_url ) else: embed.set_author( name=msg.author.username, icon_url=msg.author.avatar_url) embed.add_field(name=u'\u200b', value=(u'→ [Jump to original message]' u'(https://discordapp.com/channels/{}/{}/{})'.format(msg.guild.id, msg.channel_id, msg.id))) embed.timestamp = msg.timestamp.isoformat() embed.color = config.get_color(len(star.stars)) return content, embed
def get_embed(self, star, msg, config): # Create the 'header' (non-embed) text stars = ':star:' if len(star.stars) > 1: if len(star.stars) >= config.star_color_max: stars = ':star2:' stars = stars + ' {}'.format(len(star.stars)) content = '**{}** <#{}> ({})'.format(stars, msg.channel_id, msg.id) # Generate embed section embed = MessageEmbed() embed.description = '{}'.format(msg.content) if msg.attachments: attach = list(msg.attachments.values())[0] if attach.url.lower().endswith( ('png', 'jpeg', 'jpg', 'gif', 'webp')): embed.set_image(url=attach.url) if msg.embeds: if msg.embeds[0].image.url: embed.set_image(url=msg.embeds[0].image.url) elif msg.embeds[0].thumbnail.url: embed.set_image(url=msg.embeds[0].thumbnail.url) author = msg.guild.get_member(msg.author) if author: embed.set_author(name=author, icon_url=author.user.avatar_url) else: embed.set_author(name=msg.author, icon_url=msg.author.avatar_url) embed.timestamp = msg.timestamp.isoformat() embed.color = config.get_color(len(star.stars)) row = ActionRow() row.add_component(label='Jump to Message', type=ComponentTypes.BUTTON, style=ButtonStyles.LINK, url='https://discord.com/channels/{}/{}/{}'.format( msg.guild.id, msg.channel_id, msg.id)) return content, embed, row
def create_message(self): msgcontent = "**Word**: " + " ".join( self.word_to_emote(self.word_current)) embed = MessageEmbed() embed.set_image(url=self.get_hangman_image(self.failed_attempts)) return self.game_channel.send_message(msgcontent, embed=embed)
def update_msg(self): msgcontent = "**Word**: " + " ".join( self.word_to_emote(self.word_current)) embed = MessageEmbed() embed.set_image(url=self.get_hangman_image(self.failed_attempts)) self.main_msg.edit(msgcontent, embed=embed)