This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

what am i doing wrong here guys

Help for those learning Tcl or writing their own scripts.
Post Reply
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

what am i doing wrong here guys

Post by BhasIRC »

i made this and i am realy new to tcl anyways it does not seem to be working can you guys please help me with this

Code: Select all

#Command Bindings
bind pub - "*how*register*channel*" pub:registerchannel
bind pub - "*how*register*nick*" pub:registernick
bind pub - "*how*autovoice*" pub:autovoice

#The Commands help
proc pub:registerchannel {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To Register a Channel, you need to join a channel get @ status then typ (/msg chanserv register #channel-name password description) expl (/msg chanserv register #help helpers fun)"
  return 1
}
proc pub:registernick {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To Register your nick typ /msg nickserv register password email expl /msg nickserv register 12345 lovers@gmail.com"
  return 1
}
proc pub:autovoice {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To set a channel on auto voice typ /msg chanserv levels #channel-name set autovoice 0 expl /msg chanserv levels #help set autovoice 0"
  return 1
}
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Look up a bind type in tcl-commands.html for the correct syntax before you use it. There are many types and they have different syntax. Some binds accept a mask. A PUB bind does not, it is defined with the arguments <flags> <command> <procname>

The following PUB bind is triggered using the command !register by any user, including those without a bot user record :-

Code: Select all

bind PUB - !register pRegister

proc pRegister {nick uhost hand chan text} {
  # code here
}
Additionally, a colon is used in output statements to seperate the destination ($nick in your case) from the text :-

Code: Select all

putquick "PRIVMSG $nick :text here"
Additional colons in the text may well mess up the output so they should be escaped with a backslash :-

Code: Select all

putquick "PRIVMSG $nick :helper \:text here"
I must have had nothing to do
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

Post by BhasIRC »

ok thanks i will try and add that i have like 50 different help commands i want added lol so i know if i get the hang of atleast 2 or so i will get the rest
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I hope the following working script gives you some useful ideas.

It is built on the premise that a single bind can be used to handle several/many commands by making use of the <text> argument that a PUB bind passes to the associated proc (everything that comes after the command).

For example, if the command is !help then typing !help me would pass me to the proc as the <text> argument.

There are other features which I will try to explain after the pasted code :-

Code: Select all

# help.tcl

### ---------- CONFIGURATION -------------------------- ###

set vHelpTrigger !
set vHelpFlag -

### ---------- CODE ----------------------------------- ###

proc pHelpTrigger {} {
    global vHelpTrigger
    return $vHelpTrigger
}

setudef flag help

bind PUB $vHelpFlag [pHelpTrigger]help pHelpProc

proc pHelpProc {nick uhost hand chan text} {
    if {[channel get $chan help]} {
        set command [regsub -all -- {[\s]} $text {}]
        if {[llength [split $command]] != 0} {
            switch -- $command {
                registerchannel {
                    set output(1) "ensure the channel is not already registered by typing \002/cs info #channelname\002"
                    set output(2) "register the channel by typing \002/cs register #channelname password description\002"
                }
                registernick {
                    set output(1) "change to the nick you wish to register"
                    set output(2) "register the nick by typing \002/ns register password email\002"
                }
                default {
                    set output(1) "\00304-error-\003 ($nick) unrecognised command \002$text\002"
                }
            }
        } else {
            set output(1) "\00304-error-\003 ($nick) correct syntax is \002[pHelpTrigger]help <command>\002"
        }
        foreach item [lsort -increasing [array names output]] {
            putserv "PRIVMSG $chan :$output($item)"
        }
    }
    return 0
}

putlog "help.tcl loaded"
A configuration section allows you to preset the command trigger (! for !help, . for .help, ^ for ^help etc etc) and also allows you to define which bot user flags are permitted to use the script (the default setting of - means literally anybody).

I have created a user defined flag help in order to restrict which channels the script can be used in. To activate the script in any channel you would have to use partyline command .chanset #channelname +help.

The regsub command inside the proc is used to remove all space characters from the <text> argument. That means !help register channel would work equally as well as !help registerchannel.

A switch command is used to define different outputs depending on what the user types with the command. Hence !help register channel has a different output from !help register nick. I have tried to maintain the script in a readable format such that you can simply add further options (as many as you like) to the switch command for different help items.

An array named output is used for output lines which makes it easy to have as many lines as you need. They will be output one after the other in the order output(1), output(2), output(3) etc etc (up to 9 as it stands).

Finally, I have used the command source channel $chan as the destination for the output. This is because using $nick has the annoying impact of the bot opening a pm window. If you must have $nick as the destination, then I would suggest a NOTICE and not a PRIVMSG.
I must have had nothing to do
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Re: what am i doing wrong here guys

Post by speechles »

BhasIRC wrote:i made this and i am realy new to tcl anyways it does not seem to be working can you guys please help me with this

Code: Select all

#Command Bindings
bind pub - "*how*register*channel*" pub:registerchannel
bind pub - "*how*register*nick*" pub:registernick
bind pub - "*how*autovoice*" pub:autovoice

#The Commands help
proc pub:registerchannel {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To Register a Channel, you need to join a channel get @ status then typ (/msg chanserv register #channel-name password description) expl (/msg chanserv register #help helpers fun)"
  return 1
}
proc pub:registernick {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To Register your nick typ /msg nickserv register password email expl /msg nickserv register 12345 lovers@gmail.com"
  return 1
}
proc pub:autovoice {nick uh hand chan args} {
  putquick "PRIVMSG $nick \00314Auto Helper: To set a channel on auto voice typ /msg chanserv levels #channel-name set autovoice 0 expl /msg chanserv levels #help set autovoice 0"
  return 1
}
http://forum.egghelp.org/viewtopic.php?t=15889&start=17

Code: Select all

variable mycommands { 
"*how*register*channel*|#mychan|NOTICE %n :\002\00314Auto Helper:\002 To Register a Channel:"
"*how*register*channel*|#mychan|NOTICE %n :You need to join a channel get @ status then"
"*how*register*channel*|#mychan|NOTICE %n :type: /msg chanserv register #channel-name password description"
"*how*register*channel*|#mychan|NOTICE %n :for example: /msg chanserv register #help helpers fun"
"*how*register*nick*|#mychan|NOTICE %n :\002\00314Auto Helper:\002 To Register your nick:
"*how*register*nick*|#mychan|NOTICE %n :type: /msg nickserv register password email"
"*how*register*nick*|#mychan|NOTICE %n :for example: /msg nickserv register 12345 lovers@gmail.com"
"*how*autovoice*|#mychan|NOTICE %n :\002\00314Auto Helper:\002 To set a channel on auto voice:
"*how*autovoice*|#mychan|NOTICE %n :type: /msg chanserv levels #channel-name set autovoice 0"
"*how*autovoice*|#mychan|NOTICE %n :for example: /msg chanserv levels #help set autovoice 0"
}
Putserv-O-matic can do this, simple putserv'd messages with replacement variables. This was done to make it easier for those converting "mIRC script" which looks similar to how mycommands does. Replace the scripts mycommands with the mycommands shown above and it does just that. Change #mychan of course to #yourchan of choice, or use wildcards (* for all channels). Arfer's script does this as well, but his requires the user use "!help" as a command, while the good-ole putserv-O-matic works the same as your script would've (if pubm and colon were where they needed to be) based off words within what a user says. Also spread your message out into several lines, this gives a cleaner look to it. Putserv-O-matic supports this ability. Keep in mind that when getting help, the last thing a person wants is "the help" to be displayed in an unreadable style.
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

Post by BhasIRC »

thanks alot i think i understand a bit but can you tell me what i am doing wrong here?

Code: Select all

# help.tcl 

### ---------- CONFIGURATION -------------------------- ### 

set vHelpTrigger ! 
set vHelpFlag - 

### ---------- CODE ----------------------------------- ### 

proc pHelpTrigger {} { 
global vHelpTrigger 
return $vHelpTrigger 
} 

setudef flag help 

bind PUB $vHelpFlag [pHelpTrigger]help pHelpProc 

proc pHelpProc {nick uhost hand chan text} { 
if {[channel get $chan help]} { 
set command [regsub -all -- {[\s]} $text {}] 
if {[llength [split $command]] != 0} { 
switch -- $command { 
registerchannel { 
set output(1) "ensure the channel is not already registered by typing \002/cs info #channelname\002" 
set output(2) "register the channel by typing \002/cs register #channelname password description\002" 
} 
registernick { 
set output(1) "\00314Auto Helper: change to the nick you wish to register" 
set output(2) "\00314Auto Helper: register the nick by typing \002/ns register password email\002" 
} 
setautovoice { 
set output(1) "\00314Auto Helper: change to the nick you wish to register" 
} 
addaccess { 
set output(1) "\00314Auto Helper: check to see if the nick you want to add is registered by typing /ns info nick" 
set output(2) "\00314Auto Helper: add access by typing /cs access #channel-name add nick level" 
} 
removeaccess { 
set output(1) "\00314Auto Helper: to remove a nick from the access typ /cs access #channel-name del nick" 
} 
invite { 
set output(1) "\00314Auto Helper: How to invite people into your channel: Type /invite <nickname> #<channel-name>" 
} 
setaway { 
set output(1) "\00314Auto Helper: Type /away <reason> >> Using /away without a reason will set you as no longer being away (back at computer)" 
} 
pmuser { 
set output(1) "\00314Auto Helper: How to private message someone: 1. Double click the users nickname in the nicklist, and begin chatting in the new window. 2. Alternatively you can use /query <nickname> <message>" 
} 
identify { 
set output(1) "\00314Auto Helper: How to identify to your nickname: 1. Change to the appropriate nickname by using /nick <your-registered-nickname>" 
set output(2) "\00314Auto Helper: Type /nickserv identify <your-nick's-password>" 
} 
partchannel { 
set output(1) "\00314Auto Helper: Type /part #<channel-name>" 
set output(2) "\00314Auto Helper: How to part all channels your on: Type /partall" 
} 
changechannelpassword { 
set output(1) "\00314Auto Helper: Typ /cs set #channel-name password newpass" 
} 
getnickdetails { 
set output(1) "\00314Auto Helper: typ /whois nick" 
set output(2) "\00314Auto Helper: to get more detail about a nick typ /ns info nick" 
} 
changenickpassword { 
set output(1) "\00314Auto Helper: Typ /ns setpassword newpass" 
} 
getvhost { 
set output(1) "\00314Auto Helper: register your nick and wait for 3 months then pick a vhost that has no bad words in it and you all join #help and ask an ircop to assign the vhost for you" 
} 
default { 
set output(1) "\00304-error-\003 ($nick) unrecognised command \002$text\002" 
} 
} 
} else { 
set output(1) "help commands are as follows \00314 !help register nick, !help register channel, !help change nick password, !help get nick details, !help change channel password, !help part #channel, !help identify, !help set away, !help set away, !help add access, !help remove access, !help set autovoice, !help get vhost" 
} 
foreach item [lsort -increasing [array names output]] { 
putserv "PRIVMSG $chan :$output($item)" 
} 
} 
return 0 
} 

putlog "help.tcl loaded" 

User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Did you do .chanset #channelname +help for the channel(s) you want the script to function in.

Otherwise, what error are you getting?

Could I also urge you to properly indent your code so that it is more easily readable.
I must have had nothing to do
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

Post by BhasIRC »

i get this msg
Error trying to set +help for #help, invalid mode.
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Post by blake »

BhasIRC wrote:i get this msg
Error trying to set +help for #help, invalid mode.
have you tryed .chanset #help +help
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

If the channel's name is #whatever where you wanted to use the script then you would need to use .chanset #whatever +help in the partyline

However, this would have to be AFTER the script has been properly loaded otherwise the bot would not recognise the user defined flag help as set by the line in the tcl setudef flag help
I must have had nothing to do
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

Post by BhasIRC »

the script is loaded and yes i did try the .chanset #help +help
B
BhasIRC
Voice
Posts: 27
Joined: Sat Jan 02, 2010 7:05 am
Location: south africa
Contact:

Post by BhasIRC »

thanks alot guys its working
Post Reply