| View previous topic :: View next topic |
| Author |
Message |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Sun Mar 31, 2013 11:36 am Post subject: Matching Text |
|
|
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? |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sun Mar 31, 2013 12:15 pm Post subject: |
|
|
Try this
| Code: |
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"
}
}
|
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Last edited by Madalin on Mon Apr 01, 2013 7:49 am; edited 2 times in total |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Apr 01, 2013 2:27 am Post subject: |
|
|
| Quote: | can't set "temp(chan)": variable isn't array
while executing
"set temp(chan) "#to" "
(file "scripts/redtext.tcl" line 3)
|
|
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Mon Apr 01, 2013 6:13 am Post subject: |
|
|
Edited the post try again _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Apr 01, 2013 7:46 am Post subject: |
|
|
| Same error.. |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Mon Apr 01, 2013 7:50 am Post subject: |
|
|
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 _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Apr 01, 2013 8:00 am Post subject: |
|
|
| I have and it still does not work.. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Mon Apr 01, 2013 11:53 am Post subject: |
|
|
Some other script is using the var name 'temp' as a scalar variable name.
Try changing the array name to something less generic...
| Code: |
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
. |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Apr 01, 2013 12:21 pm Post subject: |
|
|
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..
| Quote: |
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] |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Mon Apr 01, 2013 12:25 pm Post subject: |
|
|
Try this
| Code: |
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"
}
}
}
|
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Mon Apr 01, 2013 12:50 pm Post subject: |
|
|
hi
That does not return the whole text in red, just the first word |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Mon Apr 01, 2013 1:02 pm Post subject: |
|
|
Maybe something more like this...
| Code: | 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
. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Apr 02, 2013 12:48 am Post subject: |
|
|
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: | # 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: | 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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
BigToe Halfop
Joined: 30 Dec 2010 Posts: 99
|
Posted: Tue Apr 02, 2013 11:43 am Post subject: |
|
|
Thank you, speechles!
This works great, really impressive!
Thank you for helping out: Madalin, Spike^^, speechles |
|
| Back to top |
|
 |
|