PtokaX forum

Development Section => HOW-TO's => Topic started by: kunal on 20 August, 2005, 15:08:31

Title: Modifying the help command?
Post by: kunal on 20 August, 2005, 15:08:31
can anyone tell me if it is possible to modify the !help cmd of ptokax
Title: help...
Post by: Markitos on 20 August, 2005, 15:12:43
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...
Title:
Post by: enigma on 04 November, 2005, 01:35:17
gd1
Title:
Post by: Dessamator on 04 November, 2005, 09:07:50
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then

is not needed.
Title:
Post by: Markitos on 16 November, 2005, 17:26:36
QuoteOriginally posted by Dessamator
Well done markitos, but this :
if( string.sub(data, 1, 1) == "<" ) then

is not needed.
Why?
Title:
Post by: 6Marilyn6Manson6 on 16 November, 2005, 17:41:09
Delete:

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

end
and work. C ya
Title:
Post by: Dessamator on 16 November, 2005, 18:51:42
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"
Title: Re: how to
Post by: Markitos on 06 March, 2006, 19:58:21
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...
Title: Re: how to
Post by: 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 ;)
Title: Re: how to
Post by: Troubadour on 06 March, 2006, 20:18:26
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
}

Title: Re: how to
Post by: 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 ;)
Title: Re: how to
Post by: Markitos on 07 March, 2006, 07:55:21
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??
Title: Re: how to
Post by: Troubadour on 07 March, 2006, 09:08:10
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  ;)
Title: Re: Modifying the help command?
Post by: 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.
Title: Re: Modifying the help command?
Post by: Markitos on 07 March, 2006, 18:57:51
thanks all  ;D
Title: Re: Modifying the help command?
Post by: 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?
Title: Re: Modifying the help command?
Post by: Herodes on 07 March, 2006, 22:34:32
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].
Title: Re: Modifying the help command?
Post by: Znupi on 10 June, 2006, 21:55:42
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
Title: Re: Modifying the help command?
Post by: Typhoon on 10 June, 2006, 22:48:16
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 ..
Title: Re: Modifying the help command?
Post by: Znupi on 10 June, 2006, 23:26:36
Sorry :(
Title: Re: Modifying the help command?
Post by: bastya_elvtars on 11 June, 2006, 02:29:46
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.