1
0
Fork 0
mirror of synced 2024-05-17 19:12:33 +12:00

Stopped trying to pull from a one indexed list, as we no longer use that in key'd tables

This commit is contained in:
phxntxm 2017-03-08 00:43:40 -06:00
parent 7a3e7afe33
commit 58eb623a1a
12 changed files with 35 additions and 39 deletions

3
bot.py
View file

@ -51,8 +51,7 @@ async def process_command(ctx):
command_usage = await utils.get_content('command_usage', key=command.qualified_name)
if command_usage is None:
command_usage = {'command': command.qualified_name}
else:
command_usage = command_usage[0]
# Add one to the total usage for this command, basing it off 0 to start with (obviously)
total_usage = command_usage.get('total_usage', 0) + 1
command_usage['total_usage'] = total_usage

View file

@ -109,8 +109,8 @@ class Core:
else:
try:
motd = await utils.get_content('motd', str(pendulum.parse(date).date()))
date = motd[0]['date']
motd = motd[0]['motd']
date = motd['date']
motd = motd['motd']
fmt = "Message of the day for {}:\n\n{}".format(date, motd)
await ctx.send(fmt)
# This one will be hit if we return None for that day

View file

@ -131,12 +131,12 @@ class Deviantart:
entry = {'member_id': ctx.message.author.id, 'subbed': [username], 'last_updated': {}}
await utils.add_content('deviantart', entry)
await ctx.send("You have just subscribed to {}!".format(username))
elif content[0]['subbed'] is None or username not in content[0]['subbed']:
if content[0]['subbed'] is None:
elif content['subbed'] is None or username not in content['subbed']:
if content['subbed'] is None:
sub_list = [username]
else:
content[0]['subbed'].append(username)
sub_list = content[0]['subbed']
content['subbed'].append(username)
sub_list = content['subbed']
await utils.update_content('deviantart', {'subbed': sub_list}, key)
await ctx.send("You have just subscribed to {}!".format(username))
else:
@ -152,9 +152,9 @@ class Deviantart:
key = ctx.message.author.id
content = await utils.get_content('deviantart', key)
if content is None or content[0]['subbed'] is None:
if content is None or content['subbed'] is None:
await ctx.send("You are not subscribed to anyone at the moment!")
elif username in content[0]['subbed']:
elif username in content['subbed']:
content[0]['subbed'].remove(username)
await utils.update_content('deviantart', {'subbed': content[0]['subbed']}, key)
await ctx.send("You have just unsubscribed from {}!".format(username))

View file

@ -57,9 +57,9 @@ class StatsUpdate:
server_settings = await config.get_content('server_settings', guild.id)
try:
join_leave_on = server_settings[0]['join_leave']
join_leave_on = server_settings['join_leave']
if join_leave_on:
channel_id = server_settings[0]['notification_channel'] or member.guild.id
channel_id = server_settings['notification_channel'] or member.guild.id
else:
return
except (IndexError, TypeError):
@ -73,9 +73,9 @@ class StatsUpdate:
server_settings = await config.get_content('server_settings', guild.id)
try:
join_leave_on = server_settings[0]['join_leave']
join_leave_on = server_settings['join_leave']
if join_leave_on:
channel_id = server_settings[0]['notification_channel'] or member.guild.id
channel_id = server_settings['notification_channel'] or member.guild.id
else:
return
except (IndexError, TypeError):

View file

@ -262,7 +262,7 @@ class Interaction:
key = booper.id
boops = await utils.get_content('boops', key)
if boops is not None:
boops = boops[0]['boops']
boops = boops['boops']
# If the booper has never booped the member provided, assure it's 0
amount = boops.get(boopee.id, 0) + 1
boops[boopee.id] = amount

View file

@ -155,7 +155,7 @@ class Mod:
update = {'nsfw_channels': r.row['nsfw_channels'].append(ctx.message.channel.id)}
server_settings = await utils.get_content('server_settings', key)
if server_settings and 'nsfw_channels' in server_settings[0].keys():
if server_settings and 'nsfw_channels' in server_settings.keys():
await utils.update_content('server_settings', update, key)
elif server_settings:
await utils.update_content('server_settings', entry, key)
@ -176,7 +176,7 @@ class Mod:
server_settings = await utils.get_content('server_settings', key)
channel = ctx.message.channel.id
try:
channels = server_settings[0]['nsfw_channels']
channels = server_settings['nsfw_channels']
if channel in channels:
channels.remove(channel)
@ -224,7 +224,7 @@ class Mod:
server_settings = await utils.get_content('server_settings', ctx.message.guild.id)
try:
server_perms = server_settings[0]['permissions']
server_perms = server_settings['permissions']
except (TypeError, IndexError):
server_perms = {}
@ -457,8 +457,6 @@ class Mod:
if not rules or len(rules) == 0:
await ctx.send("This server currently has no rules on it! I see you like to live dangerously...")
return
else:
rules = rules[0]
if rule is None:
try:

View file

