this is my first script.
special thanks to Influx for his kto nolak script.
the one that blocks the message
- Code: Select all
import string
def apply_script(protocol, connection, config):
class antiswearConnection(connection):
global sweardict
sweardict = [
'duck',
'shit',
'bitch',
'bastard',
'fucking',
'penis',
'deuce',
'deuce',
'asshole',
'dick',
]
def on_chat(self, value, global_message):
message = string.lower(value)
for punc in string.punctuation:
message = message.replace(punc,"")
if any(swears in message for swears in sweardict):
self.send_chat('Your message has been blocked. Please do not swear in this server.')
return False
return connection.on_chat(self, value, global_message)
return protocol, antiswearConnection
the one that censors the message
- Code: Select all
#A 'string' is another word for a sentence or text. Here we are importing a module that can do things we need with text
import string
#Starting the script
def apply_script(protocol, connection, config):
#This is where we start creating the script
class antiswearConnection(connection):
# We're telling the script that 'sweardict' is a global variable. That means it can be used throughout the script, rather than as one local instance. We need to assign it as 'global' before we can change its value
global sweardict
# Here we are giving 'sweardict' values. If we didn't make it global above, then we couldn't do this here.
sweardict = [
'duck',
'shit',
'bitch',
'bastard',
'fucking',
'penis',
'deuce',
'deuce',
'asshole',
'dick',
]
#This is called a 'hook', and is called whenever anyone chats. We're interested in the 'value' variable, which is where the text they send is held.
def on_chat(self, value, global_message):
# Converting the message sent to lower case - as the dictionary is case sensitive, it means people can't get around it by typing swear-words in capitals or lIkE tHiS.
message = string.lower(value)
# Gets number of entries in the list of banned words
sweardictcount = len(sweardict)
# This variable is used to decide when to send the player a message about their message being filtered. Without it, it'd send to everyone who sent a message regardless of what was in it.
naughty = 0
# This assigns the values 0, 1, 2, ..., x to a variable 'n', where x is the number of entries in your list of banned words. The 'for' operator then cycles through all these values.
for n in range (sweardictcount):
# This creates a variable called 'swears', and assigns to it the nth entry in the sweardict.
#Since lists in Python start at 0 and not at 1 like you'd expect, the first entry is entry 0, the second is entry 1, etc. If n = 2, swears would = "bitch" as it's entry 3.
swears = sweardict[n]
# If the person said a naughty word...
if swears in message:
# ...then they are naughty.
naughty = 1
# This is what you filter the swearword to. It can be anything you like. Right now, it becomes "Don't worry, be happy :)".
message = message.replace(swears, '\"Don\'t worry, be happy :)\"')
# If the person is naughty... (the variable from just before)
if naughty:
# ...tell them that they are naughty.
self.send_chat('Your message has been filtered, please do not swear in this server.')
# Capitilize the sentence, since we made it all lower case earlier. This step is purely cosmetic.
value = message.capitalize()
# Returns the hook.
return connection.on_chat(self, value, global_message)
# Ends the script
return protocol, antiswearConnection
Instructions
you may think you know how to install but you have to do it this way.
1.copy and paste the code into notepad.
2.change duck to the f word and change one deuce to c*nt and the other to n*gga
3.save as "antiswear.py" in the scripts folder.
4.change the config file like normal.
5.run your server.
6.enjoy!
edit:thanks to influx for helping me make the script tidier and better!