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

return False return False
return commands.check(predicate) 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(): 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(): def not_pm():
return commands.check(lambda ctx: ctx.message.channel.type != discord.ChannelType.private) return commands.check(lambda ctx: ctx.message.channel.type != discord.ChannelType.private)

+ 7
- 5
cogs/reddit.py View File

import random import random
import requests import requests
from bs4 import BeautifulSoup 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. # 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. # 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.
for x in range(10): for x in range(10):
choice = random.choice(links) choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit) 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"]) url = Scrapper().retriveurl(choice["data"]["url"])
if url: if url:
break break


choice = random.choice(links) choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit) 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( return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.") "This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"]) url = Scrapper().retriveurl(choice["data"]["url"])


choice = random.choice(links) choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit) 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( return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.") "This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"]) url = Scrapper().retriveurl(choice["data"]["url"])


choice = random.choice(links) choice = random.choice(links)
title = "**{}** from /r/{}\n".format(choice["data"]["title"], subreddit) 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( return await self.bot.say(
"This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.") "This server doesn't have my NSFW stuff enabled. This extends to posting NFSW content from Reddit.")
url = Scrapper().retriveurl(choice["data"]["url"]) url = Scrapper().retriveurl(choice["data"]["url"])

+ 19
- 1
cogs/settings.py View File

else: else:
return await self.bot.say("'{}' is already in the list.".format(role.name)) 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) @group(pass_context=True)
@checks.is_owner_or_admin() @checks.is_owner_or_admin()
async def remove(self, ctx): async def remove(self, ctx):
self.con.update_config(self.servers) self.con.update_config(self.servers)
return await self.bot.say("'{}' has been removed from the Mod role list.".format(role.name)) 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): def setup(Bot):

Loading…
Cancel
Save