From 788743de25f7bebe9ae3dbfa842d9165afe3f197 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Wed, 22 Mar 2017 22:21:34 -0500 Subject: [PATCH] Update to allow nsfw channel management in DM --- cogs/mod.py | 13 +++++++++++-- cogs/utils/utilities.py | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cogs/mod.py b/cogs/mod.py index 84325e2..05ba745 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -150,7 +150,12 @@ class Mod: EXAMPLE: !nsfw add RESULT: ;)""" - key = str(ctx.message.guild.id) + + if ctx.message.channel is discord.DMChannel: + key = 'DMs' + else: + key = str(ctx.message.guild.id) + entry = {'server_id': key, 'nsfw_channels': [str(ctx.message.channel.id)]} update = {'nsfw_channels': r.row['nsfw_channels'].append(str(ctx.message.channel.id))} @@ -173,7 +178,11 @@ class Mod: EXAMPLE: !nsfw remove RESULT: ;(""" - key = str(ctx.message.guild.id) + if ctx.message.channel is discord.DMChannel: + key = 'DMs' + else: + key = str(ctx.message.guild.id) + server_settings = await utils.get_content('server_settings', key) channel = str(ctx.message.channel.id) try: diff --git a/cogs/utils/utilities.py b/cogs/utils/utilities.py index 3e30643..d430857 100644 --- a/cogs/utils/utilities.py +++ b/cogs/utils/utilities.py @@ -1,6 +1,7 @@ import aiohttp from io import BytesIO import inspect +import discord from . import config from PIL import Image @@ -44,7 +45,11 @@ def get_subcommands(command): pass async def channel_is_nsfw(channel): - server = str(channel.guild.id) + if channel is discord.DMChannel: + server = 'DMs' + else: + server = str(channel.guild.id) + channel = str(channel.id) server_settings = await config.get_content('server_settings', server)