allow shutting down all the rooms in a single list as well as many list files in a specific directory

This commit is contained in:
PC-Admin 2023-05-15 22:17:53 +08:00
parent 0b781813a6
commit fdb1b7ed8f

View File

@ -520,29 +520,41 @@ def shutdown_room(preset_internal_ID,preset_user_ID,preset_new_room_name,preset_
def shutdown_multiple_rooms(): def shutdown_multiple_rooms():
print("Shutdown multiple rooms selected") print("Shutdown multiple rooms selected")
purge_list_location = input("\nPlease enter the path of the file containing a newline seperated list of room ids: ") purge_list_location = input("\nPlease enter the path of the file or directory containing a newline seperated list of room ids: ")
with open(purge_list_location, newline='') as f: file_list = []
reader = csv.reader(f) # check if the input path is a directory or a file
data = list(reader) if os.path.isdir(purge_list_location):
# iterate over all files in the directory
for filename in os.listdir(purge_list_location):
# construct full file path
file_path = os.path.join(purge_list_location, filename)
# add it to the list
file_list.append(file_path)
else:
# it's a single file
file_list.append(purge_list_location)
preset_user_ID = input("\nPlease enter the local username that will create a 'muted violation room' for your users (Example: michael): ") preset_user_ID = input("\nPlease enter the local username that will create a 'muted violation room' for your users (Example: michael): ")
preset_new_room_name = input("\nPlease enter the room name of the muted violation room your users will be sent to: ") preset_new_room_name = input("\nPlease enter the room name of the muted violation room your users will be sent to: ")
preset_message = input("\nPlease enter the shutdown message that will be displayed to users: ") preset_message = input("\nPlease enter the shutdown message that will be displayed to users: ")
preset_purge_choice = input("\n Do you want to purge these rooms? (This deletes all the room history from your database.) y/n? ") preset_purge_choice = input("\n Do you want to purge these rooms? (This deletes all the room history from your database.) y/n? ")
preset_block_choice = input("\n Do you want to block these rooms? (This prevents your server users re-entering the room.) y/n? ") preset_block_choice = input("\n Do you want to block these rooms? (This prevents your server users re-entering the room.) y/n? ")
shutdown_confirmation = input("\n" + str(data) + "\n\nAre you sure you want to shutdown these rooms? y/n? ") # Get the directory of the current script
#print(len(data[0])) script_dir = os.path.dirname(os.path.realpath(__file__))
#print(data[0][0]) for file in file_list:
if shutdown_confirmation == "y" or shutdown_confirmation == "Y" or shutdown_confirmation == "yes" or shutdown_confirmation == "Yes": # Change the current working directory
x = 0 os.chdir(script_dir)
while x <= (len(data) - 1): with open(file, newline='') as f:
#print(data[x][0]) reader = csv.reader(f)
shutdown_room(data[x][0],preset_user_ID,preset_new_room_name,preset_message,preset_purge_choice,preset_block_choice) data = list(reader)
x += 1 shutdown_confirmation = input("\n" + str(data) + "\n\nAre you sure you want to shutdown these rooms? y/n? ")
#print(x) if shutdown_confirmation.lower() in ["y", "yes"]:
time.sleep(10) for room_id in data:
shutdown_room(room_id[0], preset_user_ID, preset_new_room_name, preset_message, preset_purge_choice, preset_block_choice)
if shutdown_confirmation == "n" or shutdown_confirmation == "N" or shutdown_confirmation == "no" or shutdown_confirmation == "No": time.sleep(10)
print("\nExiting...\n") elif shutdown_confirmation.lower() in ["n", "no"]:
print("\nSkipping this file...\n")
else:
print("\nInvalid input, skipping this file...\n")
# Example: # Example:
# See shutdown_room() # See shutdown_room()