Hi,
I wanted to edit this script for commands in main (not PM to bot).
Example: Somebody writes in main
!addtofile test test test
And this text writes to a file
If somebody writes in main !readfromfile , bot sends a PM to him
[19:42] 14:21 22.08.2004 NemeziS added to file: test test test
botname = "Joker"
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end
function Main()
frmHub:RegBot(botname)
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (cmd=="!addtofile") then
arg= GetArgs(data)
local handle=openfile("file.dat","a")
write(handle," "..date("%H:%M").." "..date("%d").."."..date("%m")..".20"..date("%y").." "..user.sName.." added to file"..arg.."?")
user:SendPM(botname,"added to file....")
closefile(handle)
end
if (cmd=="!readfromfile") then
handle2=openfile("file.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end
end
end
end
end
Who can edit and test it for me? =)
i change it to send it to main if i understud you right...
============================================
edited by DJ-Valhala To Send to main-chat insted of PM
============================================
botname = "Joker"
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end
function Main()
frmHub:RegBot(botname)
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (cmd=="!addtofile") then
arg= GetArgs(data)
local handle=openfile("file.dat","a")
write(handle," "..date("%H:%M").." "..date("%d").."."..date("%m")..".20"..date("%y").." "..user.sName.." added to file"..arg.."?")
user:SendData(botname,"added to file....")
closefile(handle)
end
if (cmd=="!readfromfile") then
handle2=openfile("file.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendData(botname,linearray[i])
end
closefile(handle2)
end
end
end
end
end
No... You misunderstood me :) I wanted this script work if I write this commands to main!
And the text appears in PM window (like by default SendPM)... Understand? :)))
i think i dont know how to do that but i'm sure that the guys here will do that for ya ;)
-- modded for NemeziS by bastya_elvtars (the rock n' roll doctor)
botname = "Joker"
function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)" gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end
function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end
function Main()
frmHub:RegBot(botname)
end
function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
local s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
if (cmd=="!addtofile") then
arg= GetArgs(data)
local handle=openfile("file.dat","a")
write(handle," "..date("%H:%M").." "..date("%d").."."..date("%m")..".20"..date("%y").." "..user.sName.." added to file"..arg.."?")
user:SendData(parseenv(user,"PM",botname).."added to file....")
closefile(handle)
elseif (cmd=="!readfromfile") then
handle2=openfile("file.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end
end
end
elseif strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
if (cmd=="!addtofile") then
arg= GetArgs(data)
local handle=openfile("file.dat","a")
write(handle," "..date("%H:%M").." "..date("%d").."."..date("%m")..".20"..date("%y").." "..user.sName.." added to file"..arg.."?")
user:SendData(parseenv(user,"PM",botname).."added to file....")
closefile(handle)
elseif (cmd=="!readfromfile") then
handle2=openfile("file.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray[i])
end
closefile(handle2)
end
end
end
end
function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end
I hope this is what you wanted.
You didn't understand me at all! :))
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
local s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
this is a line from script that configs a PM to bot.
If the command was sent to bot's PM this service works.
By default this bot don't do anything if the command send to main. It works only in PM.
I don't want bot to check if the comand was sent to bot's PM or to main. It must work both in main and PM
Example:
User sends to main !addtofile i want bot works in main too!
and bot sends to him [22:28] added to file....
The same with !readfromfile command.
Did you understand me now? =)))
if main, replies in main
if PM, replies in PM
just grabbed the default routine from lawmaker :P
OK then.
I'm using right click.
so another question.
here are my command lines from it.
user:SendData("$UserCommand 1 3 "..sMenu.."\\FileWriting\\Read$<%[mynick]> !readfromfile ||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\FileWriting\\Add$<%[mynick]> !addtofile %[line:Your message please...]||")
this commands in my rightclick menu don't work. What should I add to this command lines to send this commands to bot's PM on rightclick?
if I add $To: From: Joker $<%[mynick]> to this line then on rightclick on this command I'm disconnected from the hub :((
I made it like that
user:SendData("$UserCommand 1 3 "..sMenu.."\\FileWriting\\Add$ $To: From: Joker $<%[mynick]> !addtofile %[line:Your message please...]||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\FileWriting\\Read$ $To: From: Joker $<%[mynick]>!readfromfile ||")
That's my idea: if right click on the command in right click menu a command sended to bot's PM and bot sends in that PM:
[22:28] added to file....
(look the script in my first reply at this topic for that service)
Understand? :)
"$UserCommand 1 3 "..menuitem.." <%mynick]> "..command.."|"
user commands should look like this. NO TRAILING PIPE! dc++ reads xml-like thingies,and pipes arent xml compatible.
menuitem and command should be replaced by what u want ^^
An example:
"$UserCommand 1 3 Hub settings\\Clear all TEMP bans$<%[mynick]> !clrtempbans|"
no.. there should be a trailing pipe.
here is an example i made for someone else:
(http://www.stcycles.com/hate/pics/usercommand.jpg)
and here is the reference backing it up:
http://dcplusplus.sourceforge.net/wiki/index.php/UserCommand%20command (http://dcplusplus.sourceforge.net/wiki/index.php/UserCommand%20command)
-BH
Then explain me how come that ALL (100cmds) work in LawMaker without an end pipe. :D
Maybe it sends the pipes with SendData, i tried some with pipe and worked. Strange. :)