PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: speedX on 29 October, 2006, 08:06:51

Title: Commands..
Post by: speedX on 29 October, 2006, 08:06:51
Is it possible to make a trigger bot like script wich shows the commands specified to all  i.e scripts & text files

Like the commands +faq , read , +myhubtime are entered in the script, and if a user type's any of these commands thn tht command will be shown to all but not the output

Hope I have not confused you'll

If already such script is available thn plzz tel me
Title: Re: Commands..
Post by: Thor on 29 October, 2006, 10:05:28
If I understand what you looking for... ;D
Title: Re: Commands..
Post by: speedX on 29 October, 2006, 11:07:15
The text file commands are not shown, so how will u come to kno abt those commands.
So I would like a script or a trigger bot wich show's the command to all when a user type's it.
This shud also work for any script if possible. And i would like a database where I can store the commands wich when typed by anyuser will be shown to all.
Like there r commands +read +hubtime.
whenever a user type's these commands all shud be able to see tht. (only command not output)
Title: Re: Commands..
Post by: Thor on 29 October, 2006, 12:19:10
Then you have to change that script, which process that command, just remove return 1 from the end of blocks. Or if just you want to see the commands, just put a line into the each scripts:
SendToNick("speedX", "<"..frmHub:GetHubBotName().."> "..curUser.sName.." used command: "..command)
Maybe the name of variables are different, but you see now, how to use it. Other solution is with an another script in the highest priority with an array which contains the commands you want to watch. If found, just write it into a file, as you want. Like this:
Code (lua) Select
tCommands={
".hubtime",
".read",
".andsoon",
}

function ChatArrival(curUser,data)
local _,_,data = string.find(data,"%b<>%s*(.*)|")
for i in ipairs(tCommands) do
if string.find(data,"^"..tCommands[i]) then
local _,_,cmd = string.find(data,"^(%S+)")
if string.find(data,"%S+%s+%S+") then
local _,_,params = string.find(data,"%S+%s*(.+)")
SaveToFile(curUser,cmd,params)
else
SaveToFile(curUser,cmd)
end
end
end
end

function SaveToFile(curUser,command,params)
local file = io.open("UsedCommands.log", "a")
if (file) then
if params then
file:write("["..os.date("%Y.%m.%d - %H:%M:%S").."] "..curUser.sName.." used command "..command.." with parameters: "..params.."\r\n")
else
file:write("["..os.date("%Y.%m.%d - %H:%M:%S").."] "..curUser.sName.." used command "..command.."\r\n")
end
end
file:close()
end

