pep.py/objects/chatFilters.py
Nyo 653303831b IRC Support for username with spaces
BATs with Donor have bright yellow username in chat
General performance improvements
Code cleaning
Multiplayer improvements and fixes
Fixed some spectator bugs
2016-09-02 12:41:19 +02:00

33 lines
813 B
Python

class chatFilters():
def __init__(self, fileName="filters.txt"):
self.filters = {}
self.loadFilters(fileName)
def loadFilters(self, fileName="filters.txt"):
# Reset chat filters
self.filters = {}
# Open filters file
with open(fileName, "r") as f:
# 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