Breaking out placeholder stuff to its own def

This commit is contained in:
Siina Mashek 2022-05-03 21:37:48 +03:00
parent 120383ced5
commit cdc5d58c5b

View file

@ -70,6 +70,41 @@ def get_quote(num):
return quote.get(num) # NOQA should work even if linter complains
def process_placeholders(sender, param, text):
# Move this dictionary to a configuration file or something
# This is so bad, it runs everything every command :pikajoy:
logging.debug("Processing placeholders")
placeholders = {
"sender": sender,
"botowner": config["DEFAULT"]["BotOwner"],
"target": param,
"random": str(random.randrange(1, 100, 1)),
"commands": ", ".join(list(commands.keys())),
"aliases": ", ".join(list(aliases.keys())),
"bot_version": __version__,
"quote": get_quote(param),
"quote_parameters": "Not implemented yet",
}
for placeholder in placeholders:
findme = "{%s}" % placeholder
if findme in text:
logging.debug("Found {}".format(findme))
if placeholders[placeholder] == "":
logging.debug("Placeholder empty")
text = "%s required" % placeholder.upper()
try:
logging.debug(
"Replacing {} with {}".format(
findme, placeholders[placeholder]))
text = text.replace(
findme, placeholders[placeholder])
except TypeError:
text = "Target not specified."
return text
def process_chat(data):
sender = data["user"]["displayName"]
text = data["body"]
@ -88,29 +123,7 @@ def process_chat(data):
except IndexError:
first_parameter = None
# Move this dictionary to a configuration file or something
# This is so bad, it runs everything every command :pikajoy:
placeholders = {
"sender": sender,
"botowner": config["DEFAULT"]["BotOwner"],
"target": first_parameter,
"random": str(random.randrange(1, 100, 1)),
"commands": ", ".join(list(commands.keys())),
"aliases": ", ".join(list(aliases.keys())),
"bot_version": __version__,
"quote": get_quote(first_parameter),
"quote_parameters": "Not implemented yet",
}
for placeholder in placeholders:
findme = "{%s}" % placeholder
if findme in command_reply:
if placeholders[placeholder] == "":
command_reply = "%s required" % placeholder.upper()
try:
command_reply = command_reply.replace(
findme, placeholders[placeholder])
except TypeError:
command_reply = "Target not specified."
command_reply = process_placeholders(
sender, first_parameter, command_reply)
logging.debug("Reply: {}".format(command_reply))
return command_reply