|
| 1 | +""" |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) 2017 Grok's naughty dev XAOS |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | +import discord |
| 26 | +from discord.ext import commands |
| 27 | +import bs4 as bs |
| 28 | +import urllib.request |
| 29 | +from bs4 import BeautifulSoup |
| 30 | +from urllib.request import Request, urlopen |
| 31 | +import json |
| 32 | +import io |
| 33 | +import safygiphy |
| 34 | +from ext import embed2box |
| 35 | + |
| 36 | +class Nsfw: |
| 37 | + """ Nsfw commands """ |
| 38 | + def __init__(self, bot): |
| 39 | + self.bot = bot |
| 40 | + |
| 41 | + async def __local_check(self, ctx): |
| 42 | + if not ctx.channel.is_nsfw(): |
| 43 | + return False |
| 44 | + git = self.bot.get_cog('Git') |
| 45 | + if not await git.starred('verixx/selfbot.py'): |
| 46 | + return False |
| 47 | + return True |
| 48 | + |
| 49 | + @commands.group(invoke_without_command=True) |
| 50 | + async def nsfw(self, ctx): |
| 51 | + """ Get random lewds from the web """ |
| 52 | + pass |
| 53 | + |
| 54 | + @nsfw.command() |
| 55 | + async def xbooru(self, ctx): |
| 56 | + """ Random image from Xbooru """ |
| 57 | + try: |
| 58 | + try: |
| 59 | + await ctx.message.delete() |
| 60 | + except discord.Forbidden: |
| 61 | + pass |
| 62 | + await ctx.channel.trigger_typing() |
| 63 | + query = urllib.request.urlopen("http://xbooru.com/index.php?page=post&s=random").read() |
| 64 | + soup = bs.BeautifulSoup(query, 'html.parser') |
| 65 | + image = soup.find(id="image").get("src") |
| 66 | + last = str(image.split('?')[-2]).replace('//', '/').replace(':/', '://') |
| 67 | + em = discord.Embed(colour=discord.Colour(0xed791d)) |
| 68 | + em.description = f'[Full Size Link*]({last})' |
| 69 | + em.set_image(url=last) |
| 70 | + em.set_footer(text='* click link at your own risk!') |
| 71 | + try: |
| 72 | + await ctx.send(embed=em) |
| 73 | + except discord.HTTPException: |
| 74 | + await ctx.send('Unable to send embeds here!') |
| 75 | + try: |
| 76 | + async with ctx.session.get(image) as resp: |
| 77 | + image = await resp.read() |
| 78 | + with io.BytesIO(image) as file: |
| 79 | + await ctx.send(file=discord.File(file, 'xbooru.png')) |
| 80 | + except discord.HTTPException: |
| 81 | + await ctx.send(image) |
| 82 | + |
| 83 | + except Exception as e: |
| 84 | + await ctx.send(f'```{e}```') |
| 85 | + |
| 86 | + @commands.command(aliases=['gelbooru']) |
| 87 | + async def gel(self, ctx): |
| 88 | + """ Random image from Gelbooru """ |
| 89 | + try: |
| 90 | + try: |
| 91 | + await ctx.message.delete() |
| 92 | + except discord.Forbidden: |
| 93 | + pass |
| 94 | + |
| 95 | + await ctx.channel.trigger_typing() |
| 96 | + query = urllib.request.urlopen("http://www.gelbooru.com/index.php?page=post&s=random").read() |
| 97 | + soup = bs.BeautifulSoup(query, 'html.parser') |
| 98 | + sans = soup.find_all('div', {'class': 'highres-show'}) |
| 99 | + partial = soup.find(id="image").get("src") |
| 100 | + image = partial.replace('//', '/').replace(':/', '://') |
| 101 | + |
| 102 | + em = discord.Embed(colour=discord.Colour(0xed791d)) |
| 103 | + em.description = f'[Full Size Link*]({image})' |
| 104 | + em.set_image(url=image) |
| 105 | + em.set_footer(text='* click link at your own risk!') |
| 106 | + try: |
| 107 | + await ctx.send(embed=em) |
| 108 | + except discord.HTTPException: |
| 109 | + # em_list = await embedtobox.etb(em) |
| 110 | + # for page in em_list: |
| 111 | + # await ctx.send(page) |
| 112 | + await ctx.send('Unable to send embeds here!') |
| 113 | + try: |
| 114 | + async with ctx.session.get(image) as resp: |
| 115 | + image = await resp.read() |
| 116 | + with io.BytesIO(image) as file: |
| 117 | + await ctx.send(file=discord.File(file, 'gelbooru.png')) |
| 118 | + except discord.HTTPException: |
| 119 | + await ctx.send(image) |
| 120 | + |
| 121 | + except Exception as e: |
| 122 | + await ctx.send(f'```{e}```') |
| 123 | + |
| 124 | + @nsfw.command() |
| 125 | + async def gif(self, ctx, *, tag): |
| 126 | + """ Get a random lewd gif |
| 127 | + Usage: gif <tag> |
| 128 | + Available tags: rule34, nsfw, hentai, tits... """ |
| 129 | + try: |
| 130 | + await ctx.message.delete() |
| 131 | + except discord.Forbidden: |
| 132 | + pass |
| 133 | + g = safygiphy.Giphy() |
| 134 | + gif = g.random(tag=tag) |
| 135 | + color = await ctx.get_dominant_color(ctx.author.avatar_url) |
| 136 | + em = discord.Embed(color=color) |
| 137 | + em.set_image(url=str(gif.get('data', {}).get('image_original_url'))) |
| 138 | + try: |
| 139 | + await ctx.send(embed=em) |
| 140 | + except discord.HTTPException: |
| 141 | + em_list = await embedtobox.etb(em) |
| 142 | + for page in em_list: |
| 143 | + await ctx.send(page) |
| 144 | + |
| 145 | + |
| 146 | +def setup(bot): |
| 147 | + bot.add_cog(Nsfw(bot)) |
0 commit comments