"""A speech filter where the user thinks they're a duck. Copyright 2000 Cabochon Technologies, Inc. """ from java.lang import String, StringBuffer from java.util import StringTokenizer from wyvern.common.util import Strings from wyvern.lib.classes.filters import SpeechFilter class duck_filter(SpeechFilter): def applyFilter(self, text): # allow them to escape it if String.startsWith(text, 'Quack quack quack '): return text if String.startsWith(text, 'quack quack quack '): return text # some time down the road, I'd like to enhance the # filter to leave in punctuation, so it looks like: # "Quack quack quack, quack. QUACK! Quack quack quack." st = StringTokenizer(text) count = st.countTokens() if count == 1: return "Quack" elif count == 2: return "Quack quack." else: quacks = Strings.create('quack ', count-2) return 'Quack ' + quacks + 'quack.' # print out filter name in Python def __repr__(self): return "duck speech filter" # print out filter name in Java def toString(self): return self.__repr__() |