08-21-2017, 04:47 +0200
AuthorPost
elven  06-13-2004, 13:44   Jabber
security dept.
(Administrator)
Member since 03/2004
55 Posts
The most convenient way is a regular expression:

TCL 8.4 (and greater)                                                                                                                               
1
2
3
proc stripcode {str} {
    return [regsub -all -- {\002|\037|\026|\003(\d{1,2})?(,\d{1,2})?} $str ""]
}

TCL 8.3:                                                                                                                               
1
2
3
4
proc stripcode {str} {
    regsub -all -- {\002|\037|\026|\003(\d{1,2})?(,\d{1,2})?} $str "" str
    return $str
}


To use it:                                                                                                                               
1
set strippedtext [stripcode $mycolorfulltextvariable]

or simple:                                                                                                                               
1
set text [stripcode $text]


Gotisch:
Be aware though that eggdrop already has a internal command for that(since 1.6.17):

                                                                                                                              
01
02
03
04
05
06
07
08
09
10
stripcodes <strip-flags> <string>
Description: strips specified control characters from the string given. Strip-flags can be any combination of the following:
b-remove all boldface codes
c-remove all color codes
r-remove all reverse video codes
u-remove all underline codes
a-remove all ANSI codes
g-remove all ctrl-g (bell) codes
Returns: the stripped string
Module: core


irc.swordcoast.net
This post was edited 5 times, last on 08-14-2007, 17:00 by thommey
thommey  09-05-2006, 20:46   | [EGG] Generic message handler to deal with chanmode +c (strip control codes) Jabber
(Administrator)
Member since 03/2004
62 Posts
Requires at least eggdrop1.6.17
                                                                                                                              
1
2
3
4
5
6
proc safemsg {dest text {queue "help"} {extra "-normal"}} {
    if {[validchan $dest] && [botonchan $dest] && [string first c [lindex [split [getchanmode $dest]] 0]] != -1} {
        set text [stripcodes bcruag $text]
    }
    put$queue "PRIVMSG $dest :$text" $extra
}


Usage:

safemsg $chan "hello \002bold\002 \0034red\003"
(that will do puthelp)

safemsg $chan "hello \002bold\002 \00312 blue \003" serv
(that will do putserv)

safemsg $chan "hello \002bold\002" help -next
(will send the message as puthelp message but on top of the queue (or use 'quick' instead of 'help')

You can also use nicks of course, even if there's no +c possible

safemsg $nick "hello\002bold\002"
(but it wont remove control codes of course, because there is no +c on querys)
This post was edited 4 times, last on 09-05-2006, 20:56 by thommey
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen