diff --git a/commands/implemented/command_tempText.py b/commands/implemented/command_tempText.py new file mode 100644 index 0000000..b928fbb --- /dev/null +++ b/commands/implemented/command_tempText.py @@ -0,0 +1,52 @@ +from abc import ABCMeta +import tempText_Module + +from commands.command_base import AbstractCommand + +import random + +import utilities_script as utilities + +class CommandChyron(AbstractCommand, metaclass=ABCMeta): + """ + this is the chyron command. + """ + command = "temptext" + + def __init__(self): + super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["The temptext string can be generated and updated with this command.", + "\nExample:","temptext update \"Name\" \"Title\" \"Content\""] + self.isCommandEnabled = True + + def do_command(self, bot, user_message): + tempBool = True + if tempBool == True: + tempParsedMessage = user_message.message.split(" ") + i = len(tempParsedMessage) + + if i > 2: + if "update" in tempParsedMessage[1]: + tempTextModule = tempText_Module.tempText_Module() + tempText = tempText_Module.tempTextItem() + if i > 2: + newText = "" + counter = 0 + for word in tempParsedMessage: + if counter > 2: + newText = newText + word + " " + counter = counter + 1 + newText = newText[:-1] # Gets rid of last space + print(tempParsedMessage[2], newText) + tempText.itemName = tempParsedMessage[2] + tempText.itemContent = newText + tempTextModule.makeItem(tempText) + else: + tempText.main() + #tempTextModule.update_tempTextFiles() + + returnMessage = "@" + user_message.user + " updated the temptextFiles!" + bot.return_message(returnMessage) + + def get_help(self): + return self.help \ No newline at end of file diff --git a/tempText_Module.py b/tempText_Module.py new file mode 100644 index 0000000..4b9a4e7 --- /dev/null +++ b/tempText_Module.py @@ -0,0 +1,92 @@ +import config +import utilities_script as utilities +import os + +class tempText_Module(): + def __init__(self): + super().__init__() + self.tempText_items = {} + + def main(self): + pass + + def makeItem(self, tempTextItem_): + self.addItem(tempTextItem_.itemName, tempTextItem_.itemTitle, tempTextItem_.itemContent) + self.tempText_stringUpdater() + self.update_tempTextFiles() + + def addItem(self, name, title, content): + newItem:tempTextItem = tempTextItem(name=name, title=title, content=content) + newItem.setupItem(name, title, content) + self.tempText_items[name] = newItem + + def getItem(self, name): + return self.tempText_items[name] + + def updateItem(self, name, title, content): + newItem:tempTextItem = tempTextItem(name=name, title=title, content=content) + newItem.setupItem(name, title, content) + self.tempText_items[name] = newItem + + def deleteItem(self, name): + return self.tempText_items.pop(name, None) + + def tempText_stringUpdater(self): + for c in self.tempText_items: + self.tempText_items[c].item_stringUpdater() + + def update_tempTextFiles(self): + dir = utilities.get_dir("stream_sources") + script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in + + for key in self.tempText_items: + item = self.tempText_items[key] + relative_path = "stream_sources/" + item.itemName + ".txt" + real_file_path = os.path.join(script_dir, relative_path) + + file = open(real_file_path, "wb") + itemText_ = item.item_stringUpdater().encode("utf8") + file.write(itemText_) + file.close + + + +class tempTextItem(): + def __init__(self, name = "", includeTitle = True, title = "", content = ""): + super().__init__() + self.itemName = name #This will determine the fileName + + self.includeTitle = includeTitle + self.itemTitle = title + self.itemContent = content + + self.itemComputedString = "" + + def setupItem(self, name, title, content): + print("Setting up tempTextItem {", name,"}[", title, content, "]") + self.itemName = name + self.itemTitle = title + self.itemContent = content + self.item_stringUpdater() + + def item_stringUpdater(self): + newString = "" + if self.includeTitle == True: + newString = newString + self.itemTitle + newString = newString + self.itemContent + self.itemComputedString = newString + return self.itemComputedString + + + +if __name__ == "__main__": + testModule = tempText_Module() + testModule.main() + + #testModule.addItem("test","title: ", "content content content") + #testModule.tempText_stringUpdater() + + testItem = tempTextItem("testy","title: ", "content content content") + testModule.makeItem(testItem) + + testModule.update_tempTextFiles() \ No newline at end of file diff --git a/user_module.py b/user_module.py index 1454e52..023c042 100644 --- a/user_module.py +++ b/user_module.py @@ -107,7 +107,7 @@ class User(): return self.flags[name] def deleteFlag(self, name): - self.flags.pop(name, None) + return self.flags.pop(name, None) class UserMessage(): def __init__(self, user = User(), message = ""):