From 1752c5d9f596c638cb6b7108b0cc9edb1de38c87 Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sat, 9 Jul 2016 11:25:28 -0500 Subject: [PATCH] Setup derpi link to search the database instead of the old configuration file. --- cogs/core.py | 10 +++++++++- cogs/mod.py | 21 ++++++++++++++++++--- cogs/utils/config.py | 1 - 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cogs/core.py b/cogs/core.py index 80a4052..bb0cc06 100644 --- a/cogs/core.py +++ b/cogs/core.py @@ -42,8 +42,16 @@ class Core: url = 'https://derpibooru.org/search.json?q=' query = '+'.join(search) url += query - if ctx.message.channel.id in config.nsfwChannels: + + cursor = config.getCursor() + cursor.execute('use phxntx5_bonfire') + cursor.execute('select * from nsfw_channels') + result = cursor.fetchall() + if {'channel_id': '{}'.format(ctx.message.channel.id)} in result: url += ",+explicit&filter_id=95938" + config.connection.commit() + config.connection.close() + # url should now be in the form of url?q=search+terms # Next part processes the json format, and saves the data in useful lists/dictionaries response = urllib.request.urlopen(url) diff --git a/cogs/mod.py b/cogs/mod.py index 09f01d1..d3cc0bb 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -12,8 +12,8 @@ class Mod: @commands.command(pass_context=True) @checks.isMod() - async def nsfwchannel(self, ctx): - """Registers this channel in the database as a 'nsfw' channel''""" + async def nsfw(self, ctx): + """Registers this channel as a 'nsfw' channel''""" cursor = config.getCursor() cursor.execute('use {}'.format(config.db_default)) try: @@ -24,7 +24,22 @@ class Mod: config.connection.commit() config.connection.close() await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)") - + + @commands.command(pass_context=True) + @checks.isMod() + async def unnsfw(self, ctx) + """Removes this channel as a 'nsfw' channel""" + cursor = config.getCursor() + cursor.execute('use {}'.format(config.db_default)) + try: + cursor.execute('delete from nsfw_channels where channel_id="{}"'.format(ctx.messsage.channel.id)) + except pymysql.IntegrityError: + await self.bot.say("This channel is not registered as a ''nsfw' channel!") + return + config.connection.commit() + config.connection.close() + await self.bot.say("This channel has just been unregistered as a nsfw channel") + @commands.command(pass_context=True, no_pm=True) @checks.isAdmin() async def leave(self, ctx): diff --git a/cogs/utils/config.py b/cogs/utils/config.py index 40f18ef..c1389ca 100644 --- a/cogs/utils/config.py +++ b/cogs/utils/config.py @@ -9,7 +9,6 @@ with open("/home/phxntx5/public_html/Bonfire/config.yml", "r") as f: db_default = global_config.get("db_default") db_boops = global_config.get("db_boops") -nsfwChannels = global_config.get("nsfw_channel") botDescription = global_config.get("description") commandPrefix = global_config.get("command_prefix")