async def hentai(ctx): if (ctx.channel.is_nsfw() != 1): await ctx.send("No NSFW post in non-NSFW channels!!! ¯\_(ツ)_/¯") return try: nhentai = NHentai() Doujin = nhentai.get_random() page = random.randrange(0, Doujin.total_pages) await ctx.send(Doujin.images[page]) except: await ctx.send("Toooo spicyyyy!!! ¬‿¬")
async def NH(ctx, Code, Option="get"): async def get_doujin(msg, Code): Doujin = NH._get_doujin(str(Code)) embD = discord.Embed(title=f"{Doujin.title}", description=f"{Doujin.id}", color=0xFF69B4) embD.add_field(name="Characters", value=f"{LtoS(Doujin.characters)}", inline=True) embD.add_field(name="Tags", value=f"{LtoS(Doujin.tags)}", inline=False) embD.add_field(name="Languages", value=f"{LtoS(Doujin.languages)}", inline=False) embD.add_field(name="Artists", value=f"{LtoS(Doujin.artists)}", inline=False) embD.add_field(name="Total Pages", value=f"{Doujin.total_pages}", inline=False) embD.set_footer(icon_url=Takodachi, text=f"Cultured Tako") embD.set_thumbnail(url=f"{Doujin.images[0]}") await msg.edit(embed=embD) option = Option.lower() NH = NHentai() with open(r"Data\Emoji.json", encoding="utf8") as F: JF = F.read() Json = json.loads(JF) GET = Json["default"] MEDIA = GET["Media"] embD = discord.Embed(title="Please wait.", description=f"Poyoyo is currently fetching {Code} doujin...", color=0xFF69B4) embD.set_footer(icon_url=Takodachi, text=f"Cultured Tako") EMSG = await ctx.send(embed=embD) if option == "get": await get_doujin(EMSG, Code) elif option == "open": Doujin = NH._get_doujin(str(Code)) embD = discord.Embed(title=f"{Doujin.title}", description=f"{Doujin.id}", color=0xFF69B4) embD.add_field(name="Characters", value=f"{LtoS(Doujin.characters)}", inline=True) #embD.add_field(name="Tags", value=f"{LtoS(Doujin.tags)}", inline=False) embD.add_field(name="Languages", value=f"{LtoS(Doujin.languages)}", inline=False) embD.add_field(name="Artists", value=f"{LtoS(Doujin.artists)}", inline=False) embD.set_footer(icon_url=Takodachi, text=f"Cultured Tako") embD.set_image(url=f"{Doujin.images[0]}") embD.add_field(name="Total Pages", value=f"{Doujin.total_pages}", inline=False) Nn = MEDIA["Next"] Pp = MEDIA["Prev"] embD.add_field(name="Controls", value=f"{Pp} prev, {Nn} next", inline=False) await EMSG.edit(embed=embD) await EMSG.add_reaction(str(MEDIA["Prev"])) await EMSG.add_reaction(str(MEDIA["Next"])) with open(r"Data\NHdata.json", "r") as JF: Jfile = JF.read() JSON = json.loads(Jfile) pages = {} count = 1 for i in Doujin.images: pages[count] = i count += 1 JSON[EMSG.id] = {"pages":pages, "current":1, "channel":ctx.channel.id, "title":f"{Doujin.title}", "code":f"{Doujin.id}"} with open(r"Data\NHdata.json", "w") as JF: json.dump(JSON, JF, indent=2)
async def search(ctx, *, term): if (ctx.channel.is_nsfw() != 1): await ctx.send("No NSFW post in non-NSFW channels!!! ¯\_(ツ)_/¯") return try: nhentai = NHentai() SearchPage = nhentai.search(query=term, sort='popular', page=1) # await ctx.send(SearchPage.doujins[0].id) Doujin = nhentai._get_doujin(id=SearchPage.doujins[0].id) page = random.randrange(0, Doujin.total_pages) await ctx.send(Doujin.images[page]) except: await ctx.send("Toooo spicyyyy!!! ¬‿¬")
class cat_nhentai(commands.Cog, name="NHentai Commands"): """Documentation""" def __init__(self, bot): self.bot = bot self.nhentai = NHentai() @commands.command(name="nh_find", help="find doujin from nhentai") async def nh_find(self, ctx, arg): print( f"[{datetime.now()}] Command Issued: nh_find\n - message: {ctx.message.content}\n - debug: {ctx.message}" ) if arg.isnumeric(): await self.nh_display(ctx, arg) return SearchPage = self.nhentai.search(query=arg, sort='popular', page=1) count = 3 if SearchPage.total_results > 3 else SearchPage.total_results if count == 0: await ctx.send(f"no results were found!") return embeds = [] * count i = 0 while i < count: await self.nh_display(ctx, SearchPage.doujins[i].id) i += 1 @commands.command(name="nh_display", help="display doujin from nhentai") async def nh_display(self, ctx, arg): print( f"[{datetime.now()}] Command Issued: nh_display\n - message: {ctx.message.content}\n - debug: {ctx.message}" ) Doujin = self.nhentai._get_doujin(id=arg) if Doujin is None: await ctx.send(f"no results were found!") return tags = "" for tag in Doujin.tags: tags += f"{tag} " embed = discord.Embed( title=Doujin.title, description=Doujin.secondary_title, color=discord.Color.gold(), url=f"https://nhentai.net/g/{arg}", ) embed.set_image(url=Doujin.images[0]) embed.add_field(name="Tags", value=tags, inline=True) embed.add_field(name="Pages", value=Doujin.total_pages, inline=False) embed.set_footer(text=f"Magic code: {arg}") await ctx.send(embed=embed)
def nhentai_random(): nhentai = NHentai() result = nhentai.get_random() return result
def nhentai_search(keyword): nhentai = NHentai() SearchPage = nhentai.search(query=keyword, sort='popular', page=1) result = SearchPage.doujins[0] return result
# This is a simple program that uses the NHentai API to get random doujins # dev: Zero Meia#8828 from NHentai import NHentai from os import system, name from time import sleep from colorama import init from termcolor import colored from random import randrange init() nhentai = NHentai() def clear(): if name == 'nt': _ = system('cls') else: _ = system('clear') def title_render(sub, link): clear() print(colored(f'Last Link: {link}\n', 'magenta')) print(colored('██╗ ██╗███████╗███╗ ██╗████████╗ █████╗ ██╗', 'cyan')) print(colored('██║ ██║██╔════╝████╗ ██║╚══██╔══╝██╔══██╗██║', 'cyan')) print(colored('███████║█████╗ ██╔██╗██║ ██║ ███████║██║', 'cyan')) print(colored('██╔══██║██╔══╝ ██║╚████║ ██║ ██╔══██║██║', 'cyan')) print(colored('██║ ██║███████╗██║ ╚███║ ██║ ██║ ██║██║', 'cyan')) print(
def __init__(self): self.NH = NHentai()
class NH(API): calls_minute = None calls_second = None last_api_call = None def __init__(self): self.NH = NHentai() @classmethod def initialize(cls): super().__init__(2, 30) def search(self, query): super()._check_rate_seconds() super()._check_rate_minutes() NH.calls_second += 1 NH.calls_minute += 1 NH.last_api_call = datetime.now() cleanquery = query tldfilter = [".us", ".com"] for x in tldfilter: cleanquery = cleanquery.replace(x, "") search_obj: SearchPage = self.NH.search(query=cleanquery, sort="popular", page=1) return [x.__dict__ for x in search_obj.doujins] def manga(self, id, title): super()._check_rate_seconds() super()._check_rate_minutes() NH.calls_second += 1 NH.calls_minute += 1 NH.last_api_call = datetime.now() book = re.sub(r"\[([^]]+)\]", "", title) book = re.findall(r"\(([^)]+)\)", book) doujin = self.NH._get_doujin(id) cleaned = re.sub(r"\[([^]]+)\]", "", str(title)) cleaned = re.sub(r"\(([^)]+)\)", "", cleaned) series_title = cleaned series_title_eng = None series_title_jap = None status = "Finished" type = "Doujinshi" description = None page_count = doujin.total_pages url = r"https://nhentai.net/g/" + str(id) + r"/" publish_date = None genres = doujin.tags artists = [x.title() for x in doujin.artists] staff = {"story": artists, "art": artists} if book is True: serializations = book[0] else: serializations = None dct = { "source": "NHentai", "id": id, "series_title": series_title, "series_title_eng": series_title_eng, "series_title_jap": series_title_jap, "status": status, "type": type, "description": description, "page_count": page_count, "url": url, "publish_date": publish_date, "genres": genres, "staff": staff, "serializations": serializations } return dct
def make_embed(cont:dict): embed = discord.Embed( colour=discord.Colour.green(), title=cont['title'], url=f"https://nhentai.net/g/{cont['id']}" ) embed.set_thumbnail(url=cont['images'][0]) embed.set_image(url=cont['images'][0]) embed.add_field(name="ID", value=cont['id'], inline=True) embed.add_field(name="Pages", value=cont['pages'][0], inline=True) embed.add_field(name="Artists", value=", ".join(cont['artists'])) embed.add_field(name="Tags", value=", ".join(cont['tags'])) embed.add_field(name="Languages", value=", ".join(cont['languages'])) return embed nh = NHentai() TOKEN = "NzY0MTY2MzY1NTM1Nzk3Mjgw.X4CTYw.w0sP1zzaYRzcusD0ts8yRk3SjcQ" def get_prefix(bot, msg): with open("prefixes.json", 'r') as fp: prefixes = json.load(fp) gid = msg.guild.id this_prefix = prefixes.get(str(gid), ">") return this_prefix intents = discord.Intents.default() intents.members = True bot = commands.Bot(command_prefix=get_prefix, intents=intents) @bot.command()
def __init__(self, bot): self.bot = bot self.nhentai = NHentai()