Skip to content

Commit

Permalink
fixed container and config
Browse files Browse the repository at this point in the history
  • Loading branch information
Wargamer-Senpai committed Oct 20, 2023
1 parent c8ba0aa commit ce282f8
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
import datetime
import inspect
import re
import shutil

# import config.py
import config
try:
# import config.py
import config
except:
DUMMY="DUMMY"
# import bad_words.py
from modules.bad_words import *
# import version.py file
Expand Down Expand Up @@ -97,8 +101,6 @@
admin_dict_checked = False
# response when searching for a user/users
user_room_ids = {}
# contains the boolean if configs should be merged
merge_bool = config.merge_config

# description for stats
stats_description = {
Expand Down Expand Up @@ -603,6 +605,7 @@ def func_find_roomid(user_identifiers):
######################################
def func_merge_configs():
global admin_dict_checked, commands_dict_checked, room_id

if merge_bool:
new_config = False
config_url = 'https://raw.githubusercontent.com/Wargamer-Senpai/teampy/main/config.py'
Expand Down Expand Up @@ -653,11 +656,14 @@ def func_merge_configs():
if new_config == True:
with open(example_config_file, 'w', encoding="utf-8") as file:
file.write(content)

os.rename("config.py", "config_backup_"+datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')+".py")
if func_container_check():
shutil.move(os.path.join("configs","config.py"), os.path.join("configs","config_backup_"+datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')+".py"))
else:
os.rename("config.py", "config_backup_"+datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')+".py")
os.rename(example_config_file, "config.py")

if func_container_check():
shutil.move("config.py", os.path.join("configs","config.py"))
import configs.config as config
else:
import config
Expand All @@ -677,26 +683,33 @@ def func_merge_configs():
############################
if func_container_check():
# if running inside a container
func_write_to_log("!! running inside a container !!", "INFO", "startup_container_check")
source_config = "/opt/teampy/config.py"
target_config = "/opt/teampy/configs/config.py"
if not os.path.exists(target_config):
with open(source_config, 'rb') as src_file:
with open(target_config, 'wb') as dest_file:
dest_file.write(src_file.read())
func_write_to_log("config.py copied successfully!", "INFO", "startup_container_check")
else:
func_write_to_log("config.py already exists!", "INFO", "startup_container_check")
# func_write_to_log("config.py copied successfully!", "INFO", "startup_container_check")
# func_write_to_log("config.py already exists!", "INFO", "startup_container_check")

# import config file from persistent folder

import configs.config as config
func_write_to_log("!! running inside a container !!", "INFO", "startup_container_check")
# change folders for files that needs to be persistent
notify_file = os.path.join(main_script_path,"configs","notify.txt")
stats_file = os.path.join(main_script_path,"configs", "stats.txt")

else:
func_write_to_log("not running inside a container", "INFO", "startup_container_check")

# contains the boolean if configs should be merged
try:
merge_bool = config.merge_config
except AttributeError:
merge_bool = True



if not config.matrix_username or not config.matrix_password:
func_write_to_log("finish configuration step first! (username and/or password empty)", "ERROR", "startup")
Expand Down

0 comments on commit ce282f8

Please sign in to comment.