PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: bastya_elvtars on 06 September, 2004, 23:52:31

Title: anti-shout (rather fun)
Post by: bastya_elvtars on 06 September, 2004, 23:52:31
-- anti-shout script
-- not perfect, only detects 2+ words to minimize bugs
-- replaces uppercase with lowercase only if whole text is uppercase
-- added non-english char table, it counts only when things are needed 2 replace
-- if both words consist of non-standard chars only, it ignores (in Hungarian, its quite impossible)
-- consumes resources, use with caution
-- NB: made for hungarian and english language, but supports german IMHO (i dont speak german) - feel free to modify the table
-- bastya_elvtars (the rock n' roll doctor)

Bot="-Silence-"

locale="hun" -- change 2 your location,if you add a bad code, the script fails to start (to avoid bad locale settings causing bad work)

nonstandard={ ["Ű"]="ű",
["?"]="?",
["?"]="?",
["Ő"]="ő",
["?"]="?",
["?"]="?",
["?"]="?",
["?"]="?"
}
-- sets locale
function Main()
assert(setlocale(locale),"Bad locale!") -- does not seem 2 have influence :-/
end
-- checks data
function DataArrival(user,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
local _,_,text=strfind(data,"%b<>%s+(%S+%s+%S+.*)")
if text then
local engletters=gsub(text, "%A","")
if strfind(engletters,"(%a+)") then
if strupper(engletters)==engletters then
SendToAll(Bot,"Hmm hmm... "..user.sName.." better not shout...;)")
attenuate(user,text)  return 1
end
end
end
end
end
-- find out what this does ^^
function attenuate(user,text)
text=strlower(text)
for a,b in nonstandard do
text=gsub(text,a,b)
end
SendToAll("<"..user.sName.."> "..text)
end