PtokaX forum

Archive => Archived 5.1 boards => Finished Scripts => Topic started by: UwV on 04 July, 2006, 08:45:54

Title: commandssweeper.lua & txtlist.lua merged (LUA 5.1)
Post by: UwV on 04 July, 2006, 08:45:54
hope someone can use it ..


------------------------------------------------------------------
-- merged  commandssweeper.lua & txtlist.lua (lua 5.1)
-----------------------------------------------------------------
-- CommandsSweeper LUA 5.1 UwV
-- this script will keep mainchat clean of chatlines starting with any punctuation characters.
-- it will send a message to user when it blocks the message
-- it will let pass default commands for ptokax3.5.0 and your own from table.
-- it will also let pass any prefixes you desire to let pass from the other table.. .. pretty easy to edit ..
---------------
-- txtlist.lua
--  simple script to (auto) update txtfiles commands -- (made it a while ago now needed to let them pass the sweeper .. )
--  and show the list of commands to user on command
--  (works only if you have txtxfiles enabled in PtokaX gui)
-- * changed from previous version,
--  creates a .txt file in " /PtokaX/txts/ " ..(and showing of list handled by PtokaX now)
-----------------------------------------------------------------------
--
-- credits :
--
--  %plop for the %p (i would have never though of that , really..)
--  deep-goa for reportng the !reggingrules command to return "Error Unknown command" and make me see my error..
------------------------
-- setting .txt bot

sTxtCmd = "txtlist"   -- command that show the txtlist (no prefix)
sHubPref = "!"    --set the prefered prefix for your hub here

sHelpTrigg = "help" -- trigger that show the help line..
sHelpLine = "\t"..sHubPref..sTxtCmd.." \t - Shows a list of available .txt commands." -- line to show on trigger.


iAutoupdate = 1 -- enable auto updating ( 1 = yes  nil = no)
iUpdateInterval  = 17   -- update dirlist.txt  every in minutes

-- settings commandsweeper-bot

-- two part message to user on sweeped command..
sMsgNoCmd = "Error unknown command :" -- before the sweeped command  ( use :   "<LooksLikeNickorBot> Error : " to make it look like msg from nick or bo).
sMsgNoCmd2 = "try "..sHubPref..sHelpTrigg.." for more help." -- after the sweped command

