cmd in main (not in bot's PM)...
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

cmd in main (not in bot's PM)...

Started by NemeziS, 12 September, 2004, 17:49:16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NemeziS

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? =)
--LUA forever! =)

D-J Valhala

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
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

NemeziS

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? :)))
--LUA forever! =)

D-J Valhala

i think i dont know how to do that but i'm sure that the guys here will do that for ya ;)
My PsyIsrael Network
==================
--=[PsyIsrael DC Hub]=--
--=[PsyIsrael Website]=--
==================

bastya_elvtars

-- 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.
Everything could have been anything else and it would have just as much meaning.

NemeziS

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? =)))
--LUA forever! =)

bastya_elvtars

if main, replies in main
if PM, replies in PM

just grabbed the default routine from lawmaker :P
Everything could have been anything else and it would have just as much meaning.

NemeziS

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? :)
--LUA forever! =)

bastya_elvtars

"$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|"
Everything could have been anything else and it would have just as much meaning.

BottledHate

no.. there should be a trailing pipe.


here is an example i made for someone else:


and here is the reference backing it up:

http://dcplusplus.sourceforge.net/wiki/index.php/UserCommand%20command

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

bastya_elvtars

Then explain me how come that ALL (100cmds) work in LawMaker without an end pipe. :D
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Maybe it sends the pipes with SendData, i tried some with pipe and worked. Strange. :)
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk