1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Setup derpi link to search the database instead of the old configuration file.

This commit is contained in:
Phxntxm 2016-07-09 11:25:28 -05:00
parent 65e25b52ff
commit 1752c5d9f5
3 changed files with 27 additions and 5 deletions

View file

@ -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)

View file

@ -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):

View file

@ -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")