adding numeric values.

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

adding numeric values.

Post by iamdeath »

Question 1:

Code: Select all

proc relay:text {nick uhost handle chan text} {
  global relay
  if {[isop $nick $chan] == "1"} {
    if {[string range "$nick" 0 0] != "^"} {return 0}
#    if {[string match "*m*" [getchanmode $chan]] == "0"} { return 0 }
    foreach badpub $relay(badpubs) { if {[string match "$badpub" [string tolower $text]] == "1"} { return 0 } }
    regsub -all {FOUR} $text "10,09FOUR" text
    regsub -all {SIX} $text "11,12SIX" text
    regsub -all {OUT} $text "04,01OUT" text
    if {[string range "$nick" 0 0] == "^"} { set nick "[string range "$nick" 1 end]" }
    if {[llength [split $nick "_"]] == "2" && [lindex [split $nick "_"] 0] != "" && [lindex [split $nick "_"] 1] != ""} { set nick "[lindex [split $nick "_"] 0] VS [lindex [split $nick "_"] 1]" }
    relay:send "PRIVMSG $relay(channel_out) :$nick: $text"
}
regsub -all {FOUR} $text "10,09FOUR" text
regsub -all {SIX} $text "11,12SIX" text
regsub -all {OUT} $text "04,01OUT" text
When the bot recieves the word FOUR SIX AND OUT, it changes the color pattern of it and shows in the channel. The way "FOUR, SIX & OUT" are added, I want something like:
regsub -all {0} $text "NO RUN" text
regsub -all {1} $text "ONE RUN" text
regsub -all {2} $text "TWO RUNS" text
I tried that but giving me error.. What could be the best way adding numeric values?

Question 2:

If you get a Nickname like :

NICK_NICK_ and I want to make it NICK VS NICK: how will you do that? can you help me out ?
Somethign like this:?

Code: Select all

    if {[llength [split $nick "_"]] == "2" && [lindex [split $nick "_"] 0] != "" && [lindex [split $nick "_"] 1] != ""} { set nick "[lindex [split $nick "_"] 0] VS [lindex [split $nick "_"] 1]" }
Thanks.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

advice: don't use regsub on simple string replaces without regular expressions. String map does fine in both cases. Though I am not sure why there should be an error, because of that line. Get the complete errorInfo (refer Help us to help you).

About the NICK_NICK_ thing... I advice you to actually try what such statements do:

Code: Select all

% set list [split NICK_NICK_ _]
NICK NICK {}
% llength $list
3
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Did'nt understand I am sorry ;/
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

With a "didnt understand" I am unable to help you. You must be more specific about the part you did not understand. If you did not understand at all, I suggest visiting some English lessons... though you wouldn't be able to understand then that suggestion, either :D.
I make a wild guess and give the link to the string map manual.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply