Skip to content

Commit

Permalink
settings overview overhaul
Browse files Browse the repository at this point in the history
Attempt to fix badge updating issue (fixes #44)
  • Loading branch information
fixator10 committed Aug 25, 2020
1 parent 886d8bb commit 4f9d45a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion leveler/commands/lvladmin/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions leveler/commands/lvladmin/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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."""
Expand Down
46 changes: 26 additions & 20 deletions leveler/commands/lvladmin/settings.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
Expand Down

0 comments on commit 4f9d45a

Please sign in to comment.