In the array you can give, what commands you want to watch. If you put a point before it, it will catch the command with all prefixes (this is the reason why I didn't use exact pattern matching).
Title: Re: Commands..
Post by: speedX on 29 October, 2006, 14:55:33
nope :( , actually i would like only a simple script in wich I store some commands of my text files and scripts. When any user type's those commands in main chat only the command shud be seen.

The script wich u gave to me just saves the time when the command was used and it doesnt show the command.
Title: Re: Commands..
Post by: Naithif on 29 October, 2006, 15:12:21
You mean something like the inbuilt !help command in PtokaX? A list of commands available per profile?
You would have to post all your commands for each specific profile you use in your hub to have someone make this for you
Title: Re: Commands..
Post by: speedX on 29 October, 2006, 16:03:40
the commands would be like +read, +hubtime, +myhubtime and remaining r my text files wich i keep changing.
Title: Re: Commands..
Post by: Thor on 29 October, 2006, 16:09:32
Code (lua) Select
if string.find(data,"%S+%s+%S+") then
local _,_,params = string.find(data,"%S+%s*(.+)")
SaveToFile(curUser,cmd,params)
SendToNick("speedX", "<"..frmHub:GetHubBotName().."> "..curUser.sName.." used command: "..command.." with parameters: "..params)
else
SaveToFile(curUser,cmd)
SendToNick("speedX", "<"..frmHub:GetHubBotName().."> "..curUser.sName.." used command: "..command)
end

Maybe this is what you want. I still don't understand what you want. (I can't dare to ask why you need this script :D)
Title: Re: Commands..
Post by: speedX on 29 October, 2006, 16:17:57
lol, Ok i am trying my best now.

There are a few scripts in my hub and text files
the command of the script cannot be seen like for eg: +read of message board and text files
There r some new members in my hub who donno any commands. When they see +read command entered by a user in main chat thn even they enter tht command to see wat is the use of it.

tht's it
I want a script wich shows the command to all so tht people would come to kno tht there is such a command. I would like a database where I will enter the commands, when any user type's any of those commands thn it will be shown to all with the help of tht script. like a trigger bot

hope I have not confused u this time. And I would like the command to be seen by all not only me..
Title: Re: Commands..
Post by: Alexinno on 29 October, 2006, 18:48:53
for the message board use this , put --return 1 instead of return 1
something like this


function MsgBoard(user, data)

local data = string.sub(data,1, -2)

local s,e,cmd = string.find(data, "%b<>%s+[%!%+%?%$%#](%S+)")

if cmd then

s,e,Prefix = string.find(data, "%b<>%s+(%p)%S+")

local tCmds = {

[Comm1] = function(user, data)

if rprofiles[user.iProfile]==1 then

SendPmToNick(user.sName, Bot, dsp1)

                                               ReadBoard(user)
                                         --return 1
                                     
     
end

end,


this will show the +read command in mainchat
and for the text files use this one

-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file exist it shows.
--
-- Converted to LUA 5 by Mutor 2/28/05
--

Bot = "???Five"
FDFolder = "texte"

function Main()
   frmHub:RegBot(Bot)
end

function ChatArrival(user, data)
   data=string.sub(data,1,string.len(data)-1)
   if( string.sub(data, 1, 1) == "<" ) then
      s,e,cmd = string.find(data,"%b<>%s+(%S+)")
      cmd = string.sub(cmd, 2,string.len(cmd))
      if io.open(FDFolder.."/"..cmd..".txt",r) ~= nil then
         showtext(user, cmd)
--return 1
      end
   end
end

function ToArrival(user, data)
    if(string.sub(data, 1, 4)) == "$To:" and (string.sub(data, 6,string.len(Bot)+5))== Bot then
        s,e,cmd = string.find(data,"^$To:%s+%S+%s+From:%s+%S+%s+%$%b<>%s+(%S+)|$")
        cmd = string.sub(cmd, 2,string.len(cmd)-1)
            if io.open(FDFolder.."/"..cmd..".txt",r) ~= nil then
                showtext(user, cmd)
--return 1
            end
   end
end

function showtext(user, file)
local contents ="\r\n\r\n"
for line in io.lines(FDFolder.."/"..file..".txt") do
    contents = contents..line.."\r\n"
    end
user:SendPM(Bot, contents.."\r\n|")
end

function showtextold(user, cmd)
local lines="\r\n\r\n"
    for line in io.lines(file) do
        lines = lines..line.."\r\n"
    end
    user:SendPM(Bot, lines.." |")
end

function OnExit()
frmHub:UnregBot(Bot)
end


i hope it's what you want...
Title: Re: Commands..
Post by: Alexinno on 29 October, 2006, 19:02:58
if you use this message board  http://forum.ptokax.org/index.php?topic=5333.0
:D
Title: Re: Commands..
Post by: Rincewind on 29 October, 2006, 19:44:42
If I understand correctly; speedX would like a script which will read a table of commands which when used will send those commands to main chat to allow all users to see them.
Title: Re: Commands..
Post by: speedX on 29 October, 2006, 19:55:49
Quote from: Rincewind on 29 October, 2006, 19:44:42
If I understand correctly; speedX would like a script which will read a table of commands which when used will send those commands to main chat to allow all users to see them.

yes.....correct
Title: Re: Commands..
Post by: Rincewind on 29 October, 2006, 20:23:57
So something like this...
---------------------------------------------------------
--  CommandDisplay by Rincewind
--  Version = v1.0.0
--  Version Date = 29/10/06
---------------------------------------------------------
tCommands = {
["read"] = 1,
["show"] = 1,
}

function ChatArrival(curUser, data)

local data = string.sub(data, 1, -2)
local s,e,cmd = nil,nil,nil
s,e,prefix,cmd = string.find(data, "%b<>%s+([%!%+%-%?%#])(%S+)")

if tCommands[cmd] == 1 then
s,e,cmd = string.find(data, "%b<>%s+[%!%+%-%?%#](.+)")
SendToAll(curUser.sName, prefix..cmd)
end

end


Just make sure any script that uses the command does a return 1 to block the script command after use or it will be sent to main twice
Title: Re: Commands..
Post by: speedX on 30 October, 2006, 08:20:32
wat is the difference ???
Title: Re: Commands..
Post by: Markitos on 30 October, 2006, 09:57:04
Quote from: speedX on 30 October, 2006, 08:20:32
wat is the difference ???
Pattern matching and local vars...
Title: Re: Commands..
Post by: speedX on 30 October, 2006, 10:09:01
???  sorry but, wat is the meaning?

It will help me to learn lua more ;)
Title: Re: Commands..
Post by: Markitos on 30 October, 2006, 10:36:24
Check the lua manual for more info.
Pattern matching are characters classes (eg: %p) used to match words, numbers, whatever you want in strings using (string.find, string.gsub, etc).
Locals are statments, like i said check the manual. It could be chinese right now =)