Add settings display
This commit is contained in:
@@ -16,6 +16,7 @@ class Db(object):
|
||||
self.config = DBDict('config')
|
||||
self.inline = DBDict('inline')
|
||||
self.errors = DBDict('errors')
|
||||
self.settings = DBDict('settings')
|
||||
self.spotify = DBDict('spotify')
|
||||
self.deezer = DBDict('deezer')
|
||||
self.youtube = DBDict('youtube')
|
||||
|
||||
1
bot/modules/settings/__init__.py
Normal file
1
bot/modules/settings/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .model import UserSettings, Setting, settings_strings
|
||||
54
bot/modules/settings/model.py
Normal file
54
bot/modules/settings/model.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from dataclasses import dataclass
|
||||
from ..database import db
|
||||
|
||||
|
||||
@dataclass
|
||||
class Setting:
|
||||
name: str
|
||||
description: str
|
||||
choices: dict[str, str]
|
||||
value: str | None = None
|
||||
|
||||
|
||||
settings_strings: dict[str, Setting] = {
|
||||
'search_preview': Setting(
|
||||
name='Search preview',
|
||||
description='Show only covers (better display), '
|
||||
'or add 30 seconds of track preview whenever possible?',
|
||||
choices={
|
||||
'cover': 'Cover picture',
|
||||
'preview': 'Audio preview'
|
||||
},
|
||||
),
|
||||
'recode_youtube': Setting(
|
||||
name='Recode YouTube (and Spotify)',
|
||||
description='Recode when downloading from YouTube (and Spotify) to '
|
||||
'more compatible format (may take some time)',
|
||||
choices={
|
||||
'no': 'Send original file',
|
||||
'yes': 'Recode to libmp3lame'
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class UserSettings:
|
||||
user_id: str
|
||||
|
||||
def __post_init__(self):
|
||||
if db.settings.get(self.user_id) is None:
|
||||
db.settings[self.user_id] = dict(
|
||||
(setting, list(settings_strings[setting].choices)[0]) for setting in
|
||||
settings_strings
|
||||
)
|
||||
|
||||
def __getitem__(self, item):
|
||||
s = settings_strings.get(item)
|
||||
if s is None:
|
||||
return None
|
||||
s.value = db.settings[self.user_id][item]
|
||||
return s
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
db.settings[self.user_id][key] = value
|
||||
Reference in New Issue
Block a user