From 4f9d45aef93c98ed383f9f4e0d9625301dc356e5 Mon Sep 17 00:00:00 2001 From: Fixator10 Date: Tue, 25 Aug 2020 18:05:58 +0400 Subject: [PATCH] settings overview overhaul Attempt to fix badge updating issue (fixes #44) --- leveler/commands/lvladmin/badge.py | 2 +- leveler/commands/lvladmin/economy.py | 6 ++++ leveler/commands/lvladmin/settings.py | 46 +++++++++++++++------------ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/leveler/commands/lvladmin/badge.py b/leveler/commands/lvladmin/badge.py index 414e1875..f3a956e4 100644 --- a/leveler/commands/lvladmin/badge.py +++ b/leveler/commands/lvladmin/badge.py @@ -108,7 +108,7 @@ async def addbadge( # update badge in the server badges["badges"][name] = new_badge await self.db.badges.update_one( - {"server_id": serverid}, {"$set": {"badges": badges["badges"]}} + {"server_id": str(serverid)}, {"$set": {"badges": badges["badges"]}} ) # go though all users and update the badge. diff --git a/leveler/commands/lvladmin/economy.py b/leveler/commands/lvladmin/economy.py index 0ff6b8c9..f877e1fd 100644 --- a/leveler/commands/lvladmin/economy.py +++ b/leveler/commands/lvladmin/economy.py @@ -10,6 +10,11 @@ async def non_global_bank(ctx): return not await bank.is_global() +# noinspection PyUnusedLocal +async def global_bank(ctx): + return await bank.is_global() + + class Economy(MixinMeta): """Economy administration commands""" @@ -33,6 +38,7 @@ async def msgcredits(self, ctx, currency: int = 0): @commands.is_owner() @lvladmin.command() + @commands.check(global_bank) @commands.guild_only() async def setprice(self, ctx, price: int): """Set a price for background changes.""" diff --git a/leveler/commands/lvladmin/settings.py b/leveler/commands/lvladmin/settings.py index c0e5ab47..2a099bdd 100644 --- a/leveler/commands/lvladmin/settings.py +++ b/leveler/commands/lvladmin/settings.py @@ -1,5 +1,7 @@ import discord from redbot.core import commands +from tabulate import tabulate +from redbot.core.utils import chat_formatting as chat from leveler.abc import MixinMeta @@ -15,33 +17,37 @@ class Settings(MixinMeta): @lvladmin.command() async def overview(self, ctx): """A list of settings.""" - num_users = await self.db.users.count_documents({}) is_owner = await self.bot.is_owner(ctx.author) em = discord.Embed(colour=await ctx.embed_color()) - msg = "" - msg += "**Enabled:** {}\n".format( - self.bool_emojify(not await self.config.guild(ctx.guild).disabled()) - ) - msg += "**Unique Users:** {}\n".format(num_users) + settings = { + "Enabled": self.bool_emojify(not await self.config.guild(ctx.guild).disabled()), + "Unique registered users": str(await self.db.users.count_documents({})), + "Level messages enabled": self.bool_emojify( + await self.config.guild(ctx.guild).lvl_msg() + ), + "Level messages are private": self.bool_emojify( + await self.config.guild(ctx.guild).private_lvl_message() + ), + } + owner_settings = {} if is_owner: - msg += "**Mentions:** {}\n".format(self.bool_emojify(await self.config.mention())) + owner_settings.update( + { + "Mentions": self.bool_emojify(await self.config.mention()), + "Badges type": await self.config.badge_type(), + } + ) + if lvl_lock := await self.config.guild(ctx.guild).lvl_msg_lock(): + settings["Level messages channel lock"] = ctx.guild.get_channel(lvl_lock) if bg_price := await self.config.bg_price(): - msg += "**Background Price:** {}\n".format(bg_price) - if is_owner: - msg += "**Badge type:** {}\n".format(await self.config.badge_type()) - msg += "**Enabled Level Messages:** {}\n".format( - self.bool_emojify(await self.config.guild(ctx.guild).lvl_msg()) + settings["Background price"] = bg_price + em.description = chat.box(tabulate(settings.items())) + ( + chat.box(tabulate(owner_settings.items())) if owner_settings else "" ) - msg += "**Private Level Messages:** {}\n".format( - self.bool_emojify(await self.config.guild(ctx.guild).private_lvl_message()) + em.set_author( + name="Settings Overview for {}".format(ctx.guild.name), icon_url=ctx.guild.icon_url ) - if lvl_lock := await self.config.guild(ctx.guild).lvl_msg_lock(): - msg += "**Level Messages Channel:** {}\n".format( - ctx.guild.get_channel(lvl_lock).mention - ) - em.description = msg - em.set_author(name="Settings Overview for {}".format(ctx.guild.name)) await ctx.send(embed=em) @lvladmin.command()