add(launcher): start launcher development
This commit is contained in:
parent
f4813702fd
commit
b03dc30c6c
8 changed files with 158 additions and 30 deletions
5
first_run/__init__.py
Normal file
5
first_run/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from .config import Config
|
||||
|
||||
setup = Config()
|
||||
setup.ask()
|
||||
setup.save()
|
61
first_run/config_generator.py
Normal file
61
first_run/config_generator.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
from .langs import locales, texts
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self):
|
||||
self.config = {
|
||||
'log_channel_id': '<INSERT_LOG_CHANNEL_HERE (in int)>',
|
||||
'main_server_id': '<INSERT_MAIN_CHANNEL_ID_HERE (in int)>',
|
||||
'authorized_id': '[admin ids here (in int)]',
|
||||
'unkickable_id': '[unkickable ids here (in int)]'
|
||||
}
|
||||
|
||||
def input(self, key, **kwargs):
|
||||
lang = self.config.get('lang', 'multiple')
|
||||
|
||||
print('\n\033[4m' + texts.get(lang).get(key) + '\033[0m')
|
||||
response = input('> ')
|
||||
|
||||
if kwargs.get('valid'):
|
||||
while response not in kwargs.get('valid'):
|
||||
print('\033[36m' + '/'.join(kwargs.get('valid')) + '\033[0m')
|
||||
response = input('> ')
|
||||
|
||||
if not kwargs.get('empty', True):
|
||||
while len(response) == 0:
|
||||
print('\033[41m' + texts.get(lang).get('not_empty')
|
||||
+ '\033[0m')
|
||||
response = input('> ')
|
||||
else:
|
||||
response = kwargs.get('default', None) if len(response) == 0 \
|
||||
else response
|
||||
|
||||
self.config[key] = response
|
||||
|
||||
def ask(self):
|
||||
self.input('lang', valid=locales)
|
||||
self.input('token', empty=False)
|
||||
self.input('postgresql_username', empty=False)
|
||||
self.input('postgresql_password', empty=False)
|
||||
self.input('postgresql_dbname', empty=False)
|
||||
|
||||
print('\n\n\033[4;36m' + texts.get(self.config.get('lang')).get('misc')
|
||||
+ '\033[0m\n')
|
||||
|
||||
self.input('activity', empty=True)
|
||||
self.input('prefix', empty=True)
|
||||
|
||||
def save(self):
|
||||
with open('config.py', 'w') as file:
|
||||
postgresql = f"postgresql://" \
|
||||
f"{self.config.get('postgresql_username')}:" \
|
||||
f"{self.config.get('postgresql_password')}@host/" \
|
||||
f"{self.config.get('postgresql_dbname')}"
|
||||
file.write(f"postgresql = '{postgresql}'\n")
|
||||
|
||||
for key, value in self.config.items():
|
||||
if not key.startswith('postgresql_'):
|
||||
value = f"'{value}'" if type(value) is str else value
|
||||
file.write(f"{key} = {value}\n")
|
||||
print('\n\n\033[4;36m' + texts.get(self.config.get('lang')).get('end')
|
||||
+ '\033[0m\n')
|
41
first_run/langs.py
Normal file
41
first_run/langs.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
locales = ['fr', 'en']
|
||||
texts = {
|
||||
'fr': {
|
||||
'token': "Veuillez entrer le token",
|
||||
'not_empty': "Cette valeur ne doit pas être vide",
|
||||
|
||||
'postgresql_username': "Veuillez entrer le nom d'utilisateur de postgresql",
|
||||
'postgresql_password': "Veuillez entrer le mot de passe de postgresql",
|
||||
'postgresql_dbname': "Veuillez entrer le nom de la base de donnée",
|
||||
|
||||
'misc': 'Autre',
|
||||
|
||||
'activity': "Joue à ...",
|
||||
'prefix': "Prefixe (par defaut : @tuxbot)",
|
||||
|
||||
"end": "Configuration terminée, vous pouvez à tout moment la rectifier en modifiant le fichier config.py"
|
||||
},
|
||||
|
||||
'en': {
|
||||
'token': "Please enter the token",
|
||||
'not_empty': "This value must not be empty",
|
||||
|
||||
'postgresql_username': "Please enter the postgresql username",
|
||||
'postgresql_password': "Please enter the postgresql password",
|
||||
'postgresql_dbname': "Please enter the database name",
|
||||
|
||||
'misc': 'Misc',
|
||||
|
||||
'activity': "Playing ...",
|
||||
'prefix': "Prefix (default is @tuxbot)",
|
||||
|
||||
"end": "Configuration completed, you can fix it at any time by modifying the config.py file"
|
||||
},
|
||||
|
||||
'multiple': {
|
||||
'lang': "Veuillez choisir une langue | Please choose a language "
|
||||
"[fr/en]",
|
||||
'not_empty': "Cette valeur ne doit pas être vide |"
|
||||
" This value must not be empty"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue