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

Commit caaed4f

Browse files
authored
Merge pull request #193 from XAOS1502/rewrite
More nsfw
2 parents d9cb9b5 + dc1efe0 commit caaed4f

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

cogs/community/nsfw.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
from urllib.request import Request, urlopen
3131
import json
3232
import io
33+
import safygiphy
3334

3435
class Nsfw:
35-
"""Nsfw commands."""
36+
""" Nsfw commands """
3637
def __init__(self, bot):
3738
self.bot = bot
3839

@@ -44,9 +45,14 @@ async def __local_check(self, ctx):
4445
return False
4546
return True
4647

47-
@commands.command()
48+
@commands.group(invoke_without_command=True)
49+
async def nsfw(self, ctx):
50+
""" Get random lewds from the web """
51+
pass
52+
53+
@nsfw.command()
4854
async def xbooru(self, ctx):
49-
"""Random image from Xbooru"""
55+
""" Random image from Xbooru """
5056
try:
5157
try:
5258
await ctx.message.delete()
@@ -76,6 +82,65 @@ async def xbooru(self, ctx):
7682
except Exception as e:
7783
await ctx.send(f'```{e}```')
7884

85+
@commands.command(aliases=['gelbooru'])
86+
async def gel(self, ctx):
87+
""" Random image from Gelbooru """
88+
try:
89+
try:
90+
await ctx.message.delete()
91+
except discord.Forbidden:
92+
pass
93+
94+
await ctx.channel.trigger_typing()
95+
query = urllib.request.urlopen("http://www.gelbooru.com/index.php?page=post&s=random").read()
96+
soup = bs.BeautifulSoup(query, 'html.parser')
97+
sans = soup.find_all('div', {'class': 'highres-show'})
98+
partial = soup.find(id="image").get("src")
99+
image = partial.replace('//', '/').replace(':/', '://')
100+
101+
em = discord.Embed(colour=discord.Colour(0xed791d))
102+
em.description = f'[Full Size Link*]({image})'
103+
em.set_image(url=image)
104+
em.set_footer(text='* click link at your own risk!')
105+
try:
106+
await ctx.send(embed=em)
107+
except discord.HTTPException:
108+
# em_list = await embedtobox.etb(em)
109+
# for page in em_list:
110+
# await ctx.send(page)
111+
await ctx.send('Unable to send embeds here!')
112+
try:
113+
async with ctx.session.get(image) as resp:
114+
image = await resp.read()
115+
with io.BytesIO(image) as file:
116+
await ctx.send(file=discord.File(file, 'gelbooru.png'))
117+
except discord.HTTPException:
118+
await ctx.send(image)
119+
120+
except Exception as e:
121+
await ctx.send(f'```{e}```')
122+
123+
@nsfw.command()
124+
async def gif(self, ctx, *, tag):
125+
""" Get a random lewd gif
126+
Usage: gif <tag>
127+
Available tags: rule34, nsfw, hentai, tits... """
128+
try:
129+
await ctx.message.delete()
130+
except discord.Forbidden:
131+
pass
132+
g = safygiphy.Giphy()
133+
gif = g.random(tag=tag)
134+
color = await ctx.get_dominant_color(ctx.author.avatar_url)
135+
em = discord.Embed(color=color)
136+
em.set_image(url=str(gif.get('data', {}).get('image_original_url')))
137+
try:
138+
await ctx.send(embed=em)
139+
except discord.HTTPException:
140+
em_list = await embedtobox.etb(em)
141+
for page in em_list:
142+
await ctx.send(page)
143+
79144

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

0 commit comments

Comments
 (0)