It is currently Fri Jan 19, 2018 5:24 am

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Patches
PostPosted: Thu Apr 15, 2010 3:25 am 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
Dump yer patches here.

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Apr 15, 2010 3:27 am 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
Here's one of my own, intended to be applied against python/plasma/ptWordFilter.py:

Code:
5a6
> import md5
36c37
<                         rating = self.wordlist[string.lower(sentence[startidx:endidx])]
---
>                         rating = self.wordlist[md5.new(string.lower(sentence[startidx:endidx])).hexdigest()]
47c48
<                 rating = self.wordlist[string.lower(sentence[startidx:])]
---
>                 rating = self.wordlist[md5.new(string.lower(sentence[startidx:])).hexdigest()]
66c67
<                         rating = self.wordlist[string.lower(sentence[startidx:endidx])]
---
>                         rating = self.wordlist[md5.new(string.lower(sentence[startidx:endidx])).hexdigest()]
82c83
<                 rating = self.wordlist[string.lower(sentence[startidx:])]
---
>                 rating = self.wordlist[md5.new(string.lower(sentence[startidx:])).hexdigest()]


This should allow wordfilter lists (definitions of what words are considered naughty) to be distributed without actually distributing the bad words themselves in any retrievable form. Note that it would completely break any plaintext wordfilter lists.

For example, after making the following changes to xCensorFilters.py:

Code:
14c14,15
<             "anotherreallybadword"  : Rating(xRatedR)\
---
>             "anotherreallybadword"  : Rating(xRatedR),\
>             "41a41e087a065a83ef79950a2deb6c28"  : Rating(xRatedR)\


I was able to produce the following python session:

Code:
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path += ['./plasma']
>>> import xCensor
>>> xCensor.xCensor("this is a test xxxbadxxx reallybadword hashedbadword", 1)
'this is a test ***** reallybadword *****'
>>>


Note that hashing only affects ExactMatchListFilter-ed words, not REFilter-ed words.


edit: Just to be clear: Cyan can do whatever they want with any contributions I submit to this forum, including but not limited to:
  • preparing modified versions and derivative works
  • redistributing modified or unmodified copies; whether gratis, at loss, at cost, or at profit; with or without attribution
  • and/or relicensing/sublicensing.

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Last edited by Pavitra on Fri Apr 16, 2010 5:29 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Apr 15, 2010 8:14 pm 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
The following script should automatically convert unhashed wordfilter files to hashed wordfilter files. Note that the process is, by design, irreversible. Don't lose the original (input) file.

[spoiler=Script.]
Code:
#!/usr/bin/python


"""
This script converts a wordfilter file (xCensorFilters.py) from unhashed to
hashed format.
"""


import sys
import os
import string
import md5


num_args = len(sys.argv)
if num_args != 3:
        print "Usage: ./xuHashifyWordfilter infile > outfile"
        sys.exit(1)

if sys.argv[1] == sys.argv[2]:
        print "Error: infile and outfile are the same. Aborting."
        sys.exit(2)

if not os.path.isfile(sys.argv[1]):
        print "Error:", sys.argv[1], "is not a file. Aborting."
        sys.exit(3)

if os.path.exists(sys.argv[2]):
        print "Error:", sys.argv[2], "exists. Aborting."
        sys.exit(4)


with open(sys.argv[1], 'r') as f1:
        text = f1.read()


intext = string.split(text, '\n')
outtext = ""

section_found = False
for line in intext:
        if section_found:
                if string.find(line, "\"") >= 0:
                        splitline = string.split(line, "\"", 2)
                        hashedline = splitline[0] + "\"" + md5.new(splitline[1]).hexdigest() + "\"  " + string.lstrip(splitline[2], " ")
                        outtext += hashedline + "\n"
                else:
                        outtext += line + "\n"

        elif string.find(line, "ExactMatchListFilter") >= 0:
                section_found = True
                outtext += line + "\n"

        else:
                outtext += line + "\n"

with open(sys.argv[2], 'w') as f2:
        f2.write(outtext)
[/spoiler]

When I used it on this file:

[spoiler=Infile.]
Code:
"""
This module contains all the strings that need to localized for the Censor

This is not the real module... it is just here for compiling
"""

from ptWordFilter import *

