30
30
from urllib .request import Request , urlopen
31
31
import json
32
32
import io
33
+ import safygiphy
33
34
34
35
class Nsfw :
35
- """Nsfw commands. """
36
+ """ Nsfw commands """
36
37
def __init__ (self , bot ):
37
38
self .bot = bot
38
39
@@ -44,9 +45,14 @@ async def __local_check(self, ctx):
44
45
return False
45
46
return True
46
47
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 ()
48
54
async def xbooru (self , ctx ):
49
- """Random image from Xbooru"""
55
+ """ Random image from Xbooru """
50
56
try :
51
57
try :
52
58
await ctx .message .delete ()
@@ -76,6 +82,65 @@ async def xbooru(self, ctx):
76
82
except Exception as e :
77
83
await ctx .send (f'```{ e } ```' )
78
84
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
+
79
144
80
145
def setup (bot ):
81
146
bot .add_cog (Nsfw (bot ))
0 commit comments