import json import time import logging import os from .helperClasses import Options logging.addLevelName(25, "PRINT") logging.basicConfig(filename="gwendolyn.log", level=logging.INFO) def getParams(): with open("resources/slashParameters.json", "r") as f: params = json.load(f) options = Options() if options.testing: for p in params: params[p]["guild_ids"] = options.guildIds return params def logThis(messages, channel : str = "", level : int = 20): localtime = time.asctime(time.localtime(time.time())) channel = channel.replace("Direct Message with ","") if type(messages) is str: messages = [messages] for x, msg in enumerate(messages): if channel == "": messages[x] = localtime+" - "+msg else: messages[x] = localtime+" ("+channel+") - "+msg if len(messages) > 1: messages[0] += " (details in log)" if level >= 25: print(messages[0]) for logMessage in messages: logging.log(level, logMessage) # Capitalizes all words except some of them def cap(s): no_caps_list = ["of","the"] # Capitalizes a strink like a movie title word_number = 0 lst = s.split() res = '' for word in lst: word_number += 1 if word not in no_caps_list or word_number == 1: word = word.capitalize() res += word+" " res = res[:-1] return res def makeFiles(): def makeJsonFile(path,content): # Creates json file if it doesn't exist if not os.path.isfile(path): logThis(path.split("/")[-1]+" didn't exist. Making it now.") with open(path,"w") as f: json.dump(content,f,indent = 4) def makeTxtFile(path,content): # Creates txt file if it doesn't exist if not os.path.isfile(path): logThis(path.split("/")[-1]+" didn't exist. Making it now.") with open(path,"w") as f: f.write(content) def directory(path): if not os.path.isdir(path): os.makedirs(path) logThis("The "+path.split("/")[-1]+" directory didn't exist") with open("resources/startingFiles.json") as f: data = json.load(f) for path, content in data["json"].items(): makeJsonFile(path,content) for path, content in data["txt"].items(): makeTxtFile(path,content) for path in data["folder"]: directory(path) # Replaces multiple things with the same thing def replaceMultiple(mainString, toBeReplaces, newString): # Iterate over the strings to be replaced for elem in toBeReplaces : # Check if string is in the main string if elem in mainString : # Replace the string mainString = mainString.replace(elem, newString) return mainString def emojiToCommand(emoji): if emoji == "1️⃣": return 1 elif emoji == "2️⃣": return 2 elif emoji == "3️⃣": return 3 elif emoji == "4️⃣": return 4 elif emoji == "5️⃣": return 5 elif emoji == "6️⃣": return 6 elif emoji == "7️⃣": return 7 elif emoji == "🎲": return "roll" elif emoji == "❌": return "none" elif emoji == "✔️": return 1 else: return ""