Added temptext Command

This commit is contained in:
Alex Orid 2021-04-16 14:15:52 -04:00
parent 1e33859f28
commit b21cb25252
3 changed files with 145 additions and 1 deletions

View File

@ -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

92
tempText_Module.py Normal file
View File

@ -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()

View File

@ -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 = ""):