fix(config): update old config code
This commit is contained in:
parent
3ca1a42cad
commit
1be4af8405
4 changed files with 24 additions and 14 deletions
|
@ -15,7 +15,7 @@ from rich.traceback import install
|
|||
|
||||
from tuxbot import version_info
|
||||
|
||||
from . import Config, ConfigFile
|
||||
from .config import Config, ConfigFile, search_for
|
||||
from .data_manager import logs_data_path, data_path
|
||||
|
||||
from . import __version__, ExitCodes
|
||||
|
@ -189,9 +189,11 @@ class Tux(commands.AutoShardedBot):
|
|||
return
|
||||
|
||||
if (
|
||||
self.config.Servers.all[message.guild.id].blacklisted
|
||||
or self.config.Channels.all[message.channel.id].blacklisted
|
||||
or self.config.Users.all[message.author.id].blacklisted
|
||||
search_for(self.config.Servers, message.guild.id, "blacklisted")
|
||||
or search_for(
|
||||
self.config.Channels, message.channel.id, "blacklisted"
|
||||
)
|
||||
or search_for(self.config.Users, message.author.id, "blacklisted")
|
||||
):
|
||||
return
|
||||
|
||||
|
@ -200,9 +202,8 @@ class Tux(commands.AutoShardedBot):
|
|||
if ctx is None or ctx.valid is False:
|
||||
self.dispatch("message_without_command", message)
|
||||
else:
|
||||
if (
|
||||
ctx.command
|
||||
in self.config.Servers.all[message.guild.id].disabled_command
|
||||
if ctx.command in search_for(
|
||||
self.config.Servers, message.guild.id, "disabled_command", []
|
||||
):
|
||||
raise exceptions.DisabledCommandByServerOwner
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from structured_config import (
|
|||
)
|
||||
|
||||
|
||||
__all__ = ["Config", "ConfigFile"]
|
||||
__all__ = ["Config", "ConfigFile", "search_for"]
|
||||
|
||||
log = logging.getLogger("tuxbot.core.config")
|
||||
|
||||
|
@ -67,3 +67,14 @@ class AppConfig(Structure):
|
|||
last_run: int = IntField(0)
|
||||
|
||||
instances: Dict[str, Instance] = {}
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Useful functions to browse configs
|
||||
# =============================================================================
|
||||
|
||||
|
||||
def search_for(config, key, value, default=False):
|
||||
if key in config.all:
|
||||
return getattr(config.all[key], value)
|
||||
return default
|
||||
|
|
|
@ -15,9 +15,7 @@ console.clear()
|
|||
class ContextPlus(commands.Context):
|
||||
async def send(self, content=None, *args, **kwargs):
|
||||
if content is not None:
|
||||
content = content.replace(
|
||||
self.bot.config("core").get("token"), "<token>"
|
||||
)
|
||||
content = content.replace(self.bot.config.Core.token, "<token>")
|
||||
if kwargs.get("embed"):
|
||||
e = str(kwargs.get("embed").to_dict())
|
||||
e = e.replace(self.bot.config("core").get("token"), "<token>")
|
||||
|
|
|
@ -2,10 +2,10 @@ from typing import List
|
|||
|
||||
import discord
|
||||
|
||||
from tuxbot.core.bot import Tux
|
||||
from tuxbot.core.config import search_for
|
||||
|
||||
|
||||
def get_prefixes(tux: Tux, guild: discord.Guild) -> List[str]:
|
||||
def get_prefixes(tux, guild: discord.Guild) -> List[str]:
|
||||
"""Get custom prefixes for one guild.
|
||||
Parameters
|
||||
----------
|
||||
|
@ -19,4 +19,4 @@ def get_prefixes(tux: Tux, guild: discord.Guild) -> List[str]:
|
|||
List[str]
|
||||
List of all prefixes.
|
||||
"""
|
||||
return tux.config.Servers.all[guild.id].prefixes or []
|
||||
return search_for(tux.config.Servers, guild.id, "prefixes", [])
|
||||
|
|
Loading…
Reference in a new issue