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)]',
|
|
|
|
}
|
|
|
|
|
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):
|
2019-09-12 15:43:57 +02:00
|
|
|
locale = self.config.get('locale', 'multiple')
|
2019-09-01 23:01:43 +02:00
|
|
|
|
2019-09-12 15:43:57 +02:00
|
|
|
print('\n\033[4m' + texts.get(locale).get(key) + '\033[0m')
|
2019-09-01 23:01:43 +02:00
|
|
|
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:
|
2019-09-12 15:43:57 +02:00
|
|
|
print('\033[41m' + texts.get(locale).get('not_empty')
|
2019-09-01 23:01:43 +02:00
|
|
|
+ '\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-12 15:43:57 +02:00
|
|
|
self.input('locale', valid=locales)
|
2019-09-08 23:05:43 +02:00
|
|
|
print('\n\n\033[4;36m'
|
2019-09-12 15:43:57 +02:00
|
|
|
+ texts.get(self.config.get('locale')).get('install')
|
2019-09-08 23:05:43 +02:00
|
|
|
+ '\033[0m\n')
|
|
|
|
|
|
|
|
for package in self.packages:
|
|
|
|
pip(['install', package])
|
|
|
|
|
|
|
|
def ask(self):
|
2019-09-12 15:43:57 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('locale'))
|
|
|
|
.get('conf') + '\033[0m\n')
|
2019-09-08 23:05:43 +02:00
|
|
|
|
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-12 15:43:57 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('locale'))
|
|
|
|
.get('logs') + '\033[0m\n')
|
2019-09-08 23:05:43 +02:00
|
|
|
|
|
|
|
self.input('wh_id', empty=True)
|
|
|
|
self.input('wh_token', empty=True)
|
|
|
|
|
2019-09-12 15:43:57 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('locale'))
|
|
|
|
.get('misc') + '\033[0m\n')
|
2019-09-01 23:01:43 +02:00
|
|
|
|
|
|
|
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")
|
2019-09-12 15:43:57 +02:00
|
|
|
print('\n\n\033[4;36m' + texts.get(self.config.get('locale'))
|
|
|
|
.get('end') + '\033[0m\n')
|
2019-09-08 23:05:43 +02:00
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
print('\n\n\033[4;36m'
|
2019-09-12 15:43:57 +02:00
|
|
|
+ texts.get(self.config.get('locale')).get('clean')
|
2019-09-08 23:05:43 +02:00
|
|
|
+ '\033[0m\n')
|