-- chat_profanity - Profanity filter functions -- (component of Chat System) -- Based on MPchat Profanity Filter by Wayne Pearson -- Template attachment: chat_system -- Created by: Patrick Ferland -- Created on: 05/30/2008 -- Revision History -- 05/30/2008 P.Ferland - New Script -- 07/22/2008 P.Ferland - Commented out sync scripts -- 07/29/2008 P.Ferland - Replaced "-" system prefix with coloration -- 09/04/2008 P.Ferland - Edited list per JJD -- 10/08/2008 P.Ferland - OX friendliness pass -- 10/28/2008 P.Ferland - Removed obsolete script attachment code -- Constants PLAYER_PROFANITY_SCRIPT = '11302:20' PROFANITY = { "fuck","shit", "dick","cock","prick","penis","wang","boner","hardon", "boob","breast", "cunt","twat","vagina","clit","pussy", "asshole","bastard","bitch", "piss", "nigger","kike", "fag","faggot", } -- Script Properties Define Properties() script_description = "Chat Profanity Filter" script_long_description = "Filter profanity from chat for everyone or just for users who want filtering" chat_system_profanity_filter = 1 ExposeProperty('chat_system_profanity_filter', 'Globally filter profanity for users?', 'checkbox') PersistProperty('chat_system_profanity_filter') chat_system_profanity_filter_user_change = 1 ExposeProperty('chat_system_profanity_filter_user_change', 'Allow users to override global filter settings?', 'checkbox') PersistProperty('chat_system_profanity_filter_user_change') IncludeScript('11302:12') -- chat_utility ExportFunction('chat_system_profanity_nice') end -- Commands -- no commands -- Triggers -- system trigger, fired when scipt is attached (in builder or world start) Trigger attach() -- Register scripts for loading chat_system_register_player_script(self, PLAYER_PROFANITY_SCRIPT) SendTo(self, 'chat_system_register_command', 0, 'profanity', 'Toggle profanity filter on or off', 0, 0) end -- system trigger, fired when scipt is detached Trigger detach() -- Unregister scripts chat_system_unregister_player_script(self, PLAYER_PROFANITY_SCRIPT) SendTo(self, 'chat_system_unregister_command', 0, 'profanity') end -- Toggle profanity filter on and off, if allowed Trigger chat_msg_profanity(sender) local channel = chat_system_channel_name('user', sender.name) local message = '' if (self.chat_system_profanity_filter_user_change == 1) then if (sender.chat_system_profanity_filter == 1) then sender.chat_system_profanity_filter = 0 message = 'Profanity filter has been disabled.' else sender.chat_system_profanity_filter = 1 message = 'Profanity filter has been enabled.' end SaveToDb(sender) else message = 'Profanity settings cannot be changed.' end chat_system_send_to_subscribers(self, sender, channel, chat_system_format_system_message(message), 'profanity') chat_system_set_callback(sender, CHAT_STATUS_CODES.OK, 'OK') end -- Local functions -- profanity parsing (sub-function) function chat_system_profanity_variants(word) return {[1]=word} end -- profanity parsing (sub-function) function chat_system_profanity_alts(c) alt={ a="@", c="%[<%(", e="3", g="6", i="!1|", k="<", l="1!|", o="0", s="5$", t="+", } if alt[c] then return alt[c] else return c end end -- profanity parsing (sub-function) function chat_system_profanity_upperlower(c) return "["..chat_system_profanity_alts(string.lower(c))..string.lower(c)..string.upper(c).."](%W*)" end -- Profanity parsing (exported function) function chat_system_profanity_nice(s) local nice=string.gsub(s,"<","<") for _,word in ipairs(PROFANITY) do -- for _,variant in ipairs(variants(word)) do variant = word local pattern=string.gsub(variant,".",chat_system_profanity_upperlower) local stars="" for x=1,#word do stars = stars .. '*' .. ( x < 10 and ("%"..x) or "") end -- end nice=string.gsub(nice,pattern,stars) end return string.gsub(nice,"<","<") end