Created
April 13, 2017 14:12
-
-
Save PlanetTeamSpeakk/b35ad4dad4dc600730c629a1a037944d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
from __main__ import send_cmd_help | |
import aiohttp | |
from bs4 import BeautifulSoup | |
import random | |
from .utils import checks | |
from cogs.utils.dataIO import dataIO | |
import os | |
class NSFW: | |
"""NSFW commands.""" | |
def __init__(self, bot): | |
self.bot = bot | |
self.settings = dataIO.load_json("data/nsfw/settings.json") | |
@commands.group(pass_context=True) | |
async def nsfw(self, ctx): | |
"""Nsfw Commands""" | |
if ctx.message.channel.id not in self.settings['nsfw_channels']: | |
await self.bot.say("NSFW commands are not allowed in this channel, this can be toggled with {}togglensfw.".format(ctx.prefix)) | |
return | |
if ctx.invoked_subcommand is None: | |
await self.bot.send_cmd_help(ctx) | |
@commands.command(pass_context=True) | |
@checks.admin_or_permissions() | |
async def togglensfw(self, ctx): | |
"""Toggles whether NSFW content should be allowed in this channel or not.""" | |
if ctx.message.channel.id not in self.settings['nsfw_channels']: | |
self.settings['nsfw_channels'].append(ctx.message.channel.id) | |
await self.bot.say("NSFW commands are now enabled in this channel.") | |
else: | |
self.settings['nsfw_channels'].remove(ctx.message.channel.id) | |
await self.bot.say("NSFW commands are now disabled in this channel.") | |
dataIO.save_json("data/nsfw/settings.json", self.settings) | |
@nsfw.command(pass_context=True) | |
async def yandere(self, ctx): | |
"""Shows a random image from Yandere""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("https://yande.re/post/random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="highres").get("href") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def konachan(self, ctx): | |
"""Shows a random image from Konachan""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("https://konachan.com/post/random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="highres").get("href") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def e621(self, ctx): | |
"""Shows a random image from e621""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("https://e621.net/post/random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="highres").get("href") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def rule34(self, ctx): | |
"""Shows a random image from Rule34""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://rule34.xxx/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say('http:' + image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def danbooru(self, ctx): | |
"""Shows a random image from Danbooru""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://danbooru.donmai.us/posts/random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say('http://danbooru.donmai.us' + image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def gelbooru(self, ctx): | |
"""Shows a random image from Gelbooru""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://www.gelbooru.com/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def tbib(self, ctx): | |
"""Shows a random image from TBib""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://www.tbib.org/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say("http:" + image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def xbooru(self, ctx): | |
"""Shows a random image from Xbooru""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://xbooru.com/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def furrybooru(self, ctx): | |
"""Shows a random image from Furrybooru""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://furry.booru.org/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def drunkenpumken(self, ctx): | |
"""Shows a random image from DrunkenPumken""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("http://drunkenpumken.booru.org/index.php?page=post&s=random") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def lolibooru(self, ctx): | |
"""Shows a random image from Lolibooru""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
query = ("https://lolibooru.moe/post/random/") | |
page = await aiohttp.get(query) | |
page = await page.text() | |
soup = BeautifulSoup(page, 'html.parser') | |
image = soup.find(id="image").get("src") | |
image = image.replace(' ','%20') | |
await self.bot.say(image) | |
except Exception as e: | |
await self.bot.say(":x: **Error:** `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def ysearch(self, ctx, *tags: str): | |
"""Search Yandere With A Tag""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
if tags == (): | |
await self.bot.say(":warning: Tags are missing.") | |
else: | |
try: | |
tags = ("+").join(tags) | |
query = ("https://yande.re/post.json?limit=42&tags=" + tags) | |
page = await aiohttp.get(query) | |
json = await page.json() | |
if json != []: | |
await self.bot.say(random.choice(json)['jpeg_url']) | |
else: | |
await self.bot.say(":warning: Yande.re has no images for requested tags.") | |
except Exception as e: | |
await self.bot.say(":x: `{}`".format(e)) | |
@nsfw.command(pass_context=True) | |
async def boobs(self, ctx): | |
"""Shows some boobs.""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
search = ("http://api.oboobs.ru/boobs/{}".format(random.randint(0, 10394))) | |
async with aiohttp.get(search) as r: | |
result = await r.json() | |
boob = random.choice(result) | |
boob = "http://media.oboobs.ru/{}".format(boob["preview"]) | |
except Exception as e: | |
await self.bot.say("{} ` Error getting results.`".format(ctx.message.author.mention)) | |
return | |
await self.bot.say(boob) | |
@nsfw.command(pass_context=True) | |
async def ass(self, ctx): | |
"""Shows some ass.""" | |
if ctx.message.channel.id in self.settings['nsfw_channels']: | |
try: | |
search = ("http://api.obutts.ru/butts/{}".format(random.randint(0, 4378))) | |
async with aiohttp.get(search) as r: | |
result = await r.json() | |
butt = random.choice(result) | |
butt = "http://media.obutts.ru/{}".format(butt["preview"]) | |
except Exception as e: | |
await self.bot.say("{} ` Error getting results.`".format(ctx.message.author.mention)) | |
return | |
await self.bot.say(butt) | |
def check_folders(): | |
if not os.path.exists("data/nsfw"): | |
print("Creating data/nsfw folder...") | |
os.makedirs("data/nsfw") | |
def check_files(): | |
if not os.path.exists("data/nsfw/settings.json"): | |
print("Creating data/nsfw/settings.json file...") | |
dataIO.save_json("data/nsfw/settings.json", {'nsfw_channels': []}) | |
def setup(bot): | |
check_folders() | |
check_files() | |
bot.add_cog(NSFW(bot)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to run it but, I'm having a problem with the "from main import send_cmd_help" ImportError. I dont know whats the problem. would appreciate the help!