--  these prefixes pass by the sweeper
tLetPass ={
["-"] = 1,
-- ["!"] = 1, -- ( like this they don't )
-- [":"] = 1,
-- ["."] = 1,
["*"] = 1,
[";"] = 1,
}

--  these 'commands' pass by the sweeper add/delete here if desired
tCommands = {
["0)"] = 1,
["0p"] = 1,
["0("] = 1,
["-)"] = 1,
["-p"] = 1,
["-("] = 1,
["trivstart"] = 1,
["trivstop"] = 1,
}

-- these 'must'  pass by .. (the inbuild ptokax commands .)
tPXCommands ={
["me"] = 1,
["myip"] = 1,
["etc.etc."] = 1,
}


--------------------------
-- end of settings.
--------------------------


-----------------------------------------------------------------
-- this is "what file"
sFileName = frmHub:GetPtokaXLocation().."texts/"..sTxtCmd..".txt"
tTriggers = {}

function fMakeList()
-- clear table.
tTriggers = {}
local h = io.open( sFileName, "r" ) -- open our file and read it
for line in h:lines() do -- add triggers from file
if string.find ( line,"^(%S+)%.txt$" ) then
local _,_,sTrigger = string.find( line,"^([^%.]+)" )

tTriggers[sTrigger] = 1
end
end
h:close()
fSaveTxtFile()
-- dont save these but add custom/ptokax triggers to table to pass the sweeper.
for i,v in pairs(tCommands) do
tTriggers[i] = 1
end
for i,v in pairs(tPXCommands) do
tTriggers[i] = 1
end
tTriggers[sTxtCmd] = 1
end

function fSaveTxtFile()
local h = io.open( sFileName, "w+") -- open same file we created and overwrite with the .txt we want to show.
h:write("K'well here you go then,..\n ---------- Your Available .txt Commands ---------\n\n")
for i,v in pairs(tTriggers) do
h:write("\t"..sHubPref..i.."\n")
end
h:write("\n ----------  Please Use them. ---------\n ")
h:close()
io.flush()
end

function OnTimer()
sDirPath = frmHub:GetPtokaXLocation().."texts/"
-- show no -Dir's,  no -S ystem and no -H idden files in /Bare format /Ordered by: /Name  and > dump output to file.
os.execute("dir \""..sDirPath.."\" /A-D-S-H /B /O:N > "..sFileName.."")
fMakeList()
end

function ChatArrival(curUser, sData)
local _,_, pFix, sCmd = string.find(sData,"^%b<>%s(%p)(%S+).*|")
if pFix and sCmd then
local sCmdlow = string.lower(sCmd)
if sCmdlow == sHelpTrigg then
curUser:SendData(sHelpLine)
return 0;
elseif tLetPass[pFix] or tTriggers[sCmdlow] then
return 0;
else
SendToNick(curUser.sName, sMsgNoCmd.."\r\n  "..pFix..sCmd.."\r\n  "..sMsgNoCmd2.."\r\n ")
return 1;
end
end
end


function Main()
if iAutoupdate then
SetTimer(60000 * iUpdateInterval)
StartTimer()
end
OnTimer()
end
Title: Re: commandssweeper.lua & txtlist.lua merged (LUA 5.1)
Post by: UwV on 04 July, 2006, 09:16:52
ps. you wil need to do :

!reloadtxt  --  (reload all textfiles)  to make the txtlist  command work.
Title: Re: commandssweeper.lua & txtlist.lua merged (LUA 5.1)
Post by: Markitos on 04 July, 2006, 10:23:12
Bug...
h:write"K'well here you go then,..\n ---------- Your Available .txt Commands ---------\n\n"

Another one
local h = io.open(sFileName, "r" ) -- open our file and read it (WHAT FILE???)

Plus you could remove (%S+) and add (%w+) [alphanumeric pattern] in
if string.find ( line,"^(%S+)%.txt$" ) then and in the chatarrival

You could remove the attach and keep the script no need to have 2...
Title: Re: commandssweeper.lua & txtlist.lua merged (LUA 5.1)
Post by: UwV on 04 July, 2006, 11:42:57
Quote from: Markitos on 04 July, 2006, 10:23:12
Bug...h:write"K'well here you go then,..\n ---------- Your Available .txt Commands ---------\n\n"
true.. ( and  Fixed)  thanks for report. somehow it gave no errors and i didn't even notice.. ..

Quote from: Markitos on 04 July, 2006, 10:23:12
Another one
local h = io.open(sFileName, "r" ) -- open our file and read it (WHAT FILE???)
just read  5 line above....
sFileName = frmHub:GetPtokaXLocation().."texts/"..sTxtCmd..".txt"
so  that is not a bug. it gets created in function OnTimer() (unorthodxly called in funtion Main And ther is no setting for it) .. maybe confusing on a hot summer day ?


Quote from: Markitos on 04 July, 2006, 10:23:12
Plus you could remove (%S+) and add (%w+) [alphanumeric pattern] in
if string.find ( line,"^(%S+)%.txt$" ) then and in the chatarriva l
well that depends on the desired effect it works like i want it i aimed at all chars (but spaces)..and well if there is no " may-2005_all.txt " etc. then yes.
Quote from: Markitos on 04 July, 2006, 10:23:12
You could remove the attach and keep the script no need to have 2...
yeye i could but then again .. is nice ilike this not ? some people prefer to download it and it aint all that big .. so for some it is nice to read before.

wow it's hot today ..
Title: version b
Post by: UwV on 06 July, 2006, 13:05:54
-- version b
-- added table for .txt files to show in main to all users

------------------------------------------------------------------
-- merged  commandssweeper.lua & txtlist.lua (lua 5.1)
-----------------------------------------------------------------------
-- credits :
--
--  DEEP-GOA as ever
--     &
--   %plop for the %p (i would have never thought of that myself, really not..)
--
-----------------------------------------------------------------=
-- CommandsSweeper LUA 5.1 UwV
-- this script will keep mainchat clean of chatlines starting with any punctuation characters. 
-- it will send a message to user when it blocks the message
-- it will let pass default commands for ptokax3.5.0 and your own from table.
-- it will also let pass any prefixes you desire to let pass from the other table.. .. pretty easy to edit ..
---------------
-- txtlist.lua (lua 5.1)
-- (made it long time ago now needed to let them pass the sweeper .. )
--  simple script to (auto) update txtfiles commands
--  and show the list of commands to user on command
--  (works only if you have txtxfiles enabled in PtokaX gui)
-- * changed from previous version,
--  creates a .txt file in " /PtokaX/txts/ " ..(and showing of list handled by ptoax now)
-----------------------------------------------------------------------
-- version b
-- added table for .txt files to show in main to all users requested by .. i forgot .. sorry.
-----------------------------------------------------------------------
--
-- credits :
--
--  %plop for the %p (i would have never though of that , really..)
--  deep-goa for reportng the !reggingrules command to return "Error Unknown command" and make me see my error..
------------------------
-- setting .txt bot
sBotName = frmHub:GetHubBotName()..".txt" -- ;0)

