.BANCHO. .FIX. Fix chat filters
This commit is contained in:
parent
9ea11c9e0e
commit
a5fd8b0431
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
**/__pycache__
|
**/__pycache__
|
||||||
config.ini
|
config.ini
|
||||||
|
filters.txt
|
||||||
.data
|
.data
|
||||||
|
|
|
@ -296,12 +296,15 @@ def systemShutdown(fro, chan, message):
|
||||||
return restartShutdown(False)
|
return restartShutdown(False)
|
||||||
|
|
||||||
def systemReload(fro, chan, message):
|
def systemReload(fro, chan, message):
|
||||||
#Reload settings from bancho_settings
|
# Reload settings from bancho_settings
|
||||||
glob.banchoConf.loadSettings()
|
glob.banchoConf.loadSettings()
|
||||||
|
|
||||||
# Reload channels too
|
# Reload channels too
|
||||||
glob.channels.loadChannels()
|
glob.channels.loadChannels()
|
||||||
|
|
||||||
|
# And chat filters
|
||||||
|
glob.chatFilters.loadFilters()
|
||||||
|
|
||||||
# Send new channels and new bottom icon to everyone
|
# Send new channels and new bottom icon to everyone
|
||||||
glob.tokens.enqueueAll(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
|
glob.tokens.enqueueAll(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
|
||||||
glob.tokens.enqueueAll(serverPackets.channelInfoEnd())
|
glob.tokens.enqueueAll(serverPackets.channelInfoEnd())
|
||||||
|
|
38
filters.txt
38
filters.txt
|
@ -1,22 +1,16 @@
|
||||||
👍=
|
fuck=firetruck
|
||||||
👎=
|
shit=shish
|
||||||
👼=
|
ass=peach
|
||||||
😈=
|
asses=peaches
|
||||||
😀=
|
bitch=fine lady
|
||||||
😃=
|
bitches=fine ladies
|
||||||
😆=
|
asshole=donkey
|
||||||
😊=
|
ass hole=donkey
|
||||||
😍=
|
cock=chicken
|
||||||
😎=
|
cocks=chickens
|
||||||
😑=
|
dick=eggplant
|
||||||
😖=
|
dicks=eggplants
|
||||||
😗=
|
boobs=bob
|
||||||
😛=
|
tits=teeth
|
||||||
😠=
|
cum=yogurt
|
||||||
😡=
|
cunt=count
|
||||||
😥=
|
|
||||||
😬=
|
|
||||||
😭=
|
|
||||||
😮=
|
|
||||||
😯=
|
|
||||||
r/osugame=cancer
|
|
|
@ -6,9 +6,7 @@ from objects import fokabot
|
||||||
from helpers import discordBotHelper
|
from helpers import discordBotHelper
|
||||||
from helpers import userHelper
|
from helpers import userHelper
|
||||||
from events import logoutEvent
|
from events import logoutEvent
|
||||||
from events import channelJoinEvent
|
|
||||||
from constants import messageTemplates
|
from constants import messageTemplates
|
||||||
from helpers import filterHelper
|
|
||||||
|
|
||||||
def joinChannel(userID = 0, channel = "", token = None, toIRC = True):
|
def joinChannel(userID = 0, channel = "", token = None, toIRC = True):
|
||||||
"""
|
"""
|
||||||
|
@ -210,9 +208,8 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
|
||||||
# Truncate message if > 2048 characters
|
# Truncate message if > 2048 characters
|
||||||
message = message[:2048]+"..." if len(message) > 2048 else message
|
message = message[:2048]+"..." if len(message) > 2048 else message
|
||||||
|
|
||||||
# check for word filters
|
# Check for word filters
|
||||||
filters = filterHelper.chatFilters()
|
message = glob.chatFilters.filterMessage(message)
|
||||||
message = filters.checkFilters(message)
|
|
||||||
|
|
||||||
# Build packet bytes
|
# Build packet bytes
|
||||||
packet = serverPackets.sendMessage(username, toClient, message)
|
packet = serverPackets.sendMessage(username, toClient, message)
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
class chatFilters():
|
|
||||||
oldWords = () # have to use tuples as a
|
|
||||||
newWords = () # dictionary broke fairly hard.
|
|
||||||
|
|
||||||
def loadFilters(self):
|
|
||||||
filterFile = open(os.path.dirname(os.path.realpath(__file__)) + "/filters.txt", "r")
|
|
||||||
|
|
||||||
for line in filterFile:
|
|
||||||
|
|
||||||
lineSplit = line.split("=")
|
|
||||||
|
|
||||||
#self.filters[lineSplit[0]] = lineSplit[1]
|
|
||||||
self.oldWords += (lineSplit[0],)
|
|
||||||
self.newWords += (lineSplit[1].replace("\n", ""),)
|
|
||||||
|
|
||||||
|
|
||||||
def checkFilters(self, message):
|
|
||||||
if " " in message:
|
|
||||||
messageTemp = message.split(" ") # split word by spaces
|
|
||||||
else:
|
|
||||||
messageTemp = message
|
|
||||||
|
|
||||||
for word in messageTemp:
|
|
||||||
if word in self.oldWords:
|
|
||||||
oldIdx = self.oldWords.index(word)
|
|
||||||
|
|
||||||
message = message.replace(word, self.newWords[oldIdx]) # replace the bad word with our filtered word
|
|
||||||
|
|
||||||
return message
|
|
35
objects/chatFilters.py
Normal file
35
objects/chatFilters.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
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.txt
|
||||||
|
#with open(os.path.dirname(os.path.realpath(__file__)) + "/../"+fileName+".txt", "r") as f:
|
||||||
|
with open("filters.txt", "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
|
|
@ -24,6 +24,7 @@ pool = None
|
||||||
fLocks = fileLocks.fileLocks()
|
fLocks = fileLocks.fileLocks()
|
||||||
verifiedCache = {}
|
verifiedCache = {}
|
||||||
cloudflare = False
|
cloudflare = False
|
||||||
|
chatFilters = None
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
outputRequestTime = False
|
outputRequestTime = False
|
||||||
|
|
6
pep.py
6
pep.py
|
@ -19,11 +19,11 @@ from helpers import configHelper
|
||||||
from objects import glob
|
from objects import glob
|
||||||
from objects import fokabot
|
from objects import fokabot
|
||||||
from objects import banchoConfig
|
from objects import banchoConfig
|
||||||
|
from objects import chatFilters
|
||||||
from helpers import consoleHelper
|
from helpers import consoleHelper
|
||||||
from helpers import databaseHelperNew
|
from helpers import databaseHelperNew
|
||||||
from helpers import generalFunctions
|
from helpers import generalFunctions
|
||||||
from helpers import logHelper as log
|
from helpers import logHelper as log
|
||||||
from helpers import filterHelper
|
|
||||||
|
|
||||||
from handlers import mainHandler
|
from handlers import mainHandler
|
||||||
from handlers import apiIsOnlineHandler
|
from handlers import apiIsOnlineHandler
|
||||||
|
@ -109,12 +109,12 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
try:
|
try:
|
||||||
consoleHelper.printNoNl("> Loading chat filters... ")
|
consoleHelper.printNoNl("> Loading chat filters... ")
|
||||||
filters = filterHelper.chatFilters()
|
glob.chatFilters = chatFilters.chatFilters()
|
||||||
filters.loadFilters()
|
|
||||||
consoleHelper.printDone()
|
consoleHelper.printDone()
|
||||||
except:
|
except:
|
||||||
consoleHelper.printError()
|
consoleHelper.printError()
|
||||||
consoleHelper.printColored("[!] Error while loading chat filters. Make sure there is a filters.txt file present", bcolors.RED)
|
consoleHelper.printColored("[!] Error while loading chat filters. Make sure there is a filters.txt file present", bcolors.RED)
|
||||||
|
raise
|
||||||
|
|
||||||
# Create data folder if needed
|
# Create data folder if needed
|
||||||
consoleHelper.printNoNl("> Checking folders... ")
|
consoleHelper.printNoNl("> Checking folders... ")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user