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.

Multiple Notices

Help for those learning Tcl or writing their own scripts.
Post Reply
M
Miku
Voice
Posts: 3
Joined: Sun Feb 08, 2009 9:49 am

Multiple Notices

Post by Miku »

Hello, I am trying to send a user multiple notices when they say a specific trigger, but each time it stops after only 2.

My code looks like this:

Code: Select all

proc putnot {nick msg} { putserv "NOTICE $nick :$msg" }

proc pub_!trigger {nick uhost hand chan rest} {
  global botnick
  set cmd [string tolower [lindex $rest 0]] 
  if {$cmd == ""} {
    putnot $nick "Message 1"
    putnot $nick "Message 2"
    putnot $nick "Message 3"
    putnot $nick "Message 4"
    putnot $nick "Message 5" ;return 0}
 }
bind pub - !trigger pub_!trigger
Any help is appreciated. Thanks!
Last edited by Miku on Sun Feb 08, 2009 12:20 pm, edited 1 time in total.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Something like this often works:

Code: Select all

set mynotcs {
Message 1
Message 2
Message 3
Message 4
}

proc mynotc {nick host handle channel text} {
 global mynotcs
  set dest [lindex [split $text] 0]
  foreach notc $mynotcs {
   puthelp "NOTICE $dest :$notc"
  }
   return
}

bind pub -|- !notc mynotc
The important things to be aware of are the global mynotcs which gives us the messages we set in set mynotcs. And as we use a foreach loop, we are able to use all the notc's one at a time using $notc

I dont know if that will work, but i hope it at least made sense. :D
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

You do seem to have a statement that, once called, would continue to attempt to call itself recursively :-

Code: Select all

proc putnot {nick msg} { putnot "NOTICE $nick :$msg" }
You are fortunate it failed, probably because the first time it called itself (the second time it executes overall, coincidentally) it does so with one argument but the proc needs two. Therefore it would not send to the IRCD ad nauseum. Lucky you.

If you particularly wanted the code in the format you pasted, then try the following :-

Code: Select all

bind PUB - !notice pNotice

proc pNotice {nick uhost hand chan rest} { 
    if {[string length [string trim $rest]] == 0} {
        pOutput $nick "Message 1" 
        pOutput $nick "Message 2" 
        pOutput $nick "Message 3" 
        pOutput $nick "Message 4" 
        pOutput $nick "Message 5"
    }
    return 0
} 

proc pOutput {nick msg} {putserv "NOTICE $nick :$msg"}
I favour the style of the previous poster. A list of responses set as a variable outside the bind proc gives greater flexibility, in case you wish to publish the script and allow users to configure their own messages.
Last edited by arfer on Sun Feb 08, 2009 4:12 pm, edited 1 time in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

TCL_no_TK wrote:Something like this often works:

Code: Select all

set mynotcs {
Message 1
Message 2
Message 3
Message 4
}

Code: Select all

set mynotcs {
"Message 1"
"Message 2"
"Message 3"
"Message 4"
}
You might need to build your tcl-list using double quotes to keep those spaces within each line from breaking things.
M
Miku
Voice
Posts: 3
Joined: Sun Feb 08, 2009 9:49 am

Post by Miku »

Okay, I feel retarded now. Turns out that my initial script, as well as all of yours, would have worked except I have a special character in my message which chokes it. Now I just have to figure out a way around this and it'll be good to go.

The line reads:

Code: Select all

"\002(MKV)\002 - \002(\002/msg [Hatsuyuki]Maka xdcc send #9\002)\002"
in case any of you know an easy fix. It hangs up on the [Hatsuyuki] part.

Thanks for all your help so far.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Tcl will attempt to interpret and substitute anything enclosed in square brackets as a command and its arguments (if it has any), so your script is choking on [Hatsuyuki] since no such command exists.

Simply escape the characters with special Tcl meaning in order for them to be accepted as their normal literal selves.

Code: Select all

"\002(MKV)\002 - \002(\002/msg \[Hatsuyuki\]Maka xdcc send #9\002)\002"
M
Miku
Voice
Posts: 3
Joined: Sun Feb 08, 2009 9:49 am

Post by Miku »

Thanks that worked like a charm. I was reading a tutorial about how to filter special characters but it was rather confusing and had the "\" in series of 3 and 5.

Anywho thanks again, script works great now :D
Post Reply