xSentenceFilters = [\
    REFilter( r'xxxbadxxx', Rating(xRatedX) ),\
    ExactMatchListFilter(\
        {
                #reallybadword
            "reallybadword"         : Rating(xRatedR),\
                #anotherreallybadword
            "anotherreallybadword"  : Rating(xRatedR),\
                #hashedbadword
            "hashedbadword"         : Rating(xRatedR)\
                # A 'real' badwords file wouldn't have these comments
                # telling you what the hashes stand for.
        }\
    )\
]
[/spoiler]

I got this file:

[spoiler=Outfile.]
Code:
"""
This module contains all the strings that need to localized for the Censor

This is not the real module... it is just here for compiling
"""

from ptWordFilter import *

xSentenceFilters = [\
    REFilter( r'xxxbadxxx', Rating(xRatedX) ),\
    ExactMatchListFilter(\
        {
                #reallybadword
            "618acd2e63b8c9ebe3e6bea721c6069f"  : Rating(xRatedR),\
                #anotherreallybadword
            "2f8d6919273625e3e301d793b90f412e"  : Rating(xRatedR),\
                #hashedbadword
            "41a41e087a065a83ef79950a2deb6c28"  : Rating(xRatedR)\
                # A 'real' badwords file wouldn't have these comments
                # telling you what the hashes stand for.
        }\
    )\
]
[/spoiler]

which then tested correctly as censoring "reallybadword" to "*****".

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Last edited by Pavitra on Fri Apr 16, 2010 5:29 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Apr 15, 2010 8:22 pm 
Offline

Joined: Tue May 09, 2006 12:33 am
Posts: 1182
Location: British Columbia, Canada
Remember that Plasma uses Python 2.3.
PotS and lower use Python 2.2.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Apr 15, 2010 9:14 pm 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
I have no idea how to deal with that, so I'm mentally filing it under "known issues, wontfix".

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 16, 2010 3:08 am 
Offline

Joined: Tue May 09, 2006 12:33 am
Posts: 1182
Location: British Columbia, Canada
hashlib does not exist in Python 2.3


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 16, 2010 5:27 pm 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
I'll go back and edit those posts to use the md5 module instead.

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 16, 2010 6:21 pm 
Offline

Joined: Sun May 21, 2006 11:51 am
Posts: 510
you could build in a profanity filter switch as well. Simple slash command for now, but it could be added into the options interface.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 16, 2010 6:59 pm 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
I don't think the code that's been released so far includes the parts that would need to be changed to add a new /command.

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Apr 16, 2010 8:00 pm 
Offline
Obduction Backer

Joined: Tue May 09, 2006 4:41 pm
Posts: 1660
Location: South Georgia
It has.

xKI.ICheckChatCommands IIRC

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Apr 17, 2010 3:14 am 
Offline
Obduction Backer

Joined: Sun Feb 14, 2010 7:53 pm
Posts: 157
Sweet. Thanks, AdamJohnso.

I wasn't able to test this, because xKI depends on a bunch of stuff that isn't present like xRPSEnglish, but here's the patch.

[spoiler=This is wrong. Preserved for historical interest.]
Code:
diff --git a/python/xKI.py b/python/xKI.py
index 3a051ec..6c0b94d 100644
--- a/python/xKI.py
+++ b/python/xKI.py
@@ -292,0 +293 @@ gFeather = 0
+userdefined_CensorRating = xCensor.xRatedG
@@ -6662,0 +6664,43 @@ class xKI(ptModifier):
+       
+       
+       
+        # New stuff starts here. ---------------------------------------------
+       
+        # A quick rgrep didn't turn up the definition of PtGetLocalizedString,
+        # only a forward-declaration, so I won't be using it.
+        # Sorry, non-English-speakers. :(
+       
+        if string.lower(chatmessage).startswith("/rating x"):
+                if AmICCR:
+                        userdefined_CensorRating = xCensor.xRatedX
+                        self.IAddRTChat(None, "Wordfilter rating set to X.", kChatSystemMessage)
+                else:
+                        userdefined_CensorRating = xCensor.xRatedR
+                        self.IAddRTChat(None, "Wordfilter rating set to R.", kChatSystemMessage)
+               return None
+        if string.lower(chatmessage).startswith("/rating r"):
+                userdefined_CensorRating = xCensor.xRatedR
+                self.IAddRTChat(None, "Wordfilter rating set to R.", kChatSystemMessage)
+               return None
+        if string.lower(chatmessage).startswith("/rating pg13") or string.lower(chatmessage).startswith("/rating pg-13"):
+                userdefined_CensorRating = xCensor.xRatedPG13
+                self.IAddRTChat(None, "Wordfilter rating set to PG-13.", kChatSystemMessage)
+               return None
+        if string.lower(chatmessage).startswith("/rating pg"):
+                userdefined_CensorRating = xCensor.xRatedPG
+                self.IAddRTChat(None, "Wordfilter rating set to PG.", kChatSystemMessage)
+               return None
+        if string.lower(chatmessage).startswith("/rating g"):
+                userdefined_CensorRating = xCensor.xRatedG
+                self.IAddRTChat(None, "Wordfilter rating set to G.", kChatSystemMessage)
+               return None
+        if string.lower(chatmessage).startswith("/rating"):
+                # Command recognized, but argument(s) missing or invalid.
+                self.IAddRTChat(None, "Usage: /rating <rating>\nValid ratings are G, PG, PG-13, R.", kChatSystemMessage)
+               return None
+               
+       
+        # New stuff ends here.   ---------------------------------------------
+       
+       
+       
[/spoiler]
I put the prefix userdefined_ on my variable to minimize the chance of collision with anything Cyan does.

(Edit: the command doesn't actually do anything yet. Working on that.)

(Edit 2: I just realized I did this completely wrong in every way. Starting over.)

(Edit 3: This should -- no, might -- work. Again, I have no way to test.)

[spoiler=Click to embiggen.]
Code:
diff --git a/python/xKI.py b/python/xKI.py
index 3a051ec..e79716e 100644
--- a/python/xKI.py
+++ b/python/xKI.py
@@ -6662,0 +6663,46 @@ class xKI(ptModifier):
+
+
+        # New stuff begins here. ---------------------------------------------
+
+        # A quick rgrep didn't turn up the definition of PtGetLocalizedString,
+        # only a forward-declaration, so I won't be using it.
+        # Sorry, non-English-speakers. :(
+       
+        if string.lower(chatmessage).startswith("/rating x"):
+                if AmICCR:
+                        theCensorLevel = xCensor.xRatedX
+                        self.ISaveCensorLevel(None)
+                        self.IAddRTChat(None, "Wordfilter rating set to X.", kChatSystemMessage)
+                else:
+                        theCensorLevel = xCensor.xRatedR
+                        self.ISaveCensorLevel(None)
+                        self.IAddRTChat(None, "Wordfilter rating set to R.", kChatSystemMessage)
+                return None
+        if string.lower(chatmessage).startswith("/rating r"):
+                theCensorLevel = xCensor.xRatedR
+                self.ISaveCensorLevel(None)
+                self.IAddRTChat(None, "Wordfilter rating set to R.", kChatSystemMessage)
+                return None
+        if string.lower(chatmessage).startswith("/rating pg13") or string.lower(chatmessage).startswith("/rating pg-13"):
+                theCensorLevel = xCensor.xRatedPG13
+                self.ISaveCensorLevel(None)
+                self.IAddRTChat(None, "Wordfilter rating set to PG-13.", kChatSystemMessage)
+                return None
+        if string.lower(chatmessage).startswith("/rating pg"):
+                theCensorLevel = xCensor.xRatedPG
+                self.ISaveCensorLevel(None)
+                self.IAddRTChat(None, "Wordfilter rating set to PG.", kChatSystemMessage)
+                return None
+        if string.lower(chatmessage).startswith("/rating g"):
+                theCensorLevel = xCensor.xRatedG
+                self.ISaveCensorLevel(None)
+                self.IAddRTChat(None, "Wordfilter rating set to G.", kChatSystemMessage)
+                return None
+        if string.lower(chatmessage).startswith("/rating"):
+                # Command recognized, but argument(s) missing or invalid.
+                self.IAddRTChat(None, "Usage: /rating <rating>\nValid ratings are G, PG, PG-13, R.", kChatSystemMessage)
+                return None
+       
+        # New stuff ends here.   ---------------------------------------------
+
+
[/spoiler]

_________________
Have Ages, and link to them without bindings. [Words 1:13]
Seltani


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron