This repository was archived by the owner on Jul 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathnsfw.py
170 lines (149 loc) · 6.11 KB
/
nsfw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""
MIT License
Copyright (c) 2017 Grok's naughty dev XAOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import discord
from discord.ext import commands
import bs4 as bs
import urllib.request
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import json
import io
import safygiphy
from ext import embedtobox
class Nsfw:
""" Nsfw commands """
def __init__(self, bot):
self.bot = bot
async def __local_check(self, ctx):
if not ctx.channel.is_nsfw():
return False
git = self.bot.get_cog('Git')
if not await git.starred('verixx/selfbot.py'):
return False
return True
class Dick:
def init(self, bot):
self.bot = bot
def dick_size(self, id):
s = 0
while id:
s += id % 10
id //= 10
return (s%10) * 2
@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 """
try:
try:
await ctx.message.delete()
except discord.Forbidden:
pass
await ctx.channel.trigger_typing()
query = urllib.request.urlopen("http://xbooru.com/index.php?page=post&s=random").read()
soup = bs.BeautifulSoup(query, 'html.parser')
image = soup.find(id="image").get("src")
last = str(image.split('?')[-2]).replace('//', '/').replace(':/', '://')
em = discord.Embed(colour=discord.Colour(0xed791d))
em.description = f'[Full Size Link*]({last})'
em.set_image(url=last)
em.set_footer(text='* click link at your own risk!')
try:
await ctx.send(embed=em)
except discord.HTTPException:
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, 'xbooru.png'))
except discord.HTTPException:
await ctx.send(image)
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}```')
@commands.command(pass_context=True)
async def dick(self, ctx, mention=""):
"""How big are you?"""
id_regex = re.compile('<@!?(\d+)>')
ids = id_regex.findall(ctx.message.content)
if len(ids) > 0:
for member in ids:
await ctx.send(' <@{}> Size: 8{}D'.format(member, self.dick_size(int(member)) * '='))
else:
await ctx.send(' <@{}> Size: 8{}D'.format(str(ctx.message.author.id), self.dick_size(ctx.message.author.id) * '='))
@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))