async def pokemon(ctx, stat_name, areaname = "", *, timespan = None): mon = details(stat_name, bot.config['mon_icon_repo'], bot.config['language']) footer_text = "" text = "" loading = f"{bot.locale['loading']} {mon.name} Stats" area = get_area(areaname) if not area[1] == bot.locale['all']: footer_text = area[1] loading = f"{loading} • " if timespan is None: timespan = list([datetime(2010, 1, 1, 0, 0), datetime.now()]) else: loading = "" if "-" in timespan: timespan = list(timespan.split('-')) for i in [0, 1]: timespan[i] = dateparser.parse(timespan[i]) footer_text = f"{(bot.locale['between']).capitalize()} {timespan[0].strftime(bot.locale['time_format_dhm'])} {bot.locale['and']} {timespan[1].strftime(bot.locale['time_format_dhm'])}" else: timespan = list([dateparser.parse(timespan), datetime.now()]) if area[1] == bot.locale['all']: footer_text = f"{(bot.locale['since']).capitalize()} {timespan[0].strftime(bot.locale['time_format_dhm'])}" else: footer_text = f"{footer_text}, {bot.locale['since']} {timespan[0].strftime(bot.locale['time_format_dhm'])}" print(f"@{ctx.author.name} requested {mon.name} stats for area {area[1]}") embed = discord.Embed(title=f"{mon.name}", description=text) embed.set_thumbnail(url=mon.icon) embed.set_footer(text=f"{loading}{footer_text}", icon_url="https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif") message = await ctx.send(embed=embed) shiny_count = await queries.get_shiny_count(mon.id, area[0], timespan[0], timespan[1], bot.config) if shiny_count > 0: shiny_total = await queries.get_shiny_total(mon.id, area[0], timespan[0], timespan[1], bot.config) shiny_odds = int(round((shiny_total / shiny_count), 0)) text = text + f"{bot.locale['shinies']}: **1:{shiny_odds}** ({shiny_count:_}/{shiny_total:_})\n" else: text = text + f"{bot.locale['shinies']}: **0**\n" embed.description = text.replace("_", bot.locale['decimal_comma']) await message.edit(embed=embed) print(f" [1/3] Shiny Data for {mon.name} Stats") scan_numbers = await queries.get_scan_numbers(mon.id, area[0], timespan[0], timespan[1], bot.config) for scanned, hundos, zeros, nineties in scan_numbers: scanned_total = int(scanned) if scanned_total > 0: hundo_count = int(hundos) zero_count = int(zeros) ninety_count = int(nineties) else: hundo_count = 0 zero_count = 0 ninety_count = 0 if hundo_count > 0: hundo_odds = int(round((scanned_total / hundo_count), 0)) text = text + f"{bot.locale['hundos']}: **{hundo_count:_}** (1:{hundo_odds})\n\n" else: text = text + f"{bot.locale['hundos']}: **0/{scanned_total:_}**\n\n" if ninety_count > 0: ninety_odds = round((scanned_total / ninety_count), 0) text = text + f"{bot.locale['90']}: **{ninety_count:_}** (1:{int(ninety_odds)}) | " else: text = text + f"{bot.locale['90']}: **0** | " if zero_count > 0: zero_odds = round((scanned_total / zero_count), 0) text = text + f"{bot.locale['0']}: **{zero_count:_}** (1:{int(zero_odds)})\n" else: text = text + f"{bot.locale['0']}: **0**\n" embed.description = text.replace("_", bot.locale['decimal_comma']) await message.edit(embed=embed) print(f" [2/3] Scan Data for {mon.name} Stats") big_numbers = await queries.get_big_numbers(mon.id, area[0], timespan[0], timespan[1], bot.config) for mons, found, boosted, time in big_numbers: mon_total = int(mons) if found is not None: found_count = int(found) boosted_count = int(boosted) else: found_count = 0 boosted_count = 0 if found_count > 0: days = (timespan[1].date() - (big_numbers[0][3]).date()).days if days < 1: days = 1 mon_odds = int(round((mon_total / found_count), 0)) mon_rate = str(round((found_count / days), 1)).replace(".", bot.locale['decimal_dot']) text = text.replace(f"\n{bot.locale['90']}", f"{bot.locale['rarity']}: **1:{mon_odds}**\n{bot.locale['rate']}: **{mon_rate}/{bot.locale['day']}**\n\n{bot.locale['90']}") boosted_odds = str(round((boosted_count / found_count * 100), 1)).replace(".", bot.locale['decimal_dot']) text = text + f"{bot.locale['weatherboost']}: **{boosted_odds}%**\n" scanned_odds = str(round((scanned_total / found_count * 100), 1)).replace(".", bot.locale['decimal_dot']) text = text + f"{bot.locale['scanned']}: **{scanned_odds}%**\n\n" text = text + f"{bot.locale['total_found']}: **{found_count:_}**" else: text = text.replace(f"\n{bot.locale['90']}", f"{bot.locale['rarity']}: **0**\n{bot.locale['rate']}: **0/{bot.locale['day']}**\n\n{bot.locale['90']}") text = text + f"{bot.locale['weatherboost']}: **0%**\n{bot.locale['scanned']}: **0**\n\n{bot.locale['total_found']}: **0**" embed.description = text.replace("_", bot.locale['decimal_comma']) embed.set_footer(text=footer_text) await message.edit(embed=embed) print(f" [3/3] Total Data for {mon.name} Stats") print(f"Done with {mon.name} Stats.")
async def quest(self, ctx, area, *, rewards): if not ctx.message.author.id in self.bot.config['admins']: print(f"@{ctx.author.name} tried to create a Quest Board but is no Admin") return print("Creating Quest Board") embed = discord.Embed(title="Quest Board", description="") message = await ctx.send(embed=embed) rewards = list(rewards.split(',')) items = list() mons = list() areaexist = False for areag in self.bot.geofences: if areag['name'].lower() == area.lower(): areaexist = True if not areaexist: embed.description = "Couldn't find that area. Try again." await message.edit(embed=embed) return for reward in rewards: item_found = False for item_id in self.bot.items: if self.bot.items[item_id]["name"].lower() == reward.lower(): items.append(int(item_id)) found_item_id = item_id item_found = True if not item_found: mon = details(reward, self.bot.config['mon_icon_repo'], self.bot.config['language']) mons.append(mon.id) await ctx.message.delete() embed.title = "Now downloading Emotes" embed_emotes = "" embed_rest = f"\n\n```Area: {area}\nMons: {mons}\nItems: {items}\nChannel ID: {message.channel.id}\nMessage ID: {message.id}```" embed.description = embed_emotes + embed_rest await message.edit(embed=embed) print("Wrote Quest Board to config/boards.json - Now downloading Emotes") guild = await self.bot.fetch_guild(self.bot.config['host_server']) existing_emotes = await guild.fetch_emojis() for mon_id in mons: emote_exist = False for existing_emote in existing_emotes: if f"m{mon_id}" == existing_emote.name: emote_exist = True if not emote_exist: try: image = await self.download_url(f"{self.bot.config['mon_icon_repo']}pokemon_icon_{str(mon_id).zfill(3)}_00.png") emote = await guild.create_custom_emoji(name=f"m{mon_id}", image=image) emote_ref = f"<:{emote.name}:{emote.id}>" embed_emotes = f"{embed_emotes}\n{emote_ref} `{emote_ref}`" embed.description = embed_emotes + embed_rest await message.edit(embed=embed) if f"m{mon_id}" in self.bot.custom_emotes: self.bot.custom_emotes[f"m{mon_id}"] = emote_ref else: self.bot.custom_emotes.update({f"m{mon_id}": emote_ref}) except Exception as err: print(err) print(f"Error while importing emote m{mon_id}") else: embed_emotes = f"{embed_emotes}\nmon {mon_id}: already exists" embed.description = embed_emotes + embed_rest await message.edit(embed=embed) for item in items: emote_exist = False for existing_emote in existing_emotes: if f"i{item}" == existing_emote.name: emote_exist = True if not emote_exist: try: image = await self.download_url(f"{self.bot.config['mon_icon_repo']}rewards/reward_{item}_1.png") emote = await guild.create_custom_emoji(name=f"i{item}", image=image) emote_ref = f"<:{emote.name}:{emote.id}>" embed_emotes = f"{embed_emotes}\n{emote_ref} `{emote_ref}`" embed.description = embed_emotes + embed_rest await message.edit(embed=embed) if f"i{item}" in self.bot.custom_emotes: self.bot.custom_emotes[f"i{item}"] = emote_ref else: self.bot.custom_emotes.update({f"i{item}": emote_ref}) except Exception as err: print(err) print(f"Error while importing emote i{item}") else: embed_emotes = f"{embed_emotes}\nitem {item}: already exists" embed.description = embed_emotes + embed_rest await message.edit(embed=embed) embed.title = "Succesfully created this Quest Board" embed.description = "You'll see the message being filled in soon.\n" + embed_emotes + embed_rest await message.edit(embed=embed) print("All done with Quest Board") title = self.bot.locale['quests'] if len(items) + len(mons) == 1: title2 = "" if len(items) == 1: title2 = self.bot.items[found_item_id]["name"] if len(mons) == 1: title2 = mon.name title = f"{title2} {title}" self.bot.boards['quests'].append({"channel_id": message.channel.id, "message_id": message.id, "title": title, "area": area, "mons": mons, "items": items}) with open("config/boards.json", "w") as f: f.write(json.dumps(self.bot.boards, indent=4)) with open("config/emotes.json", "w") as f: f.write(json.dumps(self.bot.custom_emotes, indent=4))
async def quest(ctx, areaname = "", *, reward): footer_text = "" text = "" loading = bot.locale['loading_quests'] area = get_area(areaname) if not area[1] == bot.locale['all']: footer_text = area[1] loading = f"{loading} • {footer_text}" print(f"@{ctx.author.name} requested quests for area {area[1]}") embed = discord.Embed(title=bot.locale['quests'], description=text) embed.set_footer(text=loading, icon_url="https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif") message = await ctx.send(embed=embed) items = list() mons = list() item_found = False for item_id in bot.items: if bot.items[item_id]["name"].lower() == reward.lower(): embed.set_thumbnail(url=f"{bot.config['mon_icon_repo']}rewards/reward_{item_id}_1.png") embed.title = f"{bot.items[item_id]['name']} {bot.locale['quests']}" items.append(int(item_id)) item_found = True if not item_found: mon = details(reward, bot.config['mon_icon_repo'], bot.config['language']) embed.set_thumbnail(url=f"{bot.config['mon_icon_repo']}pokemon_icon_{str(mon.id).zfill(3)}_00.png") embed.title = f"{mon.name} {bot.locale['quests']}" mons.append(mon.id) await message.edit(embed=embed) quests = await queries.get_active_quests(bot.config, area[0]) length = 0 reward_mons = list() reward_items = list() lat_list = list() lon_list = list() for quest_json, quest_text, lat, lon, stop_name, stop_id in quests: quest_json = json.loads(quest_json) found_rewards = True item_id = quest_json[0]["item"]["item"] mon_id = quest_json[0]["pokemon_encounter"]["pokemon_id"] if item_id in items: reward_items.append([item_id, lat, lon]) emote_name = f"i{item_id}" emote_img = f"{bot.config['mon_icon_repo']}rewards/reward_{item_id}_1.png" elif mon_id in mons: reward_mons.append([mon_id, lat, lon]) emote_name = f"m{mon_id}" emote_img = f"{bot.config['mon_icon_repo']}pokemon_icon_{str(mon_id).zfill(3)}_00.png" else: found_rewards = False if found_rewards: if len(stop_name) >= 30: stop_name = stop_name[0:27] + "..." lat_list.append(lat) lon_list.append(lon) if bot.config['use_map']: map_url = bot.map_url.quest(lat, lon, stop_id) else: map_url = f"https://www.google.com/maps/search/?api=1&query={lat},{lon}" map_url = short(map_url) entry = f"[{stop_name}]({map_url})\n" if length + len(entry) >= 2048: break else: text = text + entry length = length + len(entry) embed.description = text image = "" if length > 0: if bot.config['use_static']: guild = await bot.fetch_guild(bot.config['host_server']) existing_emotes = await guild.fetch_emojis() emote_exist = False for existing_emote in existing_emotes: if emote_name == existing_emote.name: emote_exist = True if not emote_exist: try: image = await Admin.download_url("", emote_img) emote = await guild.create_custom_emoji(name=emote_name, image=image) emote_ref = f"<:{emote.name}:{emote.id}>" if emote_name in bot.custom_emotes: bot.custom_emotes[emote_name] = emote_ref else: bot.custom_emotes.update({emote_name: emote_ref}) except Exception as err: print(err) print(f"Error while importing emote {emote_name}") static_map = bot.static_map.quest(lat_list, lon_list, reward_items, reward_mons, bot.custom_emotes) urllib.request.urlretrieve(static_map, "quest_command_static_map_temp.png") channel = await bot.fetch_channel(bot.config['host_channel']) image_msg = await channel.send(file=discord.File("quest_command_static_map_temp.png")) image = image_msg.attachments[0].url os.remove("quest_command_static_map_temp.png") if not emote_exist: await emote.delete() bot.custom_emotes.pop(emote_name) else: embed.description = bot.locale["no_quests_found"] embed.set_footer(text=footer_text) embed.set_image(url=image) await message.edit(embed=embed) await asyncio.sleep(2)
async def pokemon(ctx, stat_name, areaname="", *, timespan=None, alt_timespan=None): if not isUser(ctx.author.roles, ctx.channel.id): print(f"@{ctx.author.name} tried to use !pokemon but is no user") return mon = details(stat_name, bot.config['mon_icon_repo'], bot.config['language']) footer_text = "" text = "" loading = f"{bot.locale['loading']} {mon.name} Stats" area = get_area(areaname) if not area[1] == bot.locale['all'] and not config['timespan_in_footer']: footer_text = area[1] loading = f"{loading} • " elif config['timespan_in_footer']: footer_text = area[1] loading = f"{loading}" if dateparser.search.search_dates( areaname, languages=[bot.config['language'] ]) is not None: #check for dates in areaname if dateparser.search.search_dates( f"{timespan}", languages=[ bot.config['language'] ]) is not None: #check for dates in everything after areaname timespan = f"{areaname} {timespan}" else: timespan = areaname elif dateparser.search.search_dates( f"{areaname} {timespan}", languages=[ bot.config['language'] ]) is not None and (dateparser.search.search_dates( timespan, languages=[bot.config['language']]) is None): timespan = f"{areaname} {timespan}" print(f"timespan found in command: {timespan}") if config['timespan_in_footer']: if config['use_alt_table_for_pokemon']: oldest_mon_date = await queries.get_oldest_mon_date( bot.config, use_alt_table=True) if oldest_mon_date is None: oldest_mon_date = await queries.get_oldest_mon_date( bot.config, use_alt_table=False) else: oldest_mon_date = await queries.get_oldest_mon_date( bot.config, use_alt_table=False) if timespan is None: timespan = list([oldest_mon_date, datetime.now()]) elif "-" in timespan: timespan = list(timespan.split('-')) for i in [0, 1]: timespan[i] = dateparser.parse( timespan[i], languages=[bot.config['language']]) else: timespan = list([ dateparser.parse(timespan, languages=[bot.config['language']]), datetime.now() ]) if timespan[0] < oldest_mon_date: timespan = list([oldest_mon_date, timespan[1]]) footer_text = f"{footer_text}, {(bot.locale['between'])} {timespan[0].strftime(bot.locale['time_format_dhm'])} {bot.locale['and']} {timespan[1].strftime(bot.locale['time_format_dhm'])}" else: if timespan is None: timespan = list([datetime(2010, 1, 1, 0, 0), datetime.now()]) else: loading = "" if "-" in timespan: timespan = list(timespan.split('-')) for i in [0, 1]: timespan[i] = dateparser.parse( timespan[i], languages=[bot.config['language']]) footer_text = f"{(bot.locale['between']).capitalize()} {timespan[0].strftime(bot.locale['time_format_dhm'])} {bot.locale['and']} {timespan[1].strftime(bot.locale['time_format_dhm'])}" else: timespan = list([ dateparser.parse(timespan, languages=[bot.config['language']]), datetime.now() ]) if area[1] == bot.locale['all']: footer_text = f"{(bot.locale['since']).capitalize()} {timespan[0].strftime(bot.locale['time_format_dhm'])}" else: footer_text = f"{footer_text}, {bot.locale['since']} {timespan[0].strftime(bot.locale['time_format_dhm'])}" print(f"@{ctx.author.name} requested {mon.name} stats for area {area[1]}") embed = discord.Embed(title=f"{mon.name}", description=text) embed.set_thumbnail(url=mon.icon) if config['timespan_in_footer']: embed.set_footer( text=f"{loading}", icon_url= "https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif" ) else: embed.set_footer( text=f"{loading}{footer_text}", icon_url= "https://mir-s3-cdn-cf.behance.net/project_modules/disp/c3c4d331234507.564a1d23db8f9.gif" ) message = await ctx.send(embed=embed) alt_shiny_count = 0 alt_shiny_total = 0 alt_scan_numbers = ((0, 0, 0, 0), ) alt_big_numbers = ((0, 0, 0, datetime.now()), ) if bot.config['use_alt_table_for_pokemon']: oldest_mon_date = await queries.get_oldest_mon_date(bot.config) if oldest_mon_date > timespan[0]: print( f"using alt table, because starttime older than oldest mon. starttime: {timespan[0]}, oldest mon: {oldest_mon_date}\n" ) if oldest_mon_date > timespan[1]: alt_timespan = list([timespan[0], timespan[1]]) else: alt_timespan = list([timespan[0], oldest_mon_date]) timespan = list([oldest_mon_date, timespan[1]]) alt_shiny_count = await queries.get_shiny_count(mon.id, area[0], alt_timespan[0], alt_timespan[1], bot.config, use_alt_table=True) alt_shiny_total = await queries.get_shiny_total(mon.id, area[0], alt_timespan[0], alt_timespan[1], bot.config, use_alt_table=True) alt_scan_numbers = await queries.get_scan_numbers( mon.id, area[0], alt_timespan[0], alt_timespan[1], bot.config, use_alt_table=True) alt_big_numbers = await queries.get_big_numbers(mon.id, area[0], alt_timespan[0], alt_timespan[1], bot.config, use_alt_table=True) if alt_big_numbers[0][3] is None: alt_big_numbers = ((alt_big_numbers[0][0], alt_big_numbers[0][1], alt_big_numbers[0][2], oldest_mon_date), ) shiny_count = await queries.get_shiny_count(mon.id, area[0], timespan[0], timespan[1], bot.config) shiny_count = shiny_count + alt_shiny_count if shiny_count > 0: shiny_total = await queries.get_shiny_total(mon.id, area[0], timespan[0], timespan[1], bot.config) shiny_total = shiny_total + alt_shiny_total shiny_odds = int(round((shiny_total / shiny_count), 0)) text = text + f"{bot.locale['shinies']}: **1:{shiny_odds}** ({shiny_count:_}/{shiny_total:_})\n" else: text = text + f"{bot.locale['shinies']}: **0**\n" embed.description = text.replace("_", bot.locale['decimal_comma']) await message.edit(embed=embed) print(f" [1/3] Shiny Data for {mon.name} Stats") scan_numbers = await queries.get_scan_numbers(mon.id, area[0], timespan[0], timespan[1], bot.config) for scanned, hundos, zeros, nineties in scan_numbers: scanned_total = int(scanned) + int(alt_scan_numbers[0][0]) if scanned_total > 0: hundo_count = int(hundos) + int(alt_scan_numbers[0][1]) zero_count = int(zeros) + int(alt_scan_numbers[0][2]) ninety_count = int(nineties) + int(alt_scan_numbers[0][3]) else: hundo_count = 0 zero_count = 0 ninety_count = 0 if hundo_count > 0: hundo_odds = int(round((scanned_total / hundo_count), 0)) text = text + f"{bot.locale['hundos']}: **{hundo_count:_}** (1:{hundo_odds})\n\n" else: text = text + f"{bot.locale['hundos']}: **0/{scanned_total:_}**\n\n" if ninety_count > 0: ninety_odds = round((scanned_total / ninety_count), 0) text = text + f"{bot.locale['90']}: **{ninety_count:_}** (1:{int(ninety_odds)}) | " else: text = text + f"{bot.locale['90']}: **0** | " if zero_count > 0: zero_odds = round((scanned_total / zero_count), 0) text = text + f"{bot.locale['0']}: **{zero_count:_}** (1:{int(zero_odds)})\n" else: text = text + f"{bot.locale['0']}: **0**\n" embed.description = text.replace("_", bot.locale['decimal_comma']) await message.edit(embed=embed) print(f" [2/3] Scan Data for {mon.name} Stats") big_numbers = await queries.get_big_numbers(mon.id, area[0], timespan[0], timespan[1], bot.config) for mons, found, boosted, time in big_numbers: mon_total = int(mons) + int(alt_big_numbers[0][0]) found_count = int(found) + int(alt_big_numbers[0][1]) boosted_count = int(boosted) + int(alt_big_numbers[0][2]) if found_count > 0: if big_numbers[0][3] is None: days = (alt_timespan[1].date() - (alt_big_numbers[0][3]).date()).days elif alt_big_numbers[0][3] < big_numbers[0][3]: days = (timespan[1].date() - (alt_big_numbers[0][3]).date()).days else: days = (timespan[1].date() - (big_numbers[0][3]).date()).days if days < 1: days = 1 mon_odds = int(round((mon_total / found_count), 0)) mon_rate = str(round((found_count / days), 1)).replace(".", bot.locale['decimal_dot']) text = text.replace( f"\n{bot.locale['90']}", f"{bot.locale['rarity']}: **1:{mon_odds}**\n{bot.locale['rate']}: **{mon_rate}/{bot.locale['day']}**\n\n{bot.locale['90']}" ) boosted_odds = str(round((boosted_count / found_count * 100), 1)).replace(".", bot.locale['decimal_dot']) text = text + f"{bot.locale['weatherboost']}: **{boosted_odds}%**\n" scanned_odds = str(round((scanned_total / found_count * 100), 1)).replace(".", bot.locale['decimal_dot']) text = text + f"{bot.locale['scanned']}: **{scanned_odds}%**\n\n" text = text + f"{bot.locale['total_found']}: **{found_count:_}**" else: text = text.replace( f"\n{bot.locale['90']}", f"{bot.locale['rarity']}: **0**\n{bot.locale['rate']}: **0/{bot.locale['day']}**\n\n{bot.locale['90']}" ) text = text + f"{bot.locale['weatherboost']}: **0%**\n{bot.locale['scanned']}: **0**\n\n{bot.locale['total_found']}: **0**" embed.description = text.replace("_", bot.locale['decimal_comma']) embed.set_footer(text=footer_text) await message.edit(embed=embed) print(f" [3/3] Total Data for {mon.name} Stats") print(f"Done with {mon.name} Stats.")