async def lmgtfy(self, *, search): """Let Me Google That For You""" command = sys._getframe().f_code.co_name url = "http://lmgtfy.com/?q=" search = search.replace(" ", "+") await self.bot.say(url + "" + "" + search) log(class_name, command)
async def g(self, *, query): """Searches google and gives you top result.""" command = sys._getframe().f_code.co_name await self.bot.type() try: card, entries = await self.get_google_entries(query) except RuntimeError as e: await self.bot.say(str(e)) else: if card: value = '\n'.join(entries[:3]) if value: card.add_field(name='Search Results', value=value, inline=False) return await self.bot.say(embed=card) if len(entries) == 0: return await self.bot.say('No results found... sorry.') next_two = entries[1:3] if next_two: formatted = '\n'.join(map(lambda x: '<%s>' % x, next_two)) msg = '{}\n\n**See also:**\n{}'.format(entries[0], formatted) else: msg = entries[0] await self.bot.say(msg) log(class_name, command)
async def ingredients(self, *, recipe): """Displays the ingredients for a specific recipe""" command = sys._getframe().f_code.co_name url = "https://api.edamam.com/" search = recipe search_addon = "search?q=" + search id_addon = "&app_id=" + food_id key_addon = "&app_key=" + food_key full_search = url + search_addon + id_addon + key_addon r = requests.get(full_search) recipe = r.json() try: test = recipe["hits"][0]["recipe"]["url"] except: await self.bot.say("There were no recipes matching your search.") return url = recipe["hits"][1]["recipe"]["url"] label = recipe["hits"][0]["recipe"]["label"] ingredients = recipe["hits"][0]["recipe"]["ingredientLines"] counter = 0 ingredients_message = "**%s**\n \n" % (label) for i in range(len(ingredients)): ingredients_message += recipe["hits"][0]["recipe"][ "ingredientLines"][counter] + "\n" counter += 1 ingredients_message += "\n<%s>" % (url) await self.bot.say(ingredients_message) log(class_name, command)
async def edward(self, ctx): """Displays a picture of Edward""" command = sys._getframe().f_code.co_name channel = self.bot.get_channel(ctx.message.channel.id) edwards = os.listdir('images/edward/') choice = random.choice(edwards) await self.bot.send_file(channel, "images/edward/" + choice) log(class_name, command)
async def logout(self, ctx): """Shuts Jeeves Down""" command = sys._getframe().f_code.co_name log(class_name, command) if discord.utils.get(ctx.message.author.roles, name="Jeeves"): await self.bot.say("Goodbye.") await self.bot.logout() else: await self.bot.say("You do not have permission to use that command.") return
async def simplewolf(self, *, search): """Extremely Simple Wolfram Alpha Search""" command = sys._getframe().f_code.co_name search = search.replace(" ", "+") url = "http://api.wolframalpha.com/v1/result?appid=" + wolfram_id + "&i=" + search f = urlopen(url) answer = f.read() answer = answer.decode("utf-8") await self.bot.say(answer) log(class_name, command)
async def restart(self, ctx): """Restarts Jeeves""" command = sys._getframe().f_code.co_name log(class_name, command) if discord.utils.get(ctx.message.author.roles, name="Jeeves"): file = open("restart_status.txt", "w") file.write("0") file.close() await self.bot.say("Rebooting...") os.execl(sys.executable, sys.executable, *sys.argv) else: await self.bot.say("You do not have permission to use that command.") return
async def recipe(self, ctx, *, ingredient): """Searches for a recipe""" command = sys._getframe().f_code.co_name url = "https://api.edamam.com/" search = ingredient search_addon = "search?q=" + search id_addon = "&app_id=" + food_id key_addon = "&app_key=" + food_key full_search = url + search_addon + id_addon + key_addon channel = self.bot.get_channel(ctx.message.channel.id) r = requests.get(full_search) recipe = r.json() try: test = recipe["hits"][0]["recipe"]["url"] except: await self.bot.say("There were no recipes matching your search.") return url = recipe["hits"][0]["recipe"]["url"] label = recipe["hits"][0]["recipe"]["label"] image = recipe["hits"][0]["recipe"]["image"] ingredients = recipe["hits"][0]["recipe"]["ingredientLines"] calories = recipe["hits"][0]["recipe"]["calories"] int(calories) filename = image.split('/')[-1] urllib.request.urlretrieve(image, "images/" + filename) image_path = "images/" + filename ingredient_list = [] for ing in ingredients: ingredient_list.append(ing) final_ingredients = "" for ing in ingredient_list: final_ingredients += ing + "\n" recipe_message = ( "**Here is the most relevant recipe based on your search.** \n \n" "%s\n" "Calories: %d \n \n" "URL to recipe: <%s> \n") % (label, calories, url) await self.bot.send_file(channel, image_path, content=recipe_message) log(class_name, command)
async def wolfram(self, ctx, *, search): """A Bit Smarter Wolfram Alpha Search""" command = sys._getframe().f_code.co_name urlsearch = search.replace(" ", "+") url = "http://api.wolframalpha.com/v1/simple?appid=" + wolfram_id + "&i=" + urlsearch + "" image = search + ".gif" number = randint(312, 789239187) stringnumber = str(number) urllib.request.urlretrieve(url, "images/wolfram/" + stringnumber + ".gif") image_path = "images/wolfram/" + stringnumber + ".gif" resize = Image.open(image_path) resize.save(image_path, quality=50) await self.bot.send_file(ctx.message.channel, image_path, content=search) log(class_name, command)
async def amazon(self, ctx, *, product): """Searches amazon and gets the top result. (Not very smart)""" command = sys._getframe().f_code.co_name products = amazon.search_n(1, Keywords=product, SearchIndex='All') channel = ctx.message.channel title = products[0].title url = products[0].offer_url image = products[0].large_image_url price = products[0].price_and_currency[0] url = url.replace("?tag=incen-20", " ") filename = image.split('/')[-1] urllib.request.urlretrieve(image, "images/amazon/" + filename) image_path = "images/amazon/" + filename amazon_message = ("**%s**\n\n" "Price: $%s \n\n" "URL: %s \n\n") % (title, price, url) await self.bot.send_file(channel, image_path, content=amazon_message) log(class_name, command)
async def get_recipes(self, *, ingredient): """Gets a list of recipes""" command = sys._getframe().f_code.co_name if " " in ingredient: split_word = ingredient.rsplit(' ', 1)[0] to_amount = ingredient.rsplit(' ', 1)[1] has_digit = any(char.isdigit() for char in to_amount) if has_digit: ingredient = split_word int(to_amount) ingredient = ingredient.replace(" ", "+") else: ingredient = ingredient.replace(" ", "+") to_amount = 5 else: ingredient = ingredient.replace(" ", "+") to_amount = 5 url = "https://api.edamam.com/" search = ingredient search_addon = "search?q=" + search id_addon = "&app_id=" + food_id key_addon = "&app_key=" + food_key from_addon = "&from=0" to_addon = "&to=" + str(to_amount) full_search = url + search_addon + id_addon + key_addon + from_addon + to_addon iteration = int(to_amount) r = requests.get(full_search) recipe = r.json() try: test = recipe["hits"][0]["recipe"]["url"] except: await self.bot.say("There were no recipes matching your search.") return urls = [] counter = 0 for i in range(iteration): urls.append(recipe["hits"][counter]["recipe"]["url"]) counter += 1 labels = [] labels_counter = 0 for i in range(iteration): labels.append(recipe["hits"][labels_counter]["recipe"]["label"]) labels_counter += 1 recipe_counter = 0 recipes_message = "**Here are the most relevant recipes based on your search.**\n \n" for i in range(iteration): recipes_message += "%s \n<%s> \n \n" % (labels[recipe_counter], urls[recipe_counter]) recipe_counter += 1 await self.bot.say(recipes_message) log(class_name, command)