Browse Source

added many redundant copies for the settings when parsing. Also added a way to get raw settings.

tags/v1.7.0
Roxie Gibson 6 years ago
parent
commit
c513d70399
2 changed files with 15 additions and 8 deletions
  1. +0
    -1
      roxbot/cogs/reddit.py
  2. +15
    -7
      roxbot/settings/settings.py

+ 0
- 1
roxbot/cogs/reddit.py View File

@@ -106,7 +106,6 @@ class Reddit():
while not url and x <= 20:
choice = random.choice(links["children"])["data"]
url = await parse_url(choice["url"])
print(x)
if url:
x_old = int(x)
# If the url or id are in the cache, continue the loop. If not, proceed with the post.

+ 15
- 7
roxbot/settings/settings.py View File

@@ -42,10 +42,11 @@ class Settings:
guild_settings.backup(guild_settings._open_config(), filename)
return await ctx.send("Settings file backed up as '{}.json'".format(filename))

def parse_setting(self, ctx, setting):
def parse_setting(self, ctx, settings_to_copy, raw=False):
settingcontent = ""
setting = settings_to_copy.copy()
convert = setting.get("convert", None)
if convert is not None:
if convert is not None and not raw:
for x in convert.keys():
if convert[x] == "bool":
if setting[x] == 0:
@@ -97,29 +98,36 @@ class Settings:
setting[x] = str(setting[x])
else:
setting[x] = str(user)

for x in setting.items():
if x[0] != "convert":
settingcontent += str(x).strip("()") + "\n"
return settingcontent

@commands.command()
@commands.command(aliases=["printsettingsraw"])
@checks.is_admin_or_mod()
async def printsettings(self, ctx, option=None):
"OWNER OR ADMIN ONLY: Prints the servers settings file."
# TODO: Use paginator to make the output here not break all the time.
config = guild_settings.get(ctx.guild)
settings = dict(config.settings) # Make a copy of settings so we don't change the actual settings.
settings = dict(config.settings.copy()) # Make a copy of settings so we don't change the actual settings.
em = discord.Embed(colour=EmbedColours.pink)
em.set_author(name="{} settings for {}.".format(self.bot.user.name, ctx.message.guild.name), icon_url=self.bot.user.avatar_url)
if option in settings:
settingcontent = self.parse_setting(ctx, settings[option])
if ctx.invoked_with == "printsettingsraw":
raw = True
else:
raw = False
settingcontent = self.parse_setting(ctx, settings[option], raw=raw)
em.add_field(name=option, value=settingcontent, inline=False)
return await ctx.send(embed=em)
else:
for setting in settings:
if setting != "custom_commands" and setting != "warnings":
settingcontent = self.parse_setting(ctx, settings[setting])
if ctx.invoked_with == "printsettingsraw":
raw = True
else:
raw = False
settingcontent = self.parse_setting(ctx, settings[setting], raw=raw)
em.add_field(name=setting, value=settingcontent, inline=False)
elif setting == "custom_commands":
em.add_field(name="custom_commands", value="For Custom Commands, use the custom list command.", inline=False)

Loading…
Cancel
Save