egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple Notices

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Miku
Voice


Joined: 08 Feb 2009
Posts: 3

PostPosted: Sun Feb 08, 2009 9:54 am    Post subject: Multiple Notices Reply with quote

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:
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
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Sun Feb 08, 2009 11:00 am    Post subject: Reply with quote

Something like this often works:
Code:
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. Very Happy
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Feb 08, 2009 11:44 am    Post subject: Reply with quote

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

Code:

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:

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
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Feb 08, 2009 12:05 pm    Post subject: Reply with quote

TCL_no_TK wrote:
Something like this often works:
Code:
set mynotcs {
Message 1
Message 2
Message 3
Message 4
}

Code:
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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Miku
Voice


Joined: 08 Feb 2009
Posts: 3

PostPosted: Sun Feb 08, 2009 1:06 pm    Post subject: Reply with quote

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:
"\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.
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Feb 08, 2009 4:09 pm    Post subject: Reply with quote

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:

"\002(MKV)\002 - \002(\002/msg \[Hatsuyuki\]Maka xdcc send #9\002)\002"
Back to top
View user's profile Send private message
Miku
Voice


Joined: 08 Feb 2009
Posts: 3

PostPosted: Mon Feb 09, 2009 2:26 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber