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 

One result in public, the rest in private

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


Joined: 15 Apr 2006
Posts: 3

PostPosted: Sat Jan 20, 2007 3:25 pm    Post subject: One result in public, the rest in private Reply with quote

Hi everyone,

Here's what i want to do. I have some results from a mysql query, lets say like 10. And right now, i am using a foreach loop to set my variables for each one of the results and output them into one channel. Now what i want to do is output the first result it finds in public, and all the rest in private.
Anyone has an idea on how this could be done?
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Sat Jan 20, 2007 6:27 pm    Post subject: Re: One result in public, the rest in private Reply with quote

Code:
puthelp "PRIVMSG #chan :[lindex $list 0]"
foreach item [lrange $list 1 end] {
   puthelp "PRIVMSG nick :$item"
}

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
rubenmb
Voice


Joined: 15 Apr 2006
Posts: 3

PostPosted: Sat Jan 20, 2007 9:35 pm    Post subject: Reply with quote

That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:
Code:
{some text more text}


lindex will result in an output of those words like they were diferent results:
Code:
some
text
more
text

Rolling Eyes
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Sat Jan 20, 2007 9:53 pm    Post subject: Reply with quote

In your first post you said you used foreach to create some variables... $list in my example would be the list you passed to foreach.
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jan 20, 2007 10:20 pm    Post subject: Reply with quote

rubenmb wrote:
That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:
Code:
{some text more text}


lindex will result in an output of those words like they were diferent results:
Code:
some
text
more
text

Rolling Eyes

Yeah, and for
Code:
{"some text" "more text"}

lindex will result in
Quote:
some text
more text

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
rubenmb
Voice


Joined: 15 Apr 2006
Posts: 3

PostPosted: Sat Jan 20, 2007 11:12 pm    Post subject: Reply with quote

Yes user your right, i should have posted you some code.
And that way you would see that after calling the foreach i handle each argument of each string in a way
that makes it impossible to use the method you posted,
because its no longer:

Code:
 {some text and more text} {second result text} {and so on}


after my foreach it'll be something like:

Code:
[TAG] Result 1: \002some text and more text\002

for each of the resulted data.

But your help was still very much appreciated, cause basing my self on that
i was able to tweak the script and end up with what i wanted.
I'll explain for the ones that will run into the same problem:
Code:

## instead of looping around the raw data first
## I separated the first result ($n1) from the rest ($nx)

       set n1 [lindex $data 0]
       set nx [lrange $data 1 end]

## then i submited the first result to my proc with type=public

       my_proc $n1 $needed $variables public

## for the rest of the results, and now yes, i use a foreach loop and type=private

       foreach item $nx {
          my_proc $item $needed $variables private
       }

## then on my proc

proc my_proc { item needed variables type }
set this
set that
bla bla
if {$type == "public"} {
     putserv "PRIVMSG $channel :$line"
} else {
     putserv "PRIVMSG $nick :$line"}
}



So thats how i pull it off Very Happy
Again thanks for the help user

regards
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jan 20, 2007 11:51 pm    Post subject: Reply with quote

So basically, you did exactly what user suggested Laughing
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
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