Пример #1
0
    async def r34(self, ctx, tags: str, limit=1):
        """Rule34
        
        Example tags : "gay furry"
        """
        if ctx.channel.is_nsfw():
            if limit > post_limit[0]['post_limit']:
                await ctx.send(over_limit)
            else:
                loop = asyncio.get_event_loop()
                Rule34 = rule34.Rule34(loop)
                totalImages = await Rule34.totalImages(tags)
                if totalImages > 0:
                    if limit > totalImages:
                        ctx.send("Only {} images found".format(totalImages))
                    images = await Rule34.getImages(tags)
                    images = images[:limit]
                    for image in images:
                        embed = discord.Embed(
                            title=tags,
                            #url = 'https://rule34.xxx/index.php?page=post&s=view&id=' + image.id, #wanted to give image source but can't because of damn library
                            color=random.randint(0, 0xffffff))
                        embed.set_footer(text='{}'.format(ctx.author))
                        embed.set_image(url=image.file_url)
                        embed.timestamp = datetime.datetime.utcnow()

                        await ctx.send(embed=embed)
                else:
                    await ctx.send("> No images found")
        else:
            await ctx.send(non_nsfw_channel)
Пример #2
0
 async def searchr34(self, searchterm):
     #r34 api
     import rule34
     loop = asyncio.get_event_loop()
     rule34 = rule34.Rule34(loop)
     url = await rule34.getImageURLS(searchterm)
     try:
         return random.choice(url)
     except TypeError:
         print("[{0}] found nothing".format(st()))
         return 0
Пример #3
0
 async def rule_thirty_four(self, ctx, *, query):
     if ctx.channel.is_nsfw():
         r34 = rule34.Rule34(loop=self.loop)
         msg = await ctx.send(embed=await macro.send(
             f"This might take a couple of seconds, standby..."))
         await asyncio.sleep(1)
         if not await r34.getImageURLS(query):
             return await msg.edit(embed=await macro.error(
                 f"I couldn't find anything for ``{query}``"))
         await msg.edit(embed=await macro.img(
             str(random.choice(await r34.getImageURLS(query)))))
     else:
         await ctx.send(embed=await macro.error(
             f"You must use this command in an NSFW channel."))
Пример #4
0
    async def rule34(self, ctx):
        rule34 = r34.Rule34(self.client.loop)
        query = ctx.message.content[8:]
        urls = await rule34.getImageURLS(query)

        if len(urls) == 0:
            return await ctx.send("Nessun risultato.")
        else:
            choose = randrange(len(urls))

        embed = discord.Embed(
            title="If it exists there is p**n of it. If not, start uploading.",
            url=urls[choose],
            description="No exception")
        embed.set_image(url=urls[choose])

        await ctx.send(embed=embed)
Пример #5
0
 async def cmd_rule_34(self, ctx, *, arg=""):
     await ctx.channel.trigger_typing()
     if await self.check_voted(ctx):
         search = arg.replace(" ", "_")
         r34 = rule34.Rule34(self.bot.loop)
         urls = await r34.getImageURLS(search)
         if urls is None:
             urls = await r34.getImageURLS(arg)
         if urls is not None:
             e = discord.Embed(title=f"Rule 34 {arg}")
             e.set_image(url=random.choice(urls))
             await ctx.send(embed=e)
         else:
             await ctx.send(
                 f"{ctx.author.mention} No Rule 34 results found for {arg}. :pensive:"
             )
     usage.update(ctx)
     return ctx.command.name
Пример #6
0
 async def rule34(self, ctx, *, search):
     '''Rule 34 NSFW'''
     if (ctx.message.channel.is_nsfw()):
         search_tag = helpers.StringManipulator()
         search_tag.build_array(search.lower().split(' '), '_')
         loop = asyncio.get_event_loop()
         r34 = rule34.Rule34(loop=loop)
         images = await r34.getImageURLS(search_tag)
         if (images == None):
             await ctx.send('No results found')
         else:
             image = images[random.randint(0, len(images) - 1)]
             embed = discord.Embed(title='Rule 34: {}'.format(search),
                                   description='',
                                   colour=0x1f0000)
             embed.set_image(url=image)
             embed.set_footer(
                 text='Requested by: {}'.format(ctx.message.author))
             await ctx.send(embed=embed)
     else:
         await ctx.send('You need to be in a NSFW channel to do that.')
