async def randomnuke(self, ctx, items: int): """ Get random nuke codes for shits and giggles. (Max limit is configurable) """ message = await ctx.send(f"Gathering [{items}] nuke code/s...") if 1 <= items <= self.config["max_limit"]: nukes = (str(Utils.get_random_id()) for i in range(items)) await message.edit(content=f'Here you go: `{", ".join(nukes)}`') else: await message.edit(content=f'Cannot generate [{items}] amount of nuke codes.')
async def rnd(self, ctx: commands.Context): """Random one""" doujin = Hentai(Utils.get_random_id()) embed_list = [] for i in doujin.image_urls: embed = Embed.default(ctx) embed.title = doujin.title(Format.Pretty) embed.set_image(url=i) embed_list.append(embed) await menus.MenuPages( source=EmbedListMenu(embed_list), clear_reactions_after=True, ).start(ctx=ctx, wait=False)
async def nhr(message, *tags): if not tags: random = str(Utils.get_random_id()) base_url = 'https://nhentai.net/g/' final_url = base_url + random + "/" await message.channel.send(final_url) else: print("Entered else statement") query_tags = "" fTags = "" n = 0 language = "language:english" commandHelp = "" for tag in tags: if (tag == "-help") or (tag == "-h") or (tag == "h") or (tag == "help"): commandHelp = "Use quaisquer combinação de tags. Ex: *%snhr yuri pantyhose*\nTambém pode usar - para remover uma tag. Ex: *%snhr glasses -netorare*" % ( prefix, prefix) await message.channel.send(commandHelp) break #enables multiple language support (to be defined in if statement) # if tag == "translated" or tag == "english": # language = "language:" + tag # else: query_tags += tag + " " if query_tags != "": fTags = "tag:" + query_tags query = fTags + language doujins = Utils.search_by_query(query, sort=Sort.PopularToday) selected = randint(0, len(doujins)) for doujin in doujins: if (commandHelp != ""): break if (n == selected): base_url = 'https://nhentai.net/g/' final_url = base_url + str(doujin.id) + "/" print(doujin.title(Format.Pretty)) print(final_url) await message.channel.send(final_url) n += 1
async def random(self, ctx: commands.Context): '''finds random doujin''' await self.nhentai(ctx, Utils.get_random_id())
async def random_id(self, ctx): await self.lookup_id(ctx, id=Utils.get_random_id(make_request=True))
async def randomsauce(self, ctx): """ Get a random sauce for shits and giggles """ await ctx.send("Getting a random sauce...") await self.sauce(ctx, nuke_code=str(Utils.get_random_id()))
async def _(event): if event.fwd_from: return await event.edit("`Searching for doujin...`") input_str = event.pattern_match.group(1) code = input_str if "nhentai" in input_str: link_regex = r"(?:https?://)?(?:www\.)?nhentai\.net/g/(\d+)" match = re.match(link_regex, input_str) code = match.group(1) if input_str == "random": code = Utils.get_random_id() try: doujin = Hentai(code) except BaseException as n_e: if "404" in str(n_e): return await event.edit(f"No doujin found for `{code}`") return await event.edit(f"**ERROR :** `{n_e}`") msg = "" imgs = "" for url in doujin.image_urls: imgs += f"<img src='{url}'/>" imgs = f"‍ {imgs}" title = doujin.title() graph_link = post_to_telegraph(title, imgs) msg += f"[{title}]({graph_link})" msg += f"\n**Source :**\n[{code}]({doujin.url})" if doujin.parody: msg += "\n**Parodies :**" parodies = [] for parody in doujin.parody: parodies.append("#" + parody.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(parodies)) if doujin.character: msg += "\n**Characters :**" charas = [] for chara in doujin.character: charas.append("#" + chara.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(charas)) if doujin.tag: msg += "\n**Tags :**" tags = [] for tag in doujin.tag: tags.append("#" + tag.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(tags)) if doujin.artist: msg += "\n**Artists :**" artists = [] for artist in doujin.artist: artists.append("#" + artist.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(artists)) if doujin.language: msg += "\n**Languages :**" languages = [] for language in doujin.language: languages.append("#" + language.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(languages)) if doujin.category: msg += "\n**Categories :**" categories = [] for category in doujin.category: categories.append( "#" + category.name.replace(" ", "_").replace("-", "_")) msg += "\n" + " ".join(natsorted(categories)) msg += f"\n**Pages :**\n{doujin.num_pages}" await event.edit(msg, link_preview=True)
def test_random_id(self): random_id = Utils.get_random_id() response = requests.get(urljoin(Hentai._URL, str(random_id))) self.assertTrue( response.ok, msg=f"Failing ID: {random_id}. Failing URL: {response.url}")
def test_random_id(self): print("Setting make_request flag to 'False'") random_id = Utils.get_random_id(make_request=False) response = requests.get(urljoin(Hentai._URL, str(random_id))) self.assertTrue(response.ok, msg=f"Failing ID: {random_id}. Failing URL: {response.url}")