Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

More nsfw #193

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions cogs/community/nsfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
from urllib.request import Request, urlopen
import json
import io
import safygiphy

class Nsfw:
"""Nsfw commands."""
""" Nsfw commands """
def __init__(self, bot):
self.bot = bot

Expand All @@ -44,9 +45,14 @@ async def __local_check(self, ctx):
return False
return True

@commands.command()
@commands.group(invoke_without_command=True)
async def nsfw(self, ctx):
""" Get random lewds from the web """
pass

@nsfw.command()
async def xbooru(self, ctx):
"""Random image from Xbooru"""
""" Random image from Xbooru """
try:
try:
await ctx.message.delete()
Expand Down Expand Up @@ -76,6 +82,65 @@ async def xbooru(self, ctx):
except Exception as e:
await ctx.send(f'```{e}```')

@commands.command(aliases=['gelbooru'])
async def gel(self, ctx):
""" Random image from Gelbooru """
try:
try:
await ctx.message.delete()
except discord.Forbidden:
pass

await ctx.channel.trigger_typing()
query = urllib.request.urlopen("http://www.gelbooru.com/index.php?page=post&s=random").read()
soup = bs.BeautifulSoup(query, 'html.parser')
sans = soup.find_all('div', {'class': 'highres-show'})
partial = soup.find(id="image").get("src")
image = partial.replace('//', '/').replace(':/', '://')

em = discord.Embed(colour=discord.Colour(0xed791d))
em.description = f'[Full Size Link*]({image})'
em.set_image(url=image)
em.set_footer(text='* click link at your own risk!')
try:
await ctx.send(embed=em)
except discord.HTTPException:
# em_list = await embedtobox.etb(em)
# for page in em_list:
# await ctx.send(page)
await ctx.send('Unable to send embeds here!')
try:
async with ctx.session.get(image) as resp:
image = await resp.read()
with io.BytesIO(image) as file:
await ctx.send(file=discord.File(file, 'gelbooru.png'))
except discord.HTTPException:
await ctx.send(image)

except Exception as e:
await ctx.send(f'```{e}```')

@nsfw.command()
async def gif(self, ctx, *, tag):
""" Get a random lewd gif
Usage: gif <tag>
Available tags: rule34, nsfw, hentai, tits... """
try:
await ctx.message.delete()
except discord.Forbidden:
pass
g = safygiphy.Giphy()
gif = g.random(tag=tag)
color = await ctx.get_dominant_color(ctx.author.avatar_url)
em = discord.Embed(color=color)
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
try:
await ctx.send(embed=em)
except discord.HTTPException:
em_list = await embedtobox.etb(em)
for page in em_list:
await ctx.send(page)


def setup(bot):
bot.add_cog(Nsfw(bot))