Files
Breadbot/bin/profanity_regex_inserter.py

44 lines
1.5 KiB
Python

# The hidden file filed with profanity and first version of this program brought to you
# by Noah Lacorazza, rewritten from Java to Python by Brad
import json
from pathlib import Path
from breadbot_common import SQLite, MySQL
script_path = Path(__file__).resolve()
config_path = Path(script_path.parent, "config.json")
words_path = Path(script_path.parent, "Words.json")
with open(config_path, 'r') as config_file:
config_json = json.loads(config_file.read())
with open(words_path, 'r') as words_file:
words_list = json.loads(words_file.read())
if config_json["db"]["type"].casefold() == "SQLITE".casefold():
db = SQLite(Path(script_path.parent.parent, config_json["db"]["db_path"]))
else:
db = MySQL(
config_json["db"]["host"],
config_json["db"]["user"],
config_json["db"]["password"],
config_json["db"]["db_name"]
)
print(db.select("db_server", ["server_snowflake"]))
for element in db.select("db_server", ["server_snowflake"]):
for word in words_list:
regex_string = "(^|\\W|\\b)"
for i in range(len(word)):
if word[i] in config_json["profanity"]["replacers"].keys():
regex_string = regex_string + config_json["profanity"]["replacers"][word[i]] + "{1,}"
else:
regex_string = regex_string + word[i] + "{1,}"
regex_string = regex_string + "($|\\W|\\b)"
db.insert("db_message_regex", ["regex", "word", "serverServerSnowflake"], [regex_string, word, element[0]])
db.close()