MsRewards-Reborn/modules/config.py

148 lines
3.6 KiB
Python
Raw Normal View History

#!/usr/bin/python3.10
2023-04-15 11:03:47 +02:00
from modules.driver_tools import *
from modules.imports import *
import modules.globals as g
2023-06-17 16:52:47 +02:00
import json
parser = argparse.ArgumentParser()
parser.add_argument(
"-o",
"--override",
help="override",
dest="override",
action="store_true"
)
parser.add_argument(
"-u",
"--unban",
help="unban an account",
dest="unban",
action="store_true"
)
parser.add_argument(
"-fl",
"--fulllog",
dest="fulllog",
help="enable full logging in discord",
action="store_true",
)
2023-06-17 16:52:47 +02:00
parser.add_argument(
"-c",
"--config",
help="Choose a specific config file",
2023-04-15 11:18:36 +02:00
default=""
)
2022-11-16 18:12:43 +01:00
2023-02-25 19:05:47 +01:00
parser.add_argument(
"-v",
"--vnc",
help="enable VNC",
dest="vnc",
default="None"
)
parser.add_argument(
2023-04-09 23:41:31 +02:00
"--version",
help="display a message on discord to tell that the bot have been updated",
dest="update_version",
default="None"
)
2023-04-25 21:56:29 +02:00
2023-06-17 16:52:47 +02:00
with open("./user_data/discord.json", "r") as inFile:
discord = json.load(inFile)
with open("./user_data/settings.json", "r") as inFile:
settings = json.load(inFile)
with open("./user_data/proxy.json", "r") as inFile:
proxy = json.load(inFile)
with open("./user_data/configs.json", "r") as inFile:
config = json.load(inFile)
with open("./user_data/database.json", "r") as inFile:
database = json.load(inFile)
2023-04-25 21:56:29 +02:00
args = parser.parse_args()
2023-04-15 11:03:47 +02:00
g.custom_start = args.override
g.unban = args.unban
g.full_log = args.fulllog
2023-04-15 11:03:47 +02:00
if g.custom_start :
g.log = True
2023-04-15 11:03:47 +02:00
g.vnc_enabled = args.vnc != "None"
g.vnc_port = args.vnc
g.update_version = args.update_version
# global variables used later in the code
g.islinux = platform == "linux" # if the computer running this program is Linux, it allow more things
g.start_time = time()
# path configurations
2023-06-17 16:52:47 +02:00
g.mot_path = "/usr/share/dict/french"
g.credential_path = "./user_data/login.csv"
2023-06-17 16:52:47 +02:00
discord_conf = config[args.config]["discord"]
# discord configuration
2023-06-17 16:52:47 +02:00
g.discord_success_link = discord[discord_conf]["successL"]
g.discord_error_link = discord[discord_conf]["errorsL"]
g.discord_enabled_error = discord[discord_conf]["errorsT"] == "True"
g.discord_enabled_success = discord[discord_conf]["successT"] == "True"
g.avatar_url = settings["avatarlink"]
2023-04-15 11:03:47 +02:00
if g.discord_enabled_error:
webhookFailure = Webhook.from_url(g.discord_error_link, adapter=RequestsWebhookAdapter())
if g.discord_enabled_success:
webhookSuccess = Webhook.from_url(g.discord_success_link, adapter=RequestsWebhookAdapter())
# base settings
2023-06-17 16:52:47 +02:00
g.discord_embed = False # send new point value in an embed, fixed for now
g.headless = False
# proxy settings
2023-06-17 16:52:47 +02:00
g.proxy_enabled = config[args.config]["proxy"] != "-1"
if g.proxy_enabled :
g.proxy_address = proxy[config[args.config]["proxy"]]["address"]
g.proxy_port = proxy[config[args.config]["proxy"]]["port"]
# MySQL settings
2023-06-17 16:52:47 +02:00
g.sql_enabled = database["checked"] == "checked"
g.sql_usr = database["usr"]
g.sql_pwd = database["pwd"]
g.sql_host = database["host"]
g.sql_database = database["table"]
2023-05-07 23:26:27 +02:00
try :
2023-05-08 20:56:55 +02:00
g.database_error_override = config["OTHER"]["database_override"] == "True"
2023-05-07 23:26:27 +02:00
except :
pass
2023-06-17 16:52:47 +02:00
g.fast = False
# list of words
2023-04-15 11:03:47 +02:00
h = open(g.mot_path, "r", encoding="utf-8")
lines = h.readlines()
if len(lines) < 3 :
Liste_de_mot = list(lines[0].split(","))
else :
Liste_de_mot = [x.replace('\n', "") for x in lines]
2023-04-15 11:03:47 +02:00
h.close()
2023-06-17 16:52:47 +02:00
Credentials = [ (config[args.config]['accounts'][x]["mail"],config[args.config]['accounts'][x]["pwd"],config[args.config]['accounts'][x]["2fa"]) for x in config[args.config]['accounts']]
2023-04-15 11:03:47 +02:00
g._cred = Credentials
if g.proxy_enabled :
setup_proxy(g.proxy_address,g.proxy_port)