2016-08-10 10:00:33 +00:00
|
|
|
class chatFilters:
|
|
|
|
def __init__(self, fileName="filters.txt"):
|
|
|
|
self.filters = {}
|
|
|
|
self.loadFilters(fileName)
|
|
|
|
|
|
|
|
def loadFilters(self, fileName="filters.txt"):
|
|
|
|
# Reset chat filters
|
|
|
|
self.filters = {}
|
|
|
|
|
2016-08-10 10:24:41 +00:00
|
|
|
# Open filters file
|
|
|
|
with open(fileName, "r") as f:
|
2016-08-10 10:00:33 +00:00
|
|
|
# Read all lines
|
|
|
|
data = f.readlines()
|
|
|
|
|
|
|
|
# Process each line
|
|
|
|
for line in data:
|
|
|
|
# Get old/new word and save it in dictionary
|
|
|
|
lineSplit = line.split("=")
|
|
|
|
self.filters[lineSplit[0]] = lineSplit[1].replace("\n", "")
|
|
|
|
|
|
|
|
def filterMessage(self, message):
|
|
|
|
# Split words by spaces
|
|
|
|
messageTemp = message.split(" ")
|
|
|
|
|
|
|
|
# Check each word
|
|
|
|
for word in messageTemp:
|
|
|
|
# If the word is filtered, replace it
|
|
|
|
if word in self.filters:
|
|
|
|
message = message.replace(word, self.filters[word])
|
|
|
|
|
|
|
|
# Return filtered message
|
|
|
|
return message
|