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.

strip colors?

General support and discussion of Eggdrop bots.
e
evilgenius
Voice
Posts: 2
Joined: Thu Dec 28, 2006 12:45 am

strip colors?

Post by evilgenius »

im wondering how can i strip colors, bold and underlines in text for the bind pub and for the text
if someone says the work text either in bold or colors i still want the code to react to the pub and also the text
here is the code below

Code: Select all

bind pub "-|-" TEST search_info
proc search_info { nick host handle channel text} {
set testing [lindex [split $text] 3]
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

Code: Select all

set testing [stripcodes bcru [lindex [split $text] 3]]
that will work for your text, but for the bind pub i have no ideas :P
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Check out this thread.
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

seems a bit bleh, must be an easy to way to strip a bind pub

summet on the lines of, im not tht good at tcl but learning ;p

bind pub - [stripcodes bcr "TEST"] search_info
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I'm certain it's not bleh, blah, or bloh :P Just load that peace of code (not too hard ;)).
Ace-T wrote:bind pub - [stripcodes bcr "TEST"] search_info
That will strip codes off of "TEST" (which is useless because it has no codes anyway) and not off the message from IRC.
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

ah i understand now :)

spoke to a friend and he said use

Code: Select all

proc filter_mirc {} { 
upvar text text 
regsub -all -- "(\002|\017|\026|\037|\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?)"  $text "" text 
} 

proc pub:search_info {nick host handle channel text} {
filter_mirc
}
but it dies on me :P

how else can u set up a bind pub to react to text?

i have mine simliar to evilgenius


here is mine:

Code: Select all


bind pub - GAMES game_games


