2019-09-08 23:05:43 +02:00
|
|
|
from pip._internal import main as pip
|
|
|
|
import shutil
|
|
|
|
|
2019-09-01 23:01:43 +02:00
|
|
|
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)]'
|
|
|
|
}
|
|
|
|
|
2019-09-08 23:05:43 +02:00
|
|
|
with open('requirements.txt', 'r') as f:
|
|
|
|
self.packages = f.read().split('\n')
|
|
|
|
|
2019-09-01 23:01:43 +02:00
|
|
|
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
|
|
|
|
|
2019-09-08 23:05:43 +02:00
|
|
|
def install(self):
|
2019-09-01 23:01:43 +02:00
|
|
|
self.input('lang', valid=locales)
|
2019-09-08 23:05:43 +02:00
|
|
|
print('\n\n\033[4;36m'
|
|
|
|
+ texts.get(self.config.get('lang')).get('install')
|
|
|
|
+ '\033[0m\n')
|
|
|
|
|
|
|
|
for package in self.packages:
|
|
|
|
pip(['install', package])
|
|
|
|
|
|
|
|
def ask(self):
|
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('lang')).get('conf')
|
|
|
|
+ '\033[0m\n')
|
|
|
|
|
2019-09-01 23:01:43 +02:00
|
|
|
self.input('token', empty=False)
|
|
|
|
self.input('postgresql_username', empty=False)
|
|
|
|
self.input('postgresql_password', empty=False)
|
|
|
|
self.input('postgresql_dbname', empty=False)
|
|
|
|
|
2019-09-08 23:05:43 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('lang')).get('logs')
|
|
|
|
+ '\033[0m\n')
|
|
|
|
|
|
|
|
self.input('wh_id', empty=True)
|
|
|
|
self.input('wh_token', empty=True)
|
|
|
|
|
2019-09-01 23:01:43 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('lang')).get('misc')
|
|
|
|
+ '\033[0m\n')
|
|
|
|
|
|
|
|
self.input('activity', empty=True)
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
with open('config.py', 'w') as file:
|
|
|
|
postgresql = f"postgresql://" \
|
|
|
|
f"{self.config.get('postgresql_username')}:" \
|
2019-09-08 23:05:43 +02:00
|
|
|
f"{self.config.get('postgresql_password')}" \
|
|
|
|
f"@localhost/{self.config.get('postgresql_dbname')}"
|
2019-09-01 23:01:43 +02:00
|
|
|
file.write(f"postgresql = '{postgresql}'\n")
|
|
|
|
|
2019-09-08 23:05:43 +02:00
|
|
|
logs_webhook = dict(id=int(self.config.get('wh_id')),
|
|
|
|
token=self.config.get('wh_token'))
|
|
|
|
file.write(f"logs_webhook = '{logs_webhook}'\n")
|
|
|
|
|
2019-09-01 23:01:43 +02:00
|
|
|
for key, value in self.config.items():
|
2019-09-08 23:05:43 +02:00
|
|
|
if not key.startswith('postgresql_') \
|
|
|
|
and not key.startswith('wh_'):
|
2019-09-01 23:01:43 +02:00
|
|
|
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')
|
2019-09-08 23:05:43 +02:00
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
print('\n\n\033[4;36m'
|
|
|
|
+ texts.get(self.config.get('lang')).get('clean')
|
|
|
|
+ '\033[0m\n')
|
|
|
|
shutil.rmtree('first_run')
|