-
Notifications
You must be signed in to change notification settings - Fork 11
/
start.py
107 lines (82 loc) · 4.4 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'''
Copyright (C) 2021-2022 Katelynn Cadwallader.
This file is part of Gatekeeper, the AMP Minecraft Discord Bot.
Gatekeeper is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Gatekeeper is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with Gatekeeper; see the file COPYING. If not, write to the Free
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA.
'''
import sys
import subprocess
import argparse
import pip
import threading
from threading import current_thread
import time
import pathlib
class Setup:
def __init__(self):
# Use action="store_true", then check the arg via "args.name" eg. "args.dev"
parser = argparse.ArgumentParser(description='AMP Discord Bot')
parser.add_argument('-token', help='Bypasse tokens validation check.', required=False, action="store_true")
parser.add_argument('-super', help='This leaves AMP Super Admin role intact, use at your own risk.', required=False, action="store_true")
# All the args below are used for development purpose.
parser.add_argument('-dev', help='Enable development print statments.', required=False, action="store_true")
parser.add_argument('-command', help='Enable command usage print statements.', required=False, action="store_true")
parser.add_argument('-discord', help='Disables Discord Intigration (used for testing)', required=False, action="store_false")
parser.add_argument('-debug', help='Enables DEBUGGING level for logging', required=False, action="store_true")
self.args = parser.parse_args()
self.pip_install()
# Custom Logger functionality.
import logging
import logger
logger.init(self.args)
self.logger = logging.getLogger()
# Renaming Main Thread to "Gatekeeper"
Gatekeeper = current_thread()
Gatekeeper.name = 'Gatekeeper'
self.logger.dev(f'Current Startup Args:{self.args}')
self.logger.dev("**ATTENTION** YOU ARE IN DEVELOPMENT MODE** All features are not present and stability is not guaranteed!")
if not self.args.discord:
self.logger.critical("***ATTENTION*** Discord Intergration has been DISABLED!")
# This sets up our SQLite Database!
import DB
self.DBHandler = DB.getDBHandler()
self.DB = self.DBHandler.DB
self.DB_Config = self.DB.DBConfig
self.logger.info(f'SQL Database Version: {self.DB.DBHandler.DB_Version} // SQL Database: {self.DB.DBHandler.SuccessfulDatabase}')
# This connects and creates all our AMP related parts
import AMP_Handler
self.AMP_Thread = threading.Thread(target=AMP_Handler.AMP_init, name='AMP Handler', args=[self.args, ])
self.AMP_Thread.start()
if self.args.discord:
while (AMP_Handler.AMP_setup == False):
time.sleep(.5)
# if self.args.dev and pathlib.Path('tokens_dev.py').exists():
# import tokens_dev as tokens
import tokens
import discordBot
discordBot.client_run(tokens)
def python_ver_check(self):
if not sys.version_info.major >= 3 and not sys.version_info.minor >= 10:
self.logger.critical(f'Unable to Start Gatekeeper, Python Version is {sys.version_info.major + "." + sys.version_info.minor} we require Python Version >= 3.10')
sys.exit(1)
def pip_install(self):
pip_version = pip.__version__.split('.')
pip_v_major = int(pip_version[0])
pip_v_minor = int(pip_version[1])
if pip_v_major > 22 or (pip_v_major == 22 and pip_v_minor >= 1):
_current_path = pathlib.Path(__file__).parent.absolute()
_requirements_path = _current_path.joinpath('requirements.txt')
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', f'{_requirements_path}'])
else:
print(f'Unable to Start Gatekeeper, PIP Version is {pip.__version__}, we require PIP Version >= 22.1')
Start = Setup()