@ -45,7 +45,7 @@ class Overwatch:
return
# This API sometimes takes a while to look up information, so send a message saying we're processing
bt = ow_stats[0]['battletag']
bt = ow_stats['battletag']
if hero == "":
# If no hero was provided, we just want the base stats for a player

View file

@ -70,7 +70,7 @@ class Picarto:
continue
guild_alerts = await utils.get_content('server_alerts', {'server_id': guild_id})
try:
channel_id = guild_alerts[0]['channel_id']
channel_id = guild_alerts['channel_id']
except (IndexError, TypeError):
channel_id = guild_id
channel = self.bot.get_channel(channel_id)
@ -95,7 +95,7 @@ class Picarto:
continue
guild_alerts = await utils.get_content('server_alerts', {'server_id': guild_id})
try:
channel_id = guild_alerts[0]['channel_id']
channel_id = guild_alerts['channel_id']
except (IndexError, TypeError):
channel_id = guild_id
channel = self.bot.get_channel(channel_id)
@ -128,7 +128,7 @@ class Picarto:
await ctx.send("That user does not have a picarto url setup!")
return
member_url = picarto_entry[0]['picarto_url']
member_url = picarto_entry['picarto_url']
# Use regex to get the actual username so that we can make a request to the API
stream = re.search("(?<=picarto.tv/)(.*)", member_url).group(1)
@ -223,7 +223,7 @@ class Picarto:
"I do not have your Picarto URL added {}. You can save your Picarto url with !picarto add".format(
ctx.message.author.mention))
# Then check if this guild is already added as one to notify in
elif ctx.message.guild.id in result[0]['servers']:
elif ctx.message.guild.id in result['servers']:
await ctx.send("I am already set to notify in this guild...")
else:
await utils.update_content('picarto', {'servers': r.row['servers'].append(ctx.message.guild.id)},

View file

@ -62,9 +62,7 @@ class Stats:
return
command_stats = await utils.get_content('command_usage', cmd.qualified_name)
try:
command_stats = command_stats[0]
except TypeError:
if command_stats is None:
await ctx.send("That command has never been used! You know I worked hard on that! :c")
return
@ -145,7 +143,7 @@ class Stats:
return
# Just to make this easier, just pay attention to the boops data, now that we have the right entry
boops = boops[0]['boops']
boops = boops['boops']
# First get a list of the ID's of all members in this server, for use in list comprehension
server_member_ids = [member.id for member in ctx.message.guild.members]
@ -175,7 +173,7 @@ class Stats:
return
# Just to make this easier, just pay attention to the boops data, now that we have the right entry
boops = boops[0]['boops']
boops = boops['boops']
# Same concept as the mostboops method
server_member_ids = [member.id for member in ctx.message.guild.members]

View file

@ -18,7 +18,7 @@ class Tags:
EXAMPLE: !tags
RESULT: All tags setup on this server"""
tags = await utils.get_content('tags', {'server_id': ctx.message.guild.id})
tags = await utils.get_content('tags', ctx.message.guild.id)
# Simple generator that adds a tag to the list to print, if the tag is for this server
try:
fmt = "\n".join("{}".format(tag['tag']) for tag in tags)

View file

@ -61,9 +61,9 @@ class Twitch:
server = self.bot.get_server(server_id)
if server is None:
continue
server_alerts = await utils.get_content('server_alerts', server_id)
server_settings = await utils.get_content('server_settings', server_id)
try:
channel_id = server_alerts[0]['channel_id']
channel_id = server_settings['notification_channel']
except (IndexError, TypeError):
channel_id = server_id
channel = self.bot.get_channel(channel_id)
@ -86,10 +86,11 @@ class Twitch:
server = self.bot.get_server(server_id)
if server is None:
continue
server_alerts = await utils.get_content('server_alerts', {'server_id': server_id})
channel_id = server_id
if server_alerts is not None and len(server_alerts) > 0:
channel_id = server_alerts[0].get('channel_id')
server_settings = await utils.get_content('server_settings', server_id)
try:
channel_id = server_settings['notification_channel']
except (IndexError, TypeError):
channel_id = server_id
channel = self.bot.get_channel(channel_id)
# Get the member that has just gone live
member = server.get_member(m_id)
@ -203,7 +204,7 @@ class Twitch:
"I do not have your twitch URL added {}. You can save your twitch url with !twitch add".format(
ctx.message.author.mention))
# Then check if this server is already added as one to notify in
elif ctx.message.guild.id in result[0]['servers']:
elif ctx.message.guild.id in result['servers']:
await ctx.send("I am already set to notify in this server...")
else:
await utils.update_content('twitch', {'servers': r.row['servers'].append(ctx.message.guild.id)}, key)

View file

@ -50,7 +50,7 @@ async def channel_is_nsfw(channel):
server_settings = await config.get_content('server_settings', server)
try:
return channel in server_settings[0]['nsfw_channels']
return channel in server_settings['nsfw_channels']
except (TypeError, IndexError):
return False