async def cheat_spawn(self, ctx: Context, waifu_id: int): waifu_commands = self.bot.get_cog("Waifu Commands") response = await waifu_commands.get_waifu_by_id(waifu_id) pictures = await waifu_commands.get_mal_waifu_pics(waifu_id) waifu_manager.prepare_waifu_spawn(response, pictures['pictures']) embed = waifu_manager.spawn_waifu() message = await ctx.send(embed=embed) waifu_manager.set_claim_message(message) timers.set_waifu_claim_timer()
async def random_waifu(self, channel): DEFAULT_IMAGE_URL = "https://cdn.myanimelist.net/img/sp/icon/apple-touch-icon-256.png" if random.randint(0, 99) < 30: comicvine = True else: comicvine = False if waifu_manager.current_waifu_spawn is not None: if timers.get_time() - timers.get_waifu_claim_timer( ) < WAIFU_CLAIM_DELTA: return await waifu_manager.skip_waifu() claim_message = waifu_manager.claim_message old_embed = claim_message.embeds[0] desc = old_embed.description desc += "\nClaimed by nobody. So sad." embed = discord.Embed(title=old_embed.title, description=desc, color=old_embed.color) await claim_message.edit(embed=embed) if waifu_manager.is_prepared: response = waifu_manager.spawn_waifu() message = await channel.send(embed=response) waifu_manager.set_claim_message(message) timers.set_waifu_claim_timer() while True: if comicvine: response = await self.get_random_comic_char() if response is not None: if not response['results'][0]['image'][ 'medium_url'].endswith('blank.png'): waifu_manager.prepare_comic_spawn(response) return else: char_id = random.randint(1, 99999) response = await self.get_waifu_by_id(char_id) if response is not None: if response['image_url'] != DEFAULT_IMAGE_URL and\ response['member_favorites'] >= 5: pictures = await self.get_mal_waifu_pics( response['mal_id']) waifu_manager.prepare_waifu_spawn( response, pictures['pictures']) return await asyncio.sleep(3)
async def random_waifu(self, channel): if random.randint(0, 99) < 30: comicvine = True else: comicvine = False if waifu_manager.current_waifu_spawn is not None: if timers.get_time() - timers.get_waifu_claim_timer( ) < WAIFU_CLAIM_DELTA: return await waifu_manager.skip_waifu() claim_message = waifu_manager.claim_message old_embed = claim_message.embeds[0] desc = old_embed.description desc += "\nClaimed by nobody. So sad." embed = discord.Embed(title=old_embed.title, description=desc, color=old_embed.color) await claim_message.edit(embed=embed) if waifu_manager.is_prepared: response = waifu_manager.spawn_waifu() message = await channel.send(embed=response) waifu_manager.set_claim_message(message) timers.set_waifu_claim_timer() while True: if comicvine: response = await self.get_random_comic_char() if response is not None: if self.is_comic_waifu_valid(response): waifu_manager.prepare_comic_spawn(response) return else: response = await self.get_random_mal_waifu() if response is not None: if self.is_mal_waifu_valid(response): pictures = await self.get_mal_waifu_pics( response['mal_id']) waifu_manager.prepare_waifu_spawn( response, pictures['pictures']) return await asyncio.sleep(3)
async def cheat_comic(self, ctx: Context, *args: str): waifu_commands = self.bot.get_cog("Waifu Commands") args = list(args) author = ctx.message.author r_map = { 0: "0⃣", 1: "1⃣", 2: "2⃣", 3: "3⃣", 4: "4⃣", 5: "5⃣", "cancel": "⏹" } name = ' '.join(args) response = await waifu_commands.find_comicvine_char(name) embed = discord.Embed(title=name.capitalize(), color=0x09d3e3) for i, character in enumerate(response['results']): embed.add_field(name=f"{i+1}: **{character['name']}**", value=f"Real name: {character['real_name']}", inline=False) msg = await ctx.send(embed=embed) for i in range(len(response['results'])): await msg.add_reaction(r_map[i + 1]) await msg.add_reaction("⏹") def check(reaction, user): e = str(reaction.emoji) return e.startswith(('1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '⏹')) and user.id == author.id\ and reaction.message.id == msg.id try: reaction, user = await self.bot.wait_for('reaction_add', check=check, timeout=60) except asyncio.TimeoutError: await msg.delete() await ctx.send("You didn't pick in time, too bad.") return await msg.delete() choice = None for k, v in r_map.items(): if v == str(reaction.emoji): choice = k break if choice == "cancel": return url = response['results'][choice - 1]['api_detail_url'] session = http_session.get_connection() params = { 'api_key': COMICVINE_API_KEY, 'format': 'json', 'field_list': 'name,real_name,deck,image,site_detail_url,id' } async with session.get(url, params=params) as resp: response = await resp.json() waifu_manager.prepare_comic_spawn(response) embed = waifu_manager.spawn_waifu() message = await ctx.send(embed=embed) waifu_manager.set_claim_message(message) timers.set_waifu_claim_timer()