Пример #7
0
    async def rule(self, ctx, choices: str = ''):
        """Manda rule34 de https://rule34.xxx"""
        choices = choices.strip()

        loop = asyncio.get_event_loop()
        boke = rule34.Rule34(loop)

        try:
            rule34_posts = await boke.getImages(choices,
                                                singlePage=True,
                                                randomPID=True)
            rule34_url = random.choice(rule34_posts).file_url
        except Exception:
            await ctx.send("No encontré eso")
            return

        print(rule34_url)

        async with aiohttp.ClientSession() as session:
            async with session.get(rule34_url) as resp:
                if resp.status != 200:
                    return await ctx.send('Could not download file...')
                data = io.BytesIO(await resp.read())
                await ctx.send(file=discord.File(data, 'cool_image.png'))
Пример #8
0
def test_async():
    import asyncio
    loop = asyncio.get_event_loop()
    r34 = rule34.Rule34(loop)
    assert (len(loop.run_until_complete(r34.getImages("gay"))) == 100)
Пример #9
0
 async def r34(self, ctx, query: str):
     rule34_instance = rule34.Rule34(loop=asyncio.get_event_loop())
     images = await rule34_instance.getImages(query)
     await ctx.send(choice(images).file_url)
Пример #10
0
def create_r34_bot(loop):
    global r34_bot

    r34_bot = rule34.Rule34(loop)
Пример #11
0
async def main(searchstr, output, threadlimit, creatorID=None, CLI=True):
    try:
        os.mkdir(output)
    except Exception as e:
        print(e)

    print("FULL DEBUG BEGIN")
    r34tag = rtag.r34tags("rule34.xxx")
    originaltime = t.time()
    global threadcounter
    global downloadCounter
    global PVVar
    global SIVar
    global OOVar
    global NCVar
    downloadCounter = 0
    threadcounter = 0

    loop = asyncio.get_event_loop()
    rule34 = r.Rule34(loop)

    sys.stdout.write(
        "\rGrabbing image list: {}            ".format(t.time() -
                                                       originaltime))
    sys.stdout.flush()

    if NCVar.get() == 1:
        searchstr = searchstr + " original*"

    imageList = None

    while imageList == None:
        try:
            imageList = await rule34.getImages(searchstr, singlePage=False)
        except:
            print("\nError in image list, retrying")
            imageList = None

    sys.stdout.write(
        "\rBeginning download threads: {}     ".format(t.time() -
                                                       originaltime))
    sys.stdout.flush()

    count = 1
    for x in imageList:
        if not CLI:
            if PVVar.get() == 0 and SIVar.get() == 0:
                URL = x.file_url
            elif PVVar.get() == 1:
                URL = x.preview_url
            elif SIVar.get() == 1:
                URL = x.sample_url
            else:
                URL = x.file_url
            while (threadcounter >= threadlimit and threadlimit != 0):
                t.sleep(0.1)  # Wait for new thread
            t1 = threading.Thread(target=download,
                                  args=(URL, x.md5, output, x, r34tag,
                                        creatorID, CLI, count))
            t1.start()
        else:
            URL = x.file_url
            while (threadcounter >= threadlimit and threadlimit != 0):
                t.sleep(0.1)  # Wait for new thread
            t1 = threading.Thread(target=downloadLITE,
                                  args=(URL, x.md5, output))
            t1.start()
        threadcounter += 1
        downloadCounter += 1
        count += 1

    sys.stdout.write("\rAll downloading threads running:  [{}]".format(
        " " * threadlimit))
    sys.stdout.flush()

    while (not threadcounter == 0):
        sys.stdout.write("\rAll downloading threads running: [{}>{}]".format(
            "=" * ((threadlimit - threadcounter) - 1), " " * threadcounter))
        sys.stdout.flush()

    print("\nFinished downloading at: {}        ".format(t.time() -
                                                         originaltime))
    print("\n")
    easygui.msgbox("{} has finished downloading".format(searchstr))
