add(launcher): start launcher development
This commit is contained in:
parent
f4813702fd
commit
b03dc30c6c
8 changed files with 158 additions and 30 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,3 +8,6 @@ private.py
|
||||||
|
|
||||||
#jetbrains
|
#jetbrains
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
#other
|
||||||
|
.logs/*
|
|
@ -1,20 +0,0 @@
|
||||||
token = "INSERT TOKEN HERE"
|
|
||||||
client_id = <INSERT_CLIENT_ID_HERE (in int)>
|
|
||||||
log_channel_id = <INSERT_LOG_CHANNEL_HERE (in int)>
|
|
||||||
main_server_id = <INSERT_MAIN_CHANNEL_ID_HERE (in int)>
|
|
||||||
|
|
||||||
game = "PLAYING_GAME_HERE"
|
|
||||||
prefix = ["."]
|
|
||||||
description = """
|
|
||||||
Je suis TuxBot, le bot qui vit de l'OpenSource ! ;)
|
|
||||||
"""
|
|
||||||
|
|
||||||
mysql = {
|
|
||||||
"host": "localhost",
|
|
||||||
"username": "msqlusername",
|
|
||||||
"password": "msqlpasswd",
|
|
||||||
"dbname": "mysqldb"
|
|
||||||
}
|
|
||||||
|
|
||||||
authorized_id = ['admin ids here']
|
|
||||||
unkickable_id = ['unkickable ids here']
|
|
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"
|
||||||
|
}
|
||||||
|
}
|
43
launcher.py
Normal file
43
launcher.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import logging
|
||||||
|
import contextlib
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
import config
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
import first_run
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def setup_logging():
|
||||||
|
try:
|
||||||
|
logging.getLogger('discord').setLevel(logging.INFO)
|
||||||
|
logging.getLogger('discord.http').setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
log = logging.getLogger()
|
||||||
|
log.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
handler = logging.FileHandler(filename='logs/tuxbot.log',
|
||||||
|
encoding='utf-8', mode='w')
|
||||||
|
fmt = logging.Formatter('[{asctime}] [{levelname:<7}]'
|
||||||
|
' {name}: {message}',
|
||||||
|
'%Y-%m-%d %H:%M:%S', style='{')
|
||||||
|
|
||||||
|
handler.setFormatter(fmt)
|
||||||
|
log.addHandler(handler)
|
||||||
|
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
handlers = log.handlers[:]
|
||||||
|
for hdlr in handlers:
|
||||||
|
hdlr.close()
|
||||||
|
log.removeHandler(hdlr)
|
||||||
|
|
||||||
|
|
||||||
|
def run_bot():
|
||||||
|
pass # Todo: initialize bot, postgresql,...
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
with setup_logging():
|
||||||
|
run_bot()
|
0
logs/tuxbot.log
Normal file
0
logs/tuxbot.log
Normal file
|
@ -1,9 +1,4 @@
|
||||||
pymysql
|
discord.py
|
||||||
beautifulsoup4
|
lxml
|
||||||
lxml==4.2.4
|
click
|
||||||
bs4
|
asyncpg>=0.12.0
|
||||||
pytz
|
|
||||||
requests
|
|
||||||
wikipedia
|
|
||||||
pillow
|
|
||||||
gtts
|
|
Loading…
Reference in a new issue