Browse Source

added channel checking for nsfw commands so the whitelist now works.

tags/v1.3.0
roxie 6 years ago
parent
commit
2b600a74bf
3 changed files with 39 additions and 7 deletions
  1. +13
    -1
      checks.py
  2. +7
    -5
      cogs/reddit.py
  3. +19
    -1
      cogs/settings.py

+ 13
- 1
checks.py View File

@@ -30,8 +30,20 @@ def is_admin_or_mod():
return False
return commands.check(predicate)

def nsfw_predicate(ctx):
nsfw = ServerConfig().load_config()[ctx.message.server.id]["nsfw"]
if not nsfw["channels"] and nsfw["enabled"]:
return nsfw["enabled"] == 1
elif nsfw["enabled"] and nsfw["channels"]:
return ctx.message.channel.id in nsfw["channels"]
else:
print("yo")
return False

def is_nfsw_enabled():
return commands.check(lambda ctx: ServerConfig().load_config()[ctx.message.server.id]["nsfw"]["enabled"] == 1)
return commands.check(lambda ctx: nsfw_predicate(ctx))



def not_pm():
return commands.check(lambda ctx: ctx.message.channel.type != discord.ChannelType.private)

+ 7
- 5
cogs/reddit.py View File

@@ -5,6 +5,7 @@ import os
import random
import requests
from bs4 import BeautifulSoup
import checks

# Warning, this cog sucks so much but hopefully it works and doesn't break the bot too much. Just lazily edited old code and bodged it into this one.
# There is redundant code here that if removed would make it easier. But it might be handy in the future and isn't that bad.
@@ -180,8 +181,9 @@ class Reddit():
for x in range(10):
choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit)
if choice["data"]["over_18"] and not self.servers[ctx.message.server.id]["nsfw"]["enabled"]:
return await self.bot.say("This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
print(checks.is_nfsw_enabled())
if choice["data"]["over_18"] and not checks.nsfw_predicate(ctx):
return await self.bot.say("This server/channel doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"])
if url:
break
@@ -208,7 +210,7 @@ class Reddit():

choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit)
if choice["data"]["over_18"] and not self.servers[ctx.message.server.id]["nsfw"]["enabled"]:
if choice["data"]["over_18"] and not checks.nsfw_predicate(ctx):
return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"])
@@ -234,7 +236,7 @@ class Reddit():

choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit)
if choice["data"]["over_18"] and not self.servers[ctx.message.server.id]["nsfw"]["enabled"]:
if choice["data"]["over_18"] and not checks.nsfw_predicate(ctx):
return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"])
@@ -258,7 +260,7 @@ class Reddit():

choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit)
if choice["data"]["over_18"] and not self.servers[ctx.message.server.id]["nsfw"]["enabled"]:
if choice["data"]["over_18"] and not checks.nsfw_predicate(ctx):
return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"])

+ 19
- 1
cogs/settings.py View File

@@ -299,6 +299,16 @@ class Settings():
else:
return await self.bot.say("'{}' is already in the list.".format(role.name))

@add.command(pass_context=True, aliases=["nsfwchannel"])
async def addnsfwchannel(self, ctx, *, channel: discord.Channel = None):
self.servers = self.con.load_config()
if channel.id not in self.servers[ctx.message.server.id]["nsfw"]["channels"]:
self.servers[ctx.message.server.id]["nsfw"]["channels"].append(channel.id)
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been added to the nsfw channel list.".format(channel.name))
else:
return await self.bot.say("'{}' is already in the list.".format(channel.name))

@group(pass_context=True)
@checks.is_owner_or_admin()
async def remove(self, ctx):
@@ -326,7 +336,15 @@ class Settings():
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been removed from the Mod role list.".format(role.name))


@remove.command(pass_context=True, aliases=["nsfwchannel"])
async def rensfwchannel(self, ctx, *, channel: discord.Channel = None):
self.servers = self.con.load_config()
try:
self.servers[ctx.message.server.id]["nsfw"]["channels"].remove(channel.id)
except ValueError:
return await self.bot.say("That role was not in the list.")
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been removed from the nsfw channel list.".format(channel.name))


def setup(Bot):

Loading…
Cancel
Save