Note: This forum is merely an archive. It is no longer possible to register or post. - StackOverflow
New Ace of Spades Forums: http://buildandshoot.com/

anti swear

Finished a script? Pop it in here.

anti swear

Postby Oshawott » Fri Aug 31, 2012 12:02 pm

anti swear prevents swearing on a server.
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!
Last edited by Oshawott on Wed Sep 26, 2012 10:13 am, edited 4 times in total.
Image
Image
Image
http://ansiart.com/ the most awesome game!
User avatar
Oshawott
Member
 
Posts: 190
Joined: Sun Aug 26, 2012 12:53 pm

Re: anti swear

Postby Influx » Fri Aug 31, 2012 9:38 pm

Thanks for using my code as a base, it's quite flattering considering I've only just started teaching myself how to Python.

However, since your use for it differs slightly from mine, there are some redundant features in your code. I've put a tidier version below (which can also get partial matches, such as, having "bitch" in the blocked word list also catches the 'bitch' in "bitches" whereas the old way wouldn't);

Code: Select all
import string
     
def apply_script(protocol, connection, config):
     
    class antiswearConnection(connection):
        global sweardict
     
        sweardict = [
'duck',
'shit',
'bitch',
'bastard',
'fucking',
'penis',
]
     
        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


For practice, and for the hell of it, I've went and created another code that doesn't block a message with a swearword in, but allows a censored version to be sent instead. I've also commented it so you can follow it through;

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',
'penis',
]
 
#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
User avatar
Influx
Member
 
Posts: 115
Joined: Thu Jan 12, 2012 11:05 pm
Location: Not France.

Re: anti swear

Postby matthew0901 » Fri Aug 31, 2012 11:54 pm

cool script but im gonna add more words to the swear list
Image
Wyvern Unknown Stage Visits Egg 6 Resource 1 Resource 2
White Aura
Dragon Scales
10 Units/DayUnknown Level Gender 1Unknown Level Progress Status 75%
Happy and content
Hatchday N/A ID: 774786
Please Click ^

Image
User avatar
matthew0901
Member
 
Posts: 106
Joined: Fri Jan 20, 2012 1:57 am
Location: In Ace Of Spades Forums

Re: anti swear

Postby Terrain » Sat Sep 01, 2012 1:21 pm

Wow really nice script. Remember to capitalize some of the code for the custom message liked "Can't".
Anyway nice script.
Might use this.
Terrain
Member
 
Posts: 23
Joined: Sat Jul 28, 2012 5:41 pm

Re: anti swear

Postby Oshawott » Sun Sep 02, 2012 5:48 am

Influx wrote:Thanks for using my code as a base, it's quite flattering considering I've only just started teaching myself how to Python.

However, since your use for it differs slightly from mine, there are some redundant features in your code. I've put a tidier version below (which can also get partial matches, such as, having "bitch" in the blocked word list also catches the 'bitch' in "bitches" whereas the old way wouldn't);

Code: Select all
import string
     
def apply_script(protocol, connection, config):
     
    class antiswearConnection(connection):
        global sweardict
     
        sweardict = [
'duck',
'shit',
'bitch',
'bastard',
'fucking',
'penis',
]
     
        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


For practice, and for the hell of it, I've went and created another code that doesn't block a message with a swearword in, but allows a censored version to be sent instead. I've also commented it so you can follow it through;

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',
'penis',
]
 
#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


Thanks!
Image
Image
Image
http://ansiart.com/ the most awesome game!
User avatar
Oshawott
Member
 
Posts: 190
Joined: Sun Aug 26, 2012 12:53 pm

Re: anti swear

Postby Dany0 » Sun Sep 02, 2012 9:29 am

Aw and my ponykicker and Sham's wordlist gets no love :(
Image
User avatar
Dany0
Member
 
Posts: 358
Joined: Mon Dec 26, 2011 7:29 pm

Re: anti swear

Postby Oshawott » Sun Sep 02, 2012 9:32 am

Dany0 wrote:Aw and my ponykicker and Sham's wordlist gets no love :(

what wordlist?
edit:but this one isnt annoying. i wanted to say my minecraft name (buggajayjay) but it comes up as huggajayjay. :P
Last edited by Oshawott on Fri Sep 07, 2012 12:52 pm, edited 1 time in total.
Image
Image
Image
http://ansiart.com/ the most awesome game!
User avatar
Oshawott
Member
 
Posts: 190
Joined: Sun Aug 26, 2012 12:53 pm

Re: anti swear

Postby EssigGurkenFred » Mon Sep 03, 2012 12:49 pm

Cool script, but now you have to get the server admins using it :P
User avatar
EssigGurkenFred
Member
 
Posts: 1370
Joined: Tue Jan 31, 2012 6:47 pm
Location: At Home

Re: anti swear

Postby Oshawott » Tue Sep 04, 2012 12:11 pm

EssigGurkenFred wrote:Cool script, but now you have to get the server admins using it :P

I know right.
:P
Image
Image
Image
http://ansiart.com/ the most awesome game!
User avatar
Oshawott
Member
 
Posts: 190
Joined: Sun Aug 26, 2012 12:53 pm

Re: anti swear

Postby SuperDaniel » Wed Sep 26, 2012 3:14 pm

How'd you go, did you add some more words to it mate?
IGN: [F4TAL]Daniel
Clan: [F4TAL]

Joined: July 27th
Rank: Leader
Server: aos://2027543882:32887
Test Server: aos://2228601799:32887
Average Ratio: 5.00


Image
Image
User avatar
SuperDaniel
Member
 
Posts: 783
Joined: Fri Jul 27, 2012 10:49 am
Location: Australia, WA

Re: anti swear

Postby Oshawott » Thu Sep 27, 2012 12:34 am

yes read the new instructions
Image
Image
Image
http://ansiart.com/ the most awesome game!
User avatar
Oshawott
Member
 
Posts: 190
Joined: Sun Aug 26, 2012 12:53 pm


Return to Script releases



Who is online

Users browsing this forum: No registered users and 1 guest

cron