Пример #12
0
async def rule34(ctx, arg):
    r34 = ru34.Rule34(bot.loop)
    gallery = await r34.getImageURLS(arg)

    if gallery is None:
        await ctx.send(
            "No results with the search term were found. Note that you need to search with \"\" to search for multiple words. For example: ~rule34 \"touhou reimu\" __φ(..)"
        )
    else:
        r34_embed = discord.Embed(
            description="Image results for the term \"{}\" on Rule34".format(
                arg))
        r34_embed.set_image(url=gallery[0])
        r34_embed.set_thumbnail(url="https://i.imgur.com/Zam0Wwg.png")
        r34_embed.set_footer(text="Results: {}/{}".format(1, len(gallery)))

        sent = await ctx.send(embed=r34_embed)

        async def update_embed(url, cnt):
            updated_embed = discord.Embed(
                description="Image results for the term \"{}\" on Rule34".
                format(arg))
            updated_embed.set_image(url=url)
            updated_embed.set_thumbnail(url="https://i.imgur.com/Zam0Wwg.png")
            updated_embed.set_footer(
                text="Results: {}/{}".format(cnt, len(gallery)))

            await sent.edit(embed=updated_embed)

        reactions = ["⏪", "⬅", "⏹", "➡", "⏩"]
        """
		⏪: go to the first image
		⬅: go to the previous image or the last one if on the first
		⏹: delete the message
		➡: go to the next image or the first one if on the last
		⏩: go to the last image
		"""

        for reaction in reactions:
            await discord.Message.add_reaction(sent, emoji=reaction)

        def check(react, source):
            return source != bot.user and str(react.emoji) in reactions

        current_image = 0

        while True:
            try:
                reacted, user = await bot.wait_for("reaction_add",
                                                   timeout=120.0,
                                                   check=check)
            except asyncio.TimeoutError:
                for emoji in reactions:
                    await discord.Message.remove_reaction(sent,
                                                          emoji=emoji,
                                                          member=bot.user)
                break
            else:
                if reacted.emoji == "⏪":
                    current_image = 0
                    await update_embed(gallery[current_image],
                                       current_image + 1)
                elif reacted.emoji == "⏩":
                    current_image = gallery.index(gallery[-1])
                    await update_embed(gallery[current_image],
                                       current_image + 1)
                elif reacted.emoji == "⏹":
                    await discord.Message.delete(sent)
                    break
                elif reacted.emoji == "⬅":
                    current_image -= 1

                    if current_image < 0:
                        current_image = gallery.index(gallery[-1])
                        await update_embed(gallery[current_image],
                                           current_image + 1)
                    else:
                        await update_embed(gallery[current_image],
                                           current_image + 1)
                elif reacted.emoji == "➡":
                    current_image += 1

                    if current_image > len(gallery) - 1:
                        current_image = 0
                        await update_embed(gallery[current_image],
                                           current_image + 1)
                    else:
                        await update_embed(gallery[current_image],
                                           current_image + 1)
Пример #13
0
import discord
from discord.ext import commands
import random

import asyncio
import rule34

loop = asyncio.get_event_loop()
rule34 = rule34.Rule34(loop)


class Help(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command(name="rule34")
    async def rule(self, ctx, *args):
        if ctx.channel.is_nsfw():
            post = await rule34.getImageURLS(tags="{}".format('+'.join(args)))
            r = random.randint(1, len(post))
            print(post[r])

            embed = discord.Embed(title="Rule34", )
            embed.set_image(url=post[r])

            await ctx.send(embed=embed)
        else:
            await ctx.send(
                "Whoa! You need to use this command in a **NSFW** channel!")

Пример #14
0
 def __init__(self, bot):
     self.bot = bot
     self.images = rule34.Rule34(self.bot.loop)