sTxtCmd = "txtlist"   -- command that show the txtlist (no prefix)
sHubPref = "!"    --set the prefered prefix for your hub here

sHelpTrigg = "help" -- trigger that show the help line..
sHelpLine = "\t"..sHubPref..sTxtCmd.." \t - Shows a list of available .txt commands." -- line to show on trigger.


iAutoupdate = 1 -- enable auto updating ( 1 = yes  nil = no)
iUpdateInterval  = 17   -- update dirlist.txt  every in minutes

-- Botname used for showing files in main to all
sBotName = frmHub:GetHubBotName() or "TEXT-BOT"
--  these .txt files will show in main to all users
--  the files must be in "ptokax_root/texts/"

tShowToAll = {
["coffee"] = 1,   --  use only the name (without .txt)
["night.txt"] = 1,
["add_your_own"] = 1,
["as_many as_you_like"] = 1,
}

-- settings commandsweeper-bot

-- two part message to user on sweeped command..
sMsgNoCmd = "Error unknown command :" -- before the sweeped command
sMsgNoCmd2 = "try "..sHubPref..sHelpTrigg.." for more help." -- after the sweped command

--  these prefixes pass by the sweeper
tLetPass ={
["-"] = 1,
-- ["!"] = 1, -- ( like this they don't )
-- [":"] = 1,
-- ["."] = 1,
["*"] = 1,
[";"] = 1,
}

--  these 'commands' pass by the sweeper add/delete here if desired
tCommands = {
["0)"] = 1,
["0p"] = 1,
["0("] = 1,
["-)"] = 1,
["-p"] = 1,
["-("] = 1,
["trivstart"] = 1,
["trivstop"] = 1,
}

-- these 'must'  pass by .. (the inbuild ptokax commands .)
tPXCommands ={
["me"] = 1,
["myip"] = 1,
["passwd"] = 1,
["etc."] = 1,
["etcetc."] = 1,
["download_script_if_you_Are_lazy:0P"] = 1,
}


--------------------------
-- end of settings.
--------------------------


-----------------------------------------------------------------

sFileName = frmHub:GetPtokaXLocation().."texts/"..sTxtCmd..".txt"
tTriggers = {}

function fMakeList()
-- clear table.
tTriggers = {}
local h = io.open( sFileName, "r" ) -- open our file and read it
for line in h:lines() do -- add triggers from file
if string.find ( line,"^(%S+)%.txt$" ) then
local _,_,sTrigger = string.find( line,"^([^%.]+)" )
tTriggers[string.lower(sTrigger)] = 1
end
end
h:close()
fSaveTxtFile()
-- dont save these but add custom/ptokax triggers to table to pass the sweeper.
for i,v in pairs(tCommands) do
tTriggers[string.lower(i)] = 1
end
for i,v in pairs(tPXCommands) do
tTriggers[i] = 1
end
tTriggers[sTxtCmd] = 1
end

function fSaveTxtFile()
local h = io.open( sFileName, "w+") -- open same file we created and overwrite with the .txt we want to show.
h:write("K'well here you go then,..\n ---------- Your Available .txt Commands ---------\n\n")


for i,v in pairs(tTriggers) do
if tShowToAll[i] then

h:write("\t"..sHubPref..i.."\t   ** shows to all users in mainchat\n")
else
h:write("\t"..sHubPref..i.."\n")
end
end

h:write("\n ----------  Please Use them. ---------\n ")
h:close()
io.flush()
end

function OnTimer()
sDirPath = frmHub:GetPtokaXLocation().."texts/"
-- show no -Dir's,  no -S ystem and no -H idden files in /Bare format /Ordered by: /Name  and > dump output to file.
os.execute("dir \""..sDirPath.."\" /A-D-S-H /B /O:N > "..sFileName.."")
fMakeList()
end

function ChatArrival(curUser, sData)
local _,_, pFix, sCmd = string.find(sData,"^%b<>%s(%p)(%S+).*|")
if pFix and sCmd then
local sCmdlow = string.lower(sCmd)

if tShowToAll[sCmdlow] then
local sMsg = "\r\n"..curUser.sName.." want to say..\r\n"
for line in io.lines(frmHub:GetPtokaXLocation().."texts/"..sCmdlow..".txt") do
sMsg = sMsg..line.."\r\n"
end
SendToAll(sBotName, sMsg)
return 1
elseif sCmdlow == sHelpTrigg then
curUser:SendData(sHelpLine)
return 0;
elseif tLetPass[pFix] or tTriggers[sCmdlow] then
return 0;
else
SendToNick(curUser.sName, sMsgNoCmd.."\r\n  "..pFix..sCmd.."\r\n  "..sMsgNoCmd2.."\r\n ")
return 1;
end
end
end


function Main()
if iAutoupdate then
SetTimer(60000 * iUpdateInterval)
StartTimer()
end
OnTimer()
end

N.B. for this to work you will need to :
!reloadtxt  --  (reload all textfiles)  to make the txtlist  command work and to refresh the files in ptokax memory if changed.
+ you will want to run this scipt as very last (bottom) or it will eat commands for other scripts.
Title: Re: commandssweeper.lua & txtlist.lua merged (LUA 5.1)
Post by: Markitos on 06 July, 2006, 17:58:20
Quote from: UwV on 04 July, 2006, 11:42:57
Quote from: Markitos on 04 July, 2006, 10:23:12
Bug...h:write"K'well here you go then,..\n ---------- Your Available .txt Commands ---------\n\n"
true.. ( and  Fixed)  thanks for report. somehow it gave no errors and i didn't even notice.. ..

Quote from: Markitos on 04 July, 2006, 10:23:12
Another one
local h = io.open(sFileName, "r" ) -- open our file and read it (WHAT FILE???)
just read  5 line above....
sFileName = frmHub:GetPtokaXLocation().."texts/"..sTxtCmd..".txt"
so  that is not a bug. it gets created in function OnTimer() (unorthodxly called in funtion Main And ther is no setting for it) .. maybe confusing on a hot summer day ?


Quote from: Markitos on 04 July, 2006, 10:23:12
Plus you could remove (%S+) and add (%w+) [alphanumeric pattern] in
if string.find ( line,"^(%S+)%.txt$" ) then and in the chatarriva l
well that depends on the desired effect it works like i want it i aimed at all chars (but spaces)..and well if there is no " may-2005_all.txt " etc. then yes.
Quote from: Markitos on 04 July, 2006, 10:23:12
You could remove the attach and keep the script no need to have 2...
yeye i could but then again .. is nice ilike this not ? some people prefer to download it and it aint all that big .. so for some it is nice to read before.

wow it's hot today ..
Lol UwV its hot indeed...
Title: version C
Post by: UwV on 08 July, 2006, 15:58:04
-----------------------------------------------------------------------
-- version c
-- added sends text commands to rightclcik menu
-----------------------------------------------------------------------



-- same as posts above. .. well i added one line i did

for line in h:lines() do -- add triggers from file
if string.find ( line,"^(%S+)%.txt$" ) then
local _,_,sTrigger = string.find( line,"^([^%.]+)" )
tTriggers[string.lower(sTrigger)] = 1
tClickTriggers[sTrigger] = 1   -- .. here this one
end
end


--------
-- new :

sMenuName = "{-Antenna17-}" -- menuname for rightclickmenu
sSubMenuName = ".txt files"  -- sub menu name

function NewUserConnected(curUser)
fSendCommands(curUser)
end

OpConnected = NewUserConnected

function fSendCommands(curUser)
curUser:SendData("$UserCommand 1 1 "..sMenuName.."\\"..sSubMenuName.."\\* shows in main to all$<%[mynick]> !"..sTxtCmd.."&#124;")
for i,v in pairs(tClickTriggers) do
if tShowToAll[i] then
curUser:SendData("$UserCommand 1 1 "..sMenuName.."\\"..sSubMenuName.."\\"..i.." *$<%[mynick]> "..sHubPref..i.."&#124;")
else
curUser:SendData("$UserCommand 1 1 "..sMenuName.."\\"..sSubMenuName.."\\"..i.."$<%[mynick]> "..sHubPref..i.."&#124;")
end
end
curUser:SendData("$UserCommand 1 1 "..sMenuName.."\\"..sSubMenuName.."\\All other show in PM to YOU$<%[mynick]> "..sHubPref..sTxtCmd.."&#124;")
if curUser.bOperator then
curUser:SendData("$UserCommand 1 1 "..sMenuName.."\\"..sSubMenuName.."\\Reload .txt Files$<%[mynick]> "..sHubPref.."reloadtxt&#124;")
end
end