Changed nsfw and rules so that they can are dictionaries
This commit is contained in:
parent
65d4b143b3
commit
138021bd90
2
bot.py
2
bot.py
|
@ -58,7 +58,6 @@ async def on_ready():
|
|||
@bot.event
|
||||
async def on_member_join(member):
|
||||
notifications = await config.get_content('user_notifications')
|
||||
notifications = notifications or {}
|
||||
server_notifications = notifications.get(member.server.id)
|
||||
|
||||
# By default, notifications should be off unless explicitly turned on
|
||||
|
@ -72,7 +71,6 @@ async def on_member_join(member):
|
|||
@bot.event
|
||||
async def on_member_remove(member):
|
||||
notifications = await config.get_content('user_notifications')
|
||||
notifications = notifications or {}
|
||||
server_notifications = notifications.get(member.server.id)
|
||||
|
||||
# By default, notifications should be off unless explicitly turned on
|
||||
|
|
|
@ -10,7 +10,6 @@ async def update_battle_records(winner, loser):
|
|||
# We're using the Harkness scale to rate
|
||||
# http://opnetchessclub.wikidot.com/harkness-rating-system
|
||||
battles = await config.get_content('battle_records')
|
||||
battles = battles or {}
|
||||
|
||||
# Start ratings at 1000 if they have no rating
|
||||
winner_stats = battles.get(winner.id) or {}
|
||||
|
@ -175,7 +174,6 @@ class Interaction:
|
|||
return
|
||||
|
||||
boops = await config.get_content('boops')
|
||||
boops = boops or {}
|
||||
|
||||
# This is only used to print the amount of times they've booped someone
|
||||
# Set to 1 for the first time someone was booped
|
||||
|
|
|
@ -70,7 +70,7 @@ class Links:
|
|||
# This sets the url as url?q=search+terms
|
||||
url = 'https://derpibooru.org/search.json?q={}'.format('+'.join(search))
|
||||
nsfw_channels = await config.get_content("nsfw_channels")
|
||||
nsfw_channels = nsfw_channels or {}
|
||||
nsfw_channels = nsfw_channels.get('registered')
|
||||
# If this is a nsfw channel, we just need to tack on 'explicit' to the terms
|
||||
# Also use the custom filter that I have setup, that blocks some certain tags
|
||||
# If the channel is not nsfw, we don't need to do anything, as the default filter blocks explicit
|
||||
|
@ -127,7 +127,7 @@ class Links:
|
|||
await self.bot.say("Looking up an image with those tags....")
|
||||
|
||||
nsfw_channels = await config.get_content("nsfw_channels")
|
||||
nsfw_channels = nsfw_channels or {}
|
||||
nsfw_channels = nsfw_channels.get('registered')
|
||||
# e621 by default does not filter explicit content, so tack on
|
||||
# safe/explicit based on if this channel is nsfw or not
|
||||
if ctx.message.channel.id in nsfw_channels:
|
||||
|
|
29
cogs/mod.py
29
cogs/mod.py
|
@ -20,7 +20,6 @@ class Mod:
|
|||
"""This command is used to set a channel as the server's 'notifications' channel
|
||||
Any notifications (like someone going live on Twitch, or Picarto) will go to that channel"""
|
||||
server_alerts = await config.get_content('server_alerts')
|
||||
server_alerts = server_alerts or {}
|
||||
# This will update/add the channel if an entry for this server exists or not
|
||||
server_alerts[ctx.message.server.id] = channel.id
|
||||
await config.save_content('server_alerts', server_alerts)
|
||||
|
@ -38,7 +37,6 @@ class Mod:
|
|||
# When mod logging becomes available, that will be kept to it's own channel if wanted as well
|
||||
on_off = ctx.message.channel.id if re.search("(on|yes|true)", on_off.lower()) else None
|
||||
notifications = await config.get_content('user_notifications')
|
||||
notifications = notifications or {}
|
||||
notifications[ctx.message.server.id] = on_off
|
||||
await config.save_content('user_notifications', notifications)
|
||||
fmt = "notify" if on_off else "not notify"
|
||||
|
@ -56,13 +54,14 @@ class Mod:
|
|||
async def nsfw_add(self, ctx):
|
||||
"""Registers this channel as a 'nsfw' channel"""
|
||||
nsfw_channels = await config.get_content('nsfw_channels')
|
||||
nsfw_channels = nsfw_channels or []
|
||||
# rethinkdb cannot save a list as a field, so we need a dict with one elemtn to store our list
|
||||
nsfw_channels = nsfw_channels.get('registered')
|
||||
if ctx.message.channel.id in nsfw_channels:
|
||||
await self.bot.say("This channel is already registered as 'nsfw'!")
|
||||
else:
|
||||
# Append instead of setting to a certain channel, so that multiple channels can be nsfw
|
||||
nsfw_channels.append(ctx.message.channel.id)
|
||||
await config.save_content('nsfw_channels', nsfw_channels)
|
||||
await config.save_content('nsfw_channels', {'registered': nsfw_channels})
|
||||
await self.bot.say("This channel has just been registered as 'nsfw'! Have fun you naughties ;)")
|
||||
|
||||
@nsfw.command(name="remove", aliases=["delete"], pass_context=True, no_pm=True)
|
||||
|
@ -70,12 +69,12 @@ class Mod:
|
|||
async def nsfw_remove(self, ctx):
|
||||
"""Removes this channel as a 'nsfw' channel"""
|
||||
nsfw_channels = await config.get_content('nsfw_channels')
|
||||
nsfw_channels = nsfw_channels or []
|
||||
nsfw_channels = nsfw_channels.get('registered')
|
||||
if ctx.message.channel.id not in nsfw_channels:
|
||||
await self.bot.say("This channel is not registered as a ''nsfw' channel!")
|
||||
else:
|
||||
nsfw_channels.remove(ctx.message.channel.id)
|
||||
await config.save_content('nsfw_channels', nsfw_channels)
|
||||
await config.save_content('nsfw_channels', {'registered': nsfw_channels})
|
||||
await self.bot.say("This channel has just been unregistered as a nsfw channel")
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
|
@ -100,7 +99,6 @@ class Mod:
|
|||
return
|
||||
|
||||
custom_perms = await config.get_content('custom_permissions')
|
||||
custom_perms = custom_perms or {}
|
||||
server_perms = custom_perms.get(ctx.message.server.id) or {}
|
||||
|
||||
cmd = None
|
||||
|
@ -211,7 +209,6 @@ class Mod:
|
|||
return
|
||||
|
||||
custom_perms = await config.get_content('custom_permissions')
|
||||
custom_perms = custom_perms or {}
|
||||
server_perms = custom_perms.get(ctx.message.server.id) or {}
|
||||
# Save the qualified name, so that we don't get screwed up by aliases
|
||||
server_perms[cmd.qualified_name] = perm_value
|
||||
|
@ -226,7 +223,6 @@ class Mod:
|
|||
async def remove_perms(self, ctx, *command: str):
|
||||
"""Removes the custom permissions setup on the command specified"""
|
||||
custom_perms = await config.get_content('custom_permissions')
|
||||
custom_perms = custom_perms or {}
|
||||
server_perms = custom_perms.get(ctx.message.server.id) or {}
|
||||
if server_perms is None:
|
||||
await self.bot.say("There are no custom permissions setup on this server yet!")
|
||||
|
@ -306,7 +302,8 @@ class Mod:
|
|||
async def rules(self, ctx):
|
||||
"""This command can be used to view the current rules on the server"""
|
||||
rules = await config.get_content('rules')
|
||||
rules = rules or {}
|
||||
# Same issue as the nsfw channels
|
||||
rules = rules.get('rules')
|
||||
server_rules = rules.get(ctx.message.server.id)
|
||||
if server_rules is None or len(server_rules) == 0:
|
||||
await self.bot.say("This server currently has no rules on it! I see you like to live dangerously...")
|
||||
|
@ -321,11 +318,11 @@ class Mod:
|
|||
"""Adds a rule to this server's rules"""
|
||||
# Nothing fancy here, just get the rules, append the rule, and save it
|
||||
rules = await config.get_content('rules')
|
||||
rules = rules or {}
|
||||
server_rules = rules.get(ctx.message.server.id) or []
|
||||
rules = rules.get('rules')
|
||||
server_rules = rules.get(ctx.message.server.id)
|
||||
server_rules.append(rule)
|
||||
rules[ctx.message.server.id] = server_rules
|
||||
await config.save_content('rules', rules)
|
||||
await config.save_content('rules', {'rules': rules})
|
||||
await self.bot.say("I have just saved your new rule, use the rules command to view this server's current rules")
|
||||
|
||||
@rules.command(name='remove', aliases=['delete'], pass_context=True, no_pm=True)
|
||||
|
@ -335,7 +332,7 @@ class Mod:
|
|||
Provide a number to delete that rule; if no number is provided
|
||||
I'll print your current rules and ask for a number"""
|
||||
rules = await config.get_content('rules')
|
||||
rules = rules or {}
|
||||
rules = rules.get('rules')
|
||||
server_rules = rules.get(ctx.message.server.id)
|
||||
if server_rules is None or len(server_rules) == 0:
|
||||
await self.bot.say(
|
||||
|
@ -358,7 +355,7 @@ class Mod:
|
|||
return
|
||||
del server_rules[int(msg.content) - 1]
|
||||
rules[ctx.message.server.id] = server_rules
|
||||
await config.save_content('rules', rules)
|
||||
await config.save_content('rules', {'rules': rules})
|
||||
await self.bot.say("I have just removed that rule from your list of rules!")
|
||||
return
|
||||
|
||||
|
@ -366,7 +363,7 @@ class Mod:
|
|||
try:
|
||||
del server_rules[rule - 1]
|
||||
rules[ctx.message.server.id] = server_rules
|
||||
await config.save_content('rules', rules)
|
||||
await config.save_content('rules', {'rules': rules})
|
||||
await self.bot.say("I have just removed that rule from your list of rules!")
|
||||
except IndexError:
|
||||
await self.bot.say("That is not a valid rule number, try running the command again. "
|
||||
|
|
|
@ -40,7 +40,6 @@ class Overwatch:
|
|||
user = ctx.message.author
|
||||
|
||||
ow_stats = await config.get_content('overwatch')
|
||||
ow_stats = ow_stats or {}
|
||||
bt = ow_stats.get(user.id)
|
||||
|
||||
if bt is None:
|
||||
|
@ -113,7 +112,6 @@ class Overwatch:
|
|||
|
||||
# Now just save the battletag
|
||||
ow = await config.get_content('overwatch')
|
||||
ow = ow or {}
|
||||
ow[ctx.message.author.id] = bt
|
||||
await config.save_content('overwatch', ow)
|
||||
await self.bot.say("I have just saved your battletag {}".format(ctx.message.author.mention))
|
||||
|
@ -123,7 +121,6 @@ class Overwatch:
|
|||
async def delete(self, ctx):
|
||||
"""Removes your battletag from the records"""
|
||||
result = await config.get_content('overwatch')
|
||||
result = result or {}
|
||||
if result.get(ctx.message.author.id):
|
||||
del result[ctx.message.author.id]
|
||||
await self.bot.say("I no longer have your battletag saved {}".format(ctx.message.author.mention))
|
||||
|
|
Loading…
Reference in a new issue