(core): Add app-global setting storage.
New `AppConfig` key-value table for arbitrary app config. New `KeyValueData` setting data mixin. New `AppSettings` settings group. Attached `AppSettings` as `client.settings`. Migrated sponsor settings to `AppSettings`.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from cmdClient.checks import is_owner
|
||||
|
||||
from .module import module
|
||||
from .config import settings
|
||||
|
||||
|
||||
@module.cmd(
|
||||
@@ -18,10 +17,10 @@ async def cmd_sponsors(ctx, flags):
|
||||
if await is_owner.run(ctx) and any(flags.values()):
|
||||
if flags['edit']:
|
||||
# Run edit setting command
|
||||
await settings.sponsor_message.command(ctx, 0)
|
||||
await ctx.client.settings.sponsor_message.command(ctx, ctx.client.conf.bot['data_appid'])
|
||||
elif flags['prompt']:
|
||||
# Run prompt setting command
|
||||
await settings.sponsor_prompt.command(ctx, 0)
|
||||
await ctx.client.settings.sponsor_prompt.command(ctx, ctx.client.conf.bot['data_appid'])
|
||||
else:
|
||||
# Display message
|
||||
await ctx.reply(**settings.sponsor_message.args(ctx))
|
||||
await ctx.reply(**ctx.client.settings.sponsor_message.args(ctx))
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
from cmdClient.checks import is_owner
|
||||
|
||||
from settings.base import Setting, ColumnData, ObjectSettings
|
||||
from settings import AppSettings, Setting, KeyValueData, ListData
|
||||
from settings.setting_types import Message, String
|
||||
|
||||
from meta import client
|
||||
from utils.lib import DotDict
|
||||
|
||||
from .data import sponsor_text
|
||||
from core.data import app_config
|
||||
|
||||
|
||||
class SponsorSettings(ObjectSettings):
|
||||
settings = DotDict()
|
||||
pass
|
||||
|
||||
|
||||
@SponsorSettings.attach_setting
|
||||
class sponsor_prompt(String, ColumnData, Setting):
|
||||
@AppSettings.attach_setting
|
||||
class sponsor_prompt(String, KeyValueData, Setting):
|
||||
attr_name = 'sponsor_prompt'
|
||||
_default = "Type {prefix}sponsors to check our wonderful partners!"
|
||||
_default = None
|
||||
|
||||
write_ward = is_owner
|
||||
|
||||
@@ -30,11 +23,11 @@ class sponsor_prompt(String, ColumnData, Setting):
|
||||
|
||||
_quote = False
|
||||
|
||||
_data_column = 'prompt_text'
|
||||
_table_interface = sponsor_text
|
||||
_id_column = 'ID'
|
||||
_upsert = True
|
||||
_create_row = True
|
||||
_table_interface = app_config
|
||||
_id_column = 'appid'
|
||||
_key_column = 'key'
|
||||
_value_column = 'value'
|
||||
_key = 'sponsor_prompt'
|
||||
|
||||
@classmethod
|
||||
def _data_to_value(cls, id, data, **kwargs):
|
||||
@@ -44,8 +37,8 @@ class sponsor_prompt(String, ColumnData, Setting):
|
||||
return None
|
||||
|
||||
|
||||
@SponsorSettings.attach_setting
|
||||
class sponsor_message(Message, ColumnData, Setting):
|
||||
@AppSettings.attach_setting
|
||||
class sponsor_message(Message, KeyValueData, Setting):
|
||||
attr_name = 'sponsor_message'
|
||||
_default = '{"content": "Coming Soon!"}'
|
||||
|
||||
@@ -58,13 +51,10 @@ class sponsor_message(Message, ColumnData, Setting):
|
||||
"Message to reply with when a user runs the `sponsors` command."
|
||||
)
|
||||
|
||||
_data_column = 'command_response'
|
||||
_table_interface = sponsor_text
|
||||
_id_column = 'ID'
|
||||
_upsert = True
|
||||
_create_row = True
|
||||
_table_interface = app_config
|
||||
_id_column = 'appid'
|
||||
_key_column = 'key'
|
||||
_value_column = 'value'
|
||||
_key = 'sponsor_message'
|
||||
|
||||
_cmd_str = "{prefix}sponsors --edit"
|
||||
|
||||
|
||||
settings = SponsorSettings(0)
|
||||
|
||||
@@ -5,8 +5,6 @@ from LionContext import LionContext
|
||||
|
||||
from meta import client
|
||||
|
||||
from .config import settings
|
||||
|
||||
|
||||
module = LionModule("Sponsor")
|
||||
|
||||
@@ -18,7 +16,7 @@ sponsored_commands = {'profile', 'stats', 'weekly', 'monthly'}
|
||||
async def sponsor_reply_wrapper(func, ctx: LionContext, *args, **kwargs):
|
||||
if ctx.cmd and ctx.cmd.name in sponsored_commands:
|
||||
sponsor_hint = discord.Embed(
|
||||
description=settings.sponsor_prompt.value,
|
||||
description=ctx.client.settings.sponsor_prompt.value,
|
||||
colour=discord.Colour.dark_theme()
|
||||
)
|
||||
if 'embed' not in kwargs:
|
||||
|
||||
Reference in New Issue
Block a user