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.

Matching Text

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Matching Text

Post by BigToe »

Hey, need your help

I need a script that when someone writes a text on channel #Froglegs and all of it or part of it is colored in red - it will return only the part of the string that is colored and red and will strip it from codes (so it won't return red, it will return just as a regular non-colored text) and will message that matching red text to #goahead

help please?
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Try this

Code: Select all

bind PUBM - "#from *" bigtoe:pubm

set temp(chan) "#to"

proc bigtoe:pubm {nick uhost hand chan arg} {

	if {[string match "*\0034*" $arg]} {
		set arg [string map [list "\0034" ""] $arg]

		putserv "PRIVMSG $::temp(chan) :Found $arg on chan $chan"
	}
}
Last edited by Madalin on Mon Apr 01, 2013 7:49 am, edited 2 times in total.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

can't set "temp(chan)": variable isn't array
while executing
"set temp(chan) "#to" "
(file "scripts/redtext.tcl" line 3)
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Edited the post try again
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Same error..
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

I have tested that version that is currently posted and works as it should i really don`t know why it doesnt work at you. Try copy paste the script and restart the eggdrop
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

I have and it still does not work..
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Some other script is using the var name 'temp' as a scalar variable name.
Try changing the array name to something less generic...

Code: Select all

bind PUBM - "#from *" bigtoe:pubm 

set bigtoetx(chan) "#to" 

proc bigtoe:pubm {nick uhost hand chan arg} { 

   if {[string match "*\0034*" $arg]} { 
      set arg [string map [list "\0034" ""] $arg] 

      putserv "PRIVMSG $::bigtoetx(chan) :Found $arg on chan $chan" 
   } 
} 

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Hey,

thank you for ur work Madalin and Spike

this works Spike^^ but it does not display just the text in red - it displays the whole sentence..


I wrote earlier..
I need a script that when someone writes a text on channel #Froglegs and all of it or part of it is colored in red - it will return only the part of the string that is colored
[/code]
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Try this

Code: Select all

bind PUBM - "#from *" bigtoe:pubm

set bigtoetx(chan) "#to"

proc bigtoe:pubm {nick uhost hand chan arg} {

	foreach a $arg {
		if {[string match "*\0034*" $a]} {
			set a [string map [list "\0034" ""] $a]

			putserv "PRIVMSG $::bigtoetx(chan) :Found $a on chan $chan"
		}
	}
}
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

hi

That does not return the whole text in red, just the first word
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Maybe something more like this...

Code: Select all

bind PUBM - "#from *" bigtoe:pubm 

set bigtoetx(chan) "#to" 

proc bigtoe:pubm {nick uhost hand chan arg} { 

   if {[string match "*\0034*" $arg]} { 

      set start [expr {[string first "\0034" $arg]+2}]
      set x [string first "\003" $arg $start]
      if {$x>"-1"} {  set end [incr x -1]  } else {  set end "end"  }

      set arg [string range $arg $start $end] 

      putserv "PRIVMSG $::bigtoetx(chan) :Found $arg on chan $chan" 
   } 
} 
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

The problem is both \0034 and \00304 both lead to red. So you need to anticipate both to accurately handle this. The script I wrote below is modified from SpiKe^^'s above. So of course this is a collaboration.

I want to relay from #chanA to #chanB for example, in the scripts config I would set the relaychan to #chanB. I would .chanset #chanA +bigtoetrack on partyline.
from irc wrote:** in #chanA **
<speechles> hi there <control-k>4this is red <control-k>this isnt <control-k>04but this is red again<control-k> then it isnt
** which appears in #chanA **
<speechles> hi there this is red this isnt but this is red again then it isnt

** moments later in #chanB **
<bot> Found results: this is red, but this is red again.
Hopefully this is what you had in mind. Enjoys ;)

Code: Select all

# BigToe Tracker v0.1

# Captures all text with a certain color, in channels you want and
# relays this to a control channel where you can see it appear

namespace eval big_toe {
   variable track
   # --> config starts

   # what color are we tracking? for colors 0 thru 9 you need to use both
   # 0-9 and 00-09. for example red is [list "4" "04"]. the number with the
   # leading zero must be last. for colors 10 and onward there is no issue
   # like this so you would use a single number for example, pink would
   # be [list "13"]
   set track(color) [list "4" "04"]

   # Which channel are we relay the tracked messages to?
   set track(relaychan) #relaychannel

   # <-- config ends
}

bind pubm - * big_toe::track

setudef flag bigtoetrack

namespace eval big_toe {
   proc track {nick uhost hand chan text} {
      if {![channel get $chan bigtoetrack]} { return 1 }
      variable track
      set stext [split $text \003]
      set matches [lsearch -glob -all -inline $stext [lindex $track(color) 0]*]
      if {[llength $track(color)] > 1} {
         set morematches [lsearch -glob -all -inline $stext [lindex $track(color) 1]*]
         set iterate [list matches 1 morematches 2]
      } else {
         set iterate [list matches 1]
      }
      foreach {n v} $iterate {
         foreach r [set $n] {
            lappend result [string range [string trim $r] $v end]
         }
      }
      if {[info exists result]} {
         putserv "privmsg $track(relaychan) :Found results: [join $result ", "]."
      }
      return 1
   }
}

putlog "*** BigToeTracker v0.1 Loaded."
#eof
Edit: Conversely, if you get this far.. Here is another way to do it. This one is more straight forward, no config, this should do exactly what you desire...

Code: Select all

bind pubm - "#froglegs *" big_toe::track

namespace eval big_toe {
   proc track {nick uhost hand chan text} {
      set text [split $text \003]
      foreach sentence $text {
         if {[string match 4* $sentence]} {
            set addme [string range $sentence 1 end]
         } elseif {[string match 04* $sentence]} { 
            set addme [string range $sentence 2 end]
         }
         if {[info exists addme]} {
            lappend result [string trim $addme]
            unset addme
         }
      }
      if {[info exists result]} {
         putserv "privmsg #goahead :#Froglegs: <$nick> [join $result " "]"
      }
   }
}
from irc wrote:*** in #Frogslegs ***
<speechles> blsh nlssdfhi there this is red again this isnt but this is red andnow its cyan then its red again :D

*** moments later in #goahead ***
<bot> #Froglegs: <speechles> this is red again but this is red and then its red again :D
The first way, gives priority to 4* appearing first in the result list. This may be a problem if the red text isn't given back in the order it was in the text. If this is a problem, the second way alleviates this issue and is a more simple approach to the exact same idea. Hopefully combined you gain a better grasp of tcl by exposing you to several ways to accomplish this.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thank you, speechles!

This works great, really impressive!

Thank you for helping out: Madalin, Spike^^, speechles
Post Reply