proc game_games {nick uhost handle channel text} {

set game [stripcodes bcru [lindex [split $text] 4]] 

putquick "PRIVMSG $channel :Test $game :: Working"
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I believe this quote from the file tcl-commands.doc (comes with the source) explains any and all ways of using pub-bindings...
doc/tcl-commands.doc wrote: (4) PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>

Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
Module: irc
<flags> would be matched against whoever tries to trigger the binding, and the associated command will only be invoked if flags match (similar matching as done by "matchattr"). If flags dont match up, no actions are taken.
This binding also allows you to check against channel-speciffic flags.

<command> is the first word in any line written to the channel. It does not support masks.
Assuming $line would be a line written on a channel, the test would look somewhat like this:

Code: Select all

if {[string equal -nocase <command> [lindex [split $line " "] 0]]} {<proc> <nick> <user@host> <handle> <channel> <text>}
<proc> would be the command-line executed whenever the binding triggers. Five (5) arguments will be added to the end of the command-line as illustrated above.

Looking at some of your previous experimenting (bind pub - [stripcodes bcr "TEST"] search_info), it would seem you're trying to make a binding trigger regardless of wether your users use control-codes or not. Your best choice here, I suppose, would be to use the pubm-binding instead, which allows the use of wildcards (and matches against the whole textline, rather than the first word).

=====================================
Your friends suggestion is (possibly) bad in one way. It relys on upvar and a static variable name, that is, it will always strip the variable named "test" regardless of what variables you use within your script. If you do not have any variable named "test" within the proc you called it from, you'll get an error roughly saing "no such variable test".

A more proper way of doing it would be something like this, which allows you to supply the variable of your choice to be stripped:

Code: Select all

#filter_mirc: remove various control-characters from the supplied variable.
#usage: filter_mirc <varname>
#Returns: The number of characters stripped.
proc filter_mirc {variable} {
 upvar $variable text
 if {[info exists text]} {
  return [regsub -all -- "(\002|\017|\026|\037|\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?)"  $text "" text]
 } {
  error "can't read "$variable": no such variable"
 }
}
Even so, I would still recommend the use of stripcodes whenever it's available.
NML_375
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

ive tried your way

Code: Select all

if {[string equal -nocase <command> [lindex [split $line " "] 0]]} {<proc> <nick> <user@host> <handle> <channel> <text>}
but get a variable errors for $line


the only thing i want to do is strip colours or bold from the first work =(
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That was not some code to be executed, but rather an illustration on how pub-bindings work.. If I did'nt make that obvious enough, I apologize.
NML_375
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

its prolly just me, im dumb hehe


could you show me how you would add it into the code i post above?
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

could you show me how you would add it into the code i post above?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Once again, that code is not intended to be added to any script!
It merely illustrates how the pub-binding works (roughly), and serves no purpose other than giving you an understanding on how the <command>-parameter works in the pub-binding...

Quoted from one of my previous posts:
NML_375 wrote:Looking at some of your previous experimenting (bind pub - [stripcodes bcr "TEST"] search_info), it would seem you're trying to make a binding trigger regardless of wether your users use control-codes or not. Your best choice here, I suppose, would be to use the pubm-binding instead, which allows the use of wildcards (and matches against the whole textline, rather than the first word).
To extend that, pub-bindings does not allow the use of wildcards (*, ?, etc), and will make a litteral (non-case sensitive) match to the first word on a line written in the channel. If there are some control-codes within the first word, it will not match your pub-binding unless you have the exact same control-codes in the exact same position. There is no way of parsing or filtering the the line of text prior bind-triggering, that is, any stripping of control-characters would have to be done within the proc (<command>) you've selected to be executed once the binding triggers.

Order of operations:
* Eggdrop recieves a PRIVMSG command from the irc-server, and extracts enough information to determine the recipient (bot or channel), sender and text.
* If the recipient was a channel, eggdrop will iterate through all registered pub and pubm-bindings.
  1. For pub-bindings, extract the first word from the recieved text.
  2. Check this word against the registered <command>.
  3. If this is an exact match, execute the command-line "<procname> <nick> <user@host> <handle> <channel> <text>", where <procname> would be whatever was registered as <proc> when the binding was created. Other parameters are extracted from the line recieved from the irc-server.

In the scenario you were experimenting, with this is roughly what happened (we're assuming there's no pubm-bindinds that might interfere).
  1. You entered the command "bind pub - [stripcodes bcr "TEST"] search_info"
  2. tcl does some preprocessing, including executing "stripcodes bcr "TEST"". The result from this ("TEST"), is inserted into the command-line, replacing "[stripcodes bcr "TEST"]".
    New command-line is: "bind pub - "TEST" search_info"
  3. tcl executes this command, registering a new pub-binding, having "TEST" as the <command> parameter, no flags to be checked, and <proc> being "search_info".
  4. Someone writes "TEST bla, blah, bleh..." in a channel your bot monitors.
  5. Your bot goes through your registered pub-bindings, looking for "TEST", and finds a match. This match tells it to run the command

    Code: Select all

    search_info someone ident@somehost somehand #thechannel "bla, blah, bleh..."
  6. The return-code of the command is checked to determine wether eggdrop should make a log-entry or not.
  7. Otheruser writes "<ctrl+c>2,3TEST bla, blah, bleh..." in the same channel (TEST in some fancy colors)
  8. Your bot goes through your registered pub-bindings, looking for "<ctrl+c>2,3TEST", but does not find a match, and thus does nothing.
Now, if you are trying to accomplish what I think you are, you'd most likely have to use a pubm-binding matching anyting (ie bind pubm - * <command>), and then within the called proc, strip the text from control-characters as discussed previously, extract the first word of the string, and test wether it matches your keyword.
NML_375
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

NML_375 thanks for your help :)

but i give up ive tried everything :'( :( :'(
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

nml375 I can't believe how far you went in trying to explain this without going crazy :lol:

Ace-T if you actually read nml375's explanation you would've understood exactly how to do this. Don't be lazy, you want something then READ what you're given and stop asking for quick solutions.
A
Ace-T
Halfop
Posts: 82
Joined: Tue Aug 29, 2006 7:25 am

Post by Ace-T »

i have read it, im fairly new to tcl, i will have another look later :P



and ive fixed it.................


\o/
Last edited by Ace-T on Sat May 12, 2007 4:08 pm, edited 1 time in total.
Post Reply