Modifying the help command?
 

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

Modifying the help command?

Started by kunal, 20 August, 2005, 15:08:31

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kunal

can anyone tell me if it is possible to modify the !help cmd of ptokax

Markitos

#1
QuoteOriginally posted by kunal
can anyone tell me if it is possible to modify the !help cmd of ptokax
Nop...unless u create a script with the cmd "!help" that can display a customized help.

This is my try...and its just an example
Bot = "yourbotname"

prefix = "!"

function Main()
	frmHub:RegBot(Bot)
end

function ChatArrival(user, data)

		data=string.sub(data,1,string.len(data)-1)

		s,e,cmd = string.find( data, "%b<>%s+(%S+)" )
		
		if cmd == prefix.."help" then

			SendToAll(Bot,"-------Help thing-----")

			SendToAll(Bot,"!help - Displays the help cmds")

			SendToAll(Bot,"-------End------------")
end 

end

end


Cheers...

enigma


Dessamator

Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then


is not needed.
Ignorance is Bliss.

Markitos

QuoteOriginally posted by Dessamator
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then


is not needed.
Why?

6Marilyn6Manson6

Delete:

if( string.sub(data, 1, 1) == "<" ) then

and last

end

and work. C ya

Dessamator

QuoteOriginally posted by Markitos
QuoteOriginally posted by Dessamator
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then


is not needed.
Why?

Well, because it was something used in the old ptokax to parse the arrivals  manually, now there are split arrivals that do that, so its no longer needed . That was the equivilant of "Chatarrival"
Ignorance is Bliss.

Markitos

I tried to modify the structure of the script and i get this error "new 1.lua:14: <eof> expected near `end'"
Bot = "Help"

function Main()
	frmHub:RegBot(Bot)
end

function ChatArrival(user, data)
	data=string.sub(data,1,string.len(data)-1)
		s,e,cmd = string.find(data, "%b<>%s+%!(%S+)")
			if cmd and tCmds[cmd] then
				return tCmds[cmd](user,data),1
			end
		end
	end
end


ToArrival = ChatArrival

tCmds = {
	["help"] = 
	function(user,data)
		if user.sName then
			user:SendToAll(Bot,"\r\n"..string.rep("---",150))
		end
	end
}


Help would be appreciated...

Herodes

Bot = "Help"

function Main()
	frmHub:RegBot(Bot)
end

function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
		if cmd and tCmds[cmd] then
			return tCmds[cmd](user,data),1
		end
	end
end


ToArrival = ChatArrival

tCmds = {
	["help"] = 
	function ( user, data )
		if user.sName then
			user:SendToAll(Bot,"\r\n"..string.rep("---",150))
		end
	end
}

Try this ;)

Troubadour

Quote from: Herodes on 06 March, 2006, 20:07:35
Bot = "Help"

function Main()
	frmHub:RegBot(Bot)
end

function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
		if cmd and tCmds[cmd] then
			return tCmds[cmd](user,data),1
		end
	end
end


ToArrival = ChatArrival

tCmds = {
	["help"] = 
	function ( user, data )
		if user.sName then
			user:SendToAll(Bot,"\r\n"..string.rep("---",150))
		end
	end
}

Try this ;)

do it more like:

Bot = "Help"

function Main()
	frmHub:RegBot(Bot)
end

function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
		if cmd and tCmds[cmd] then
			return tCmds[cmd](user,data),1
		end
	end



ToArrival = ChatArrival

tCmds = {
	["help"] = 
	function ( user, data )
		if user.sName then
			user:SendToAll(Bot,"\r\n"..string.rep("---",150))
		end
	end
}

Regards,

Troubadour

** Guardian Forum **

hubaddy:   nederfun.no-ip.com

Herodes

Quote from: Troubadour on 06 March, 2006, 20:18:26
do it more like:
function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
		if cmd and tCmds[cmd] then
			return tCmds[cmd](user,data),1
		end
	end

now that's bad tabbing ;)

Markitos

Quote from: Mutor on 06 March, 2006, 22:37:32
You shouold only tab at control structures.

function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
	if cmd and tCmds[cmd] then
		return tCmds[cmd](user,data),1
	end
end


Another question, why are tCmds a global var? Better to include that table in the function as a local.
I didnt understand ur point mutor. Could show me an example??

Troubadour

Quote from: Herodes on 06 March, 2006, 20:23:14
Quote from: Troubadour on 06 March, 2006, 20:18:26
do it more like:
function ChatArrival(user, data)
	data = string.sub ( data, 1, -2 ) -- watch this tip ;)
	local s, e, cmd = string.find ( data, "%b<>%s+%!(%S+)" )
	if cmd and tCmds[cmd] then
		return tCmds[cmd](user,data),1
	end
end

now that's bad tabbing ;)
yep, it looks nicer like this  ;)
Regards,

Troubadour

** Guardian Forum **

hubaddy:   nederfun.no-ip.com

bastya_elvtars

Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.
Everything could have been anything else and it would have just as much meaning.

Markitos


Troubadour

Quote from: bastya_elvtars on 07 March, 2006, 18:30:28
Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.

Is there a difference in bandwith usage in global or local variables or is it to few to mention?
Regards,

Troubadour

** Guardian Forum **

hubaddy:   nederfun.no-ip.com

Herodes

Quote from: Troubadour on 07 March, 2006, 22:28:29
Quote from: bastya_elvtars on 07 March, 2006, 18:30:28
Sidenote: sometimes global variables are the only way, do not be afraid of them, they can be your friend. Sometimes you have to balance whether to use global or local. You have to review some code to get the point.

Is there a difference in bandwith usage in global or local variables or is it to few to mention?

No badnwirdth talk on this matter. ..
It is generally speaking stack ( memory ) issues [size, namespace-cleaness].

Znupi

lol ... why so much discussion ... ? I think its the easiest thing a script can do ...
Bot = frmHub:GetHubBotName()
prefix = "!"
function ChatArrival(user,data)
	data = string.sub(data,1,string.len(data)-1)
	s,e,cmd = string.find(data,"%s+(%S+)")
	if (cmd == prefix.."help")
		user:SendData(Bot,"\r\n\r\n\t-------H-e-L-P-------\r\n\r\n"..
				"\t - Help thingie 1\r\n"..
				"\t - Help thingie 2\r\n"..
				"\t - Help thingie 3\r\n\r\n"..
				"\t-------H-e-L-P-------\r\n")
		return 1
	end
end

What can be more easy than that? ;D

Typhoon

Quote from: Mutor on 10 June, 2006, 22:32:03
Quote from: Znupi on 10 June, 2006, 21:55:42
lol ... why so much discussion ... ? I think its the easiest thing a script can do ...

What can be more easy than that? ;D

What could be easier? Doing just that only better

  • You're missing a 'then' on line 7
  • This statement data = string.sub(data,1,string.len(data)-1) is meaningless
  • Your string.find is weak
  • You're using global vars when they should be local
  • Should anyone care this script blocks the inbuilt help, drop the retun 1 to not do this

By 'How To" what's really intended here is 'How To Do It Well'.
Consider what's being said before sharing your amusement and broken code.


indeed a good point Mutor ..




bastya_elvtars

I think that string.sub thing is a matter of personal preference, and the criticism itself should be constructive - for instance instead of saying 'weak' one should say: 'dude, you ought to think of special characters that may confuse pattern matching' - even though the manner in which it has been posted is a bit annoying.
Everything could have been anything else and it would have just as much meaning.

SMF spam blocked by CleanTalk