This forum is locked: you cannot post, reply to, or edit topics. This topic is locked: you cannot edit posts or make replies.

Page 1 of 1

Topic

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Thu Apr 15, 2010 3:25 am — Post subject: Patches

Dump yer patches here.


_________________
Have Ages, and link to them without bindings.

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Thu Apr 15, 2010 3:27 am — Post subject:

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.



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

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Thu Apr 15, 2010 8:14 pm — Post subject:

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.

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)


When I used it on this file:

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.
        }\
    )\
]


I got this file:

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.
        }\
    )\
]


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


_________________
Have Ages, and link to them without bindings.



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

Paradox

Joined: 09 May 2006

Posts: 1178

Location: British Columbia, Canada

Reply with quote

Post Posted: Thu Apr 15, 2010 8:22 pm — Post subject:

Remember that Plasma uses Python 2.3.
PotS and lower use Python 2.2.

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Thu Apr 15, 2010 9:14 pm — Post subject:

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.

Paradox

Joined: 09 May 2006

Posts: 1178

Location: British Columbia, Canada

Reply with quote

Post Posted: Fri Apr 16, 2010 3:08 am — Post subject:

hashlib does not exist in Python 2.3

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Fri Apr 16, 2010 5:27 pm — Post subject:

I'll go back and edit those posts to use the md5 module instead.


_________________
Have Ages, and link to them without bindings.

DarK

Joined: 21 May 2006

Posts: 508

Reply with quote

Post Posted: Fri Apr 16, 2010 6:21 pm — Post subject:

you could build in a profanity filter switch as well. Simple slash command for now, but it could be added into the options interface.

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Fri Apr 16, 2010 6:59 pm — Post subject:

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.

AdamJohnso

Joined: 09 May 2006

Posts: 1252

Location: Milledgeville, GA

Reply with quote

Post Posted: Fri Apr 16, 2010 8:00 pm — Post subject:

It has.

xKI.ICheckChatCommands IIRC


_________________

Pavitra

Joined: 14 Feb 2010

Posts: 157

Reply with quote

Post Posted: Sat Apr 17, 2010 3:14 am — Post subject:

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.

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.   ---------------------------------------------
+       
+       
+       

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.)

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.   ---------------------------------------------
+
+


_________________
Have Ages, and link to them without bindings.

All times are GMT

Jump to:

This forum is locked: you cannot post, reply to, or edit topics. This topic is locked: you cannot edit posts or make replies.

Page 1 of 1

You can…

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
You cannot vote in polls in this forum