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 

strip colors?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Eggdrop Help
View previous topic :: View next topic  
Author Message
evilgenius
Voice


Joined: 28 Dec 2006
Posts: 2

PostPosted: Sat May 12, 2007 7:46 am    Post subject: strip colors? Reply with quote

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:

bind pub "-|-" TEST search_info
proc search_info { nick host handle channel text} {
set testing [lindex [split $text] 3]
Back to top
View user's profile Send private message
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 8:10 am    Post subject: Reply with quote

Code:

set testing [stripcodes bcru [lindex [split $text] 3]]


that will work for your text, but for the bind pub i have no ideas Razz
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat May 12, 2007 9:05 am    Post subject: Reply with quote

Check out this thread.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 9:40 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat May 12, 2007 10:34 am    Post subject: Reply with quote

I'm certain it's not bleh, blah, or bloh Razz Just load that peace of code (not too hard Wink).
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 11:02 am    Post subject: Reply with quote

ah i understand now Smile

spoke to a friend and he said use

Code:

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 Razz

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

i have mine simliar to evilgenius


here is mine:

Code:


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"
}
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat May 12, 2007 12:06 pm    Post subject: Reply with quote

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:
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:
#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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 12:21 pm    Post subject: Reply with quote

ive tried your way

Code:

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 =(
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat May 12, 2007 12:24 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 12:24 pm    Post subject: Reply with quote

its prolly just me, im dumb hehe


could you show me how you would add it into the code i post above?
Back to top
View user's profile Send private message
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 1:07 pm    Post subject: Reply with quote

could you show me how you would add it into the code i post above?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat May 12, 2007 1:54 pm    Post subject: Reply with quote

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:
    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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 2:08 pm    Post subject: Reply with quote

NML_375 thanks for your help Smile

but i give up ive tried everything :'( Sad :'(
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat May 12, 2007 3:35 pm    Post subject: Reply with quote

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

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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ace-T
Halfop


Joined: 29 Aug 2006
Posts: 82

PostPosted: Sat May 12, 2007 3:38 pm    Post subject: Reply with quote

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



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


\o/


Last edited by Ace-T on Sat May 12, 2007 4:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Eggdrop Help All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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