import es import cPickle, os.path, psyco import cfglib, cmdlib psyco.full() info = es.AddonInfo() info.name = 'Word Filter' info.version = 'RC 1' info.url = '' info.basename = 'mod_wordFilter' info.author = 'CrAzD' es.ServerVar('private_version', info.version, info.name).makepublic() # Directory Setup dirs = {} dirs['base'] = str(es.ServerVar('eventscripts_addondir')).strip('\eventscripts').strip('addons') dirs['cfg'] = dirs['base'] + 'cfg/EventScripts/' dirs['db'] = dirs['cfg'] + 'DataBases/' for dir in dirs: if not os.path.exists(dirs[dir]): os.makedirs(dirs[dir]) cfgWords = cfglib.AddonCFG(dirs['cfg'] + 'Word Filter.cfg') cvarWords = {} cvarWords['blocked'] = cfgWords.cvar('wordsBlocked', 'poop, fart, tart, tard, caca, butthole, butt hole', 'Put the words you want blocked. \n// You only need the basic word (poop is all you need you do NOT need p00p).\n// Seperate each word with a comma!') cvarWords['type'] = cfgWords.cvar('wordsType', '*', 'This is what you want to replace blocked words with, if you put ANYTHING other than the type options that\'s what EACH character in blocked words will be.\n// Type options: random, delete, kill') cvarWords['filter'] = cfgWords.cvar('wordsFilter', '!, @, #, $, %, ^, &, *, ~, ?', 'Place the characters you want to use for the random type filter. **This is only if you have wordType set to random!**') cfgWords.write() cfgWords.execute() filter = { '0':'o', '1':'i', '!':'i', '3':'e', '4':'a' } wordList = [] filterRandom = '' replace = '' rType = '' def load(): es.addons.registerSayFilter(wordFilter) buildFilters() def unload(): es.addons.unregisterSayFilter(wordFilter) def es_map_start(eV): buildFilters() def wordFilter(user, text, team): words = text.split(' ') i = 0 for word in words: word = str(word).lower().strip(' ').strip('"') if word == ' ' or word == '' or not word: continue for tWord in wordList: if word == tWord: if rType == 'kill': return (0, None, 0) elif rType == 'delete': del words[i] i -= 1 elif rType == 'random': tStr = '' for letter in word: tStr += str(random.choice(filterRandom)) words[i] = tStr else: tStr = '' for letter in word: tStr += str(replace) words[i] = tStr break else: nWord = '' x = i while True: nWord += str(getWord(words[x])).strip('"') if nWord == tWord: toChange = (x - i) + 1 z = i while toChange > 0: if rType == 'delete': del words[i] elif rType == 'random': tStr = '' for letter in words[z].strip('"'): tStr += str(random.choice(filterRandom)) words[z] = tStr else: tStr = '' for letter in words[z].strip('"'): tStr += str(replace) words[z] = tStr z += 1 toChange -= 1 x += 1 try: next = words[x] except IndexError: break i += 1 nText = '' for word in words: nText += word.strip('"') + ' ' return (user, nText, team) def getWord(filteredWord): for number in filter: if number in filteredWord: filteredWord.replace(number, filter[number]) return filteredWord def buildFilters(): global wordList, filter, filterRandom, replace, rType wordList = str(cvarWords['blocked']).replace(', ', ',').split(',') filterRandom = str(cvarWords['filter']).replace(', ', ',').split(',') replace = cvarWords['type'] rType = str(replace).lower()