async def pokemon_route(ctx:tanjun.abc.SlashContext, pokemon:str, version:str): try: possibilities = ["red","blue","diamond","pearl","platinum","yellow","gold","silver","crystal","firered","leafgreen","heartgold","soulsilver","ruby","sapphire","emerald","x","y","omega-ruby","alpha-sapphire","black","white"] matches = difflib.get_close_matches( version.lower(), possibilities, n=1, cutoff=0.3) pokemondata = (requests.get("https://pokeapi.co/api/v2/pokemon/{}/encounters".format(pokemon.lower()))).json() vlist = [] dlist = [] for x in pokemondata: version = x["version_details"][0] if version["version"]["name"] == matches[0]: vlist.append(x) else: if version["version"]["name"]: dlist.append(version["version"]["name"]) dlist = list(set(dlist)) if len(vlist) > 0: embed = hikari.Embed( title = pokemon.title() + " Routes " "- Version: " + matches[0].title(), color = hikari.Color(0xee1515) ) for y in vlist: version = y["version_details"][0] name = y["location_area"]["name"].replace("-", " ") embed.add_field(name=name.title(), value="Encounter Potential: " + str(version["max_chance"]) + "%", inline=False) await ctx.respond(embed) elif len(vlist) <= 1 and dlist == []: await ctx.respond("This pokemon cannot be found in wild grass.") elif vlist == [] and len(dlist) > 0: embed = hikari.Embed( title = pokemon.title() + " can be found in these versions!", color = hikari.Color(0xee1515) ) for x in dlist: embed.add_field(name=x.title(), value="\u200b", inline=True) await ctx.respond(embed) except JSONDecodeError: await ctx.respond("Make sure the pokemon's name is typed correctly!")
async def mtg_rulings(ctx:tanjun.abc.SlashContext, card:str): try: mtgdata = (requests.get("https://api.magicthegathering.io/v1/cards?name={}&pageSize=1&contains=imageUrl".format(card.lower()))).json() card = mtgdata.get("cards")[0] rulings = card["rulings"] embed = hikari.Embed( title = "Rulings.", color = hikari.Color(0xFF0000) ) embed.set_thumbnail(card["imageUrl"]) for x in rulings: embed.add_field(name="Date: {}".format(x["date"]), value= x["text"], inline=False) await ctx.respond(embed) except IndexError: await ctx.respond("Please double check the spelling of the card.") except KeyError: await ctx.respond("This card does not have any rulings.")
async def count(ctx: tanjun.abc.SlashContext, game: str) -> None: results = await SteamSearch(game) appID = results[0] name = results[1] gsdata = (requests.get( "https://store.steampowered.com/api/appdetails/?appids={}&l=english". format(appID))).json() codata = (requests.get( "https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid={}" .format(appID))).json() check = codata["response"] if check.get("player_count") not in check.values(): await ctx.respond("This game currently does not have players online.") else: player_count = codata["response"]["player_count"] appdetails = gsdata.get("{}".format(appID)).get("data") embed = hikari.Embed(title=name, description="There are currently " + "`{}`".format(player_count) + " playing.", color=hikari.Color(0x808080)) embed.set_thumbnail(appdetails["header_image"]) await ctx.respond(embed)
async def specials(ctx: tanjun.abc.SlashContext) -> None: locale.setlocale(locale.LC_ALL, "en_US.UTF-8") sdata = (requests.get( "http://store.steampowered.com/api/featuredcategories/&l=english") ).json() specials = sdata["specials"]["items"] special1 = specials[0] special2 = specials[1] special3 = specials[2] special4 = specials[3] special5 = specials[4] embed = hikari.Embed( title="Specials", url="https://store.steampowered.com/search/?specials=1", color=hikari.Color(0xE6E6FA)) embed.add_field(name=special1["name"], value="Price: " + locale.currency(float(special1["final_price"]) / 100.0) + "\nDiscount Ends: " + datetime.datetime.fromtimestamp( special1["discount_expiration"]).strftime('%m/%d/%Y'), inline=False) embed.add_field(name=special2["name"], value="Price: " + locale.currency(float(special2["final_price"]) / 100.0) + "\nDiscount Ends: " + datetime.datetime.fromtimestamp( special2["discount_expiration"]).strftime('%m/%d/%Y'), inline=False) embed.add_field(name=special3["name"], value="Price: " + locale.currency(float(special3["final_price"]) / 100.0) + "\nDiscount Ends: " + datetime.datetime.fromtimestamp( special3["discount_expiration"]).strftime('%m/%d/%Y'), inline=False) embed.add_field(name=special4["name"], value="Price: " + locale.currency(float(special4["final_price"]) / 100.0) + "\nDiscount Ends: " + datetime.datetime.fromtimestamp( special4["discount_expiration"]).strftime('%m/%d/%Y'), inline=False) embed.add_field(name=special5["name"], value="Price: " + locale.currency(float(special5["final_price"]) / 100.0) + "\nDiscount Ends: " + datetime.datetime.fromtimestamp( special5["discount_expiration"]).strftime('%m/%d/%Y'), inline=False) await ctx.respond(embed)
async def game_updates(ctx: tanjun.abc.SlashContext, game: str) -> None: results = await SteamSearch(game) appID = results[0] updata = (requests.get( "https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/?appid={}". format(appID))).json() cleanr = re.compile(f'<.*?>|{{.*?}}|\[img\].+\[/img\]|\[.*?\]') def cleanhtml(raw_html): cleantext = re.sub(cleanr, '', raw_html) return cleantext items = updata["appnews"]["newsitems"] item = [x for x in items if x["feedlabel"] == "Community Announcements"] contents = cleanhtml(item[0]["contents"]) # Tokenizes sentence to limit the amt of sentences displayed. scontents = sent_tokenize(contents) contents = " ".join([str(item) for item in scontents[:5]]) url = item[0]["url"] url = url.replace(" ", "") embed = hikari.Embed(title=item[0]["title"], url=url, description=contents, color=hikari.Color(0x454B1B)) date_time = item[0]["date"] date_time = datetime.datetime.fromtimestamp(date_time).strftime('%m/%d/%Y') embed.add_field(name="Date: ", value=date_time, inline=True) if item[0]["author"] != "": embed.add_field(name="Author: ", value=item[0]["author"], inline=True) else: pass embed.set_footer(text=item[0]["feedlabel"]) await ctx.respond(embed=embed)
async def mtg_list(ctx:tanjun.abc.SlashContext, card:str): try: mtgdata = (requests.get("https://api.magicthegathering.io/v1/cards?name={}&pageSize=7&contains=imageUrl".format(card.lower()))).json() cards = mtgdata.get("cards") embed = hikari.Embed( title = "Cards", color = hikari.Color(0x228b22) ) for x in cards: embed.add_field(name=x["name"], value="Set: " + x["setName"], inline=False) await ctx.respond(embed) except IndexError: await ctx.respond("Please double check the spelling of the card.")
async def pokemon_nature(ctx:tanjun.abc.SlashContext, nature:str): possibilities = ["adamant","bashful","bold","brave","calm","careful","docile","gentle","hardy","hasty","impish","jolly","lax","lonely","mild","modest","naive","naughty","quiet","quirky","rash","relaxed","sassy","serious","timid"] matches = difflib.get_close_matches( nature.lower(), possibilities, n=1, cutoff=0.3) pokemondata = (requests.get("https://pokeapi.co/api/v2/nature/{}/".format(matches[0].lower()))).json() move_preference = pokemondata['move_battle_style_preferences'] embed= hikari.Embed( title = pokemondata["name"].title(), color = hikari.Color(0xffcb05) ) embed.add_field(name="Decreased Stat", value = pokemondata['decreased_stat']['name'].title(), inline=True) embed.add_field(name="Increased Stat", value = pokemondata['increased_stat']['name'].title(), inline=True) embed.add_field(name="Likes Flavor", value = pokemondata['likes_flavor']['name'].title(), inline=True) embed.add_field(name="Hates Flavor", value = pokemondata['hates_flavor']['name'].title(), inline=True) for x in move_preference: embed.add_field(name=x['move_battle_style']['name'].title(), value = "High HP Preference: " + str(x['high_hp_preference']) + "%" + "\nLow HP Preference: " + str(x['low_hp_preference']) + "%", inline=False) await ctx.respond(embed)
def purple(): return hikari.Color(0x9b59b6) @staticmethod
def dark_blue(): return hikari.Color(0x206694) @staticmethod
def blue(): return hikari.Color(0x3498db) @staticmethod
def og_blurple(): return hikari.Color(0x7289da) @staticmethod
def lighter_gray(): return hikari.Color(0x95a5a6) @staticmethod
def light_gray(): return hikari.Color(0x979c9f) @staticmethod
def teal(): return hikari.Color(0x1abc9c) @staticmethod
def yellow(): return hikari.Color(0xFEE75C) def get_emote(discord_text: str) -> str:
def fuchsia(): return hikari.Color(0xEB459E) @staticmethod
def dark_theme(): return hikari.Color(0x36393F) @staticmethod
def greyple(): return hikari.Color(0x5865F2) @staticmethod
def blurple(): return hikari.Color(0x5865F2) @staticmethod
def dark_purple(): return hikari.Color(0x71368a) @staticmethod
def magenta(): return hikari.Color(0xe91e63) @staticmethod
def dark_teal(): return hikari.Color(0x11806a) @staticmethod
async def _game_embed(ctx: tanjun.abc.Context, appID) -> None: # API request to then get game details using appID. gsdata = (requests.get( "https://store.steampowered.com/api/appdetails/?appids={}&l=english". format(appID))).json() # Remove html content from description and notice. cleanr = re.compile('<.*?>') def cleanhtml(raw_html): cleantext = re.sub(cleanr, '', raw_html) return cleantext # API request to get reviews for games. rdata = (requests.get( "https://store.steampowered.com/appreviews/{}?json=1".format(appID)) ).json() # Accessing data dictionary and assigned them values. appdetails = gsdata.get("{}".format(appID)).get("data") description = appdetails.get("short_description") embed = hikari.Embed( title=appdetails["name"], url="https://store.steampowered.com/app/{}/".format(appID), description=cleanhtml(description), color=hikari.Color(0x00FFFF)) embed.set_image(appdetails["header_image"]) # If statement to check if game has a legal notice or not. if appdetails.get("legal_notice") not in appdetails.values( ) or appdetails.get("legal_notice") == None: embed.set_footer(text="") else: notice = appdetails["legal_notice"] snotice = sent_tokenize(notice) notice = " ".join([str(item) for item in snotice[:1]]) embed.set_footer(text=cleanhtml(notice)) # Adding multiple devs to developer field. dev = ", ".join([str(item) for item in appdetails.get("developers")]) embed.add_field(name="Developers: ", value=dev, inline=True) # Price checks for games. price = appdetails.get("price_overview") if appdetails["is_free"] == True: embed.add_field(name="Price: ", value="Free", inline=True) elif appdetails["release_date"]["coming_soon"] == True and price is None: embed.add_field(name="Price: ", value="Coming Soon.", inline=True) elif price.get("initial_formatted") != "": embed.add_field(name="Price: ", value="~~{}~~".format(price.get("initial_formatted")) + " " + "**{}**".format(price.get("final_formatted")), inline=True) else: embed.add_field(name="Price: ", value=price["final_formatted"], inline=True) review = rdata["query_summary"]["review_score_desc"] embed.add_field(name="Review:", value=review, inline=True) try: await ctx.edit_last_response(content="", embed=embed) except LookupError: await ctx.respond(embed)
def dark_red(): return hikari.Color(0x992d22) @staticmethod
def dark_gray(): return hikari.Color(0x607d8b) @staticmethod
def dark_green(): return hikari.Color(0x1f8b4c) @staticmethod
def brand_green(): return hikari.Color(0x57F287) @staticmethod
def darker_gray(): return hikari.Color(0x546e7a) @staticmethod
def green(): return hikari.Color(0x2ecc71) @staticmethod
def red(): return hikari.Color(0xe74c3c) @staticmethod