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.

How do I make the x data variable into the y data variable?

Help for those learning Tcl or writing their own scripts.
Post Reply
B
Bewedesign
Voice
Posts: 3
Joined: Wed Jan 31, 2024 8:27 am

How do I make the x data variable into the y data variable?

Post by Bewedesign »

How do I make the x data variable into the y data variable, like the following example:

from notices: blue 3 wild wild draw four green draw two yellow 6 red 0 wild

to txt file:
blue 3
wild
wild draw four
green draw two
yellow 6
redo 0
wild
User avatar
CrazyCat
Revered One
Posts: 1279
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: How do I make the x data variable into the y data variable?

Post by CrazyCat »

I don't understand how you want to split the notice.
Can you be more explicit or use real example?
D
DasBrain
Voice
Posts: 19
Joined: Thu Apr 08, 2021 12:31 pm

Re: How do I make the x data variable into the y data variable?

Post by DasBrain »

It seems like you want to write an UNO bot - that plays UNO as a player.

So, I added the colored reverse.
This should extract the information into a Tcl list:

Code: Select all

set cardstr {blue 3 wild wild draw four green draw two yellow 6 red 0 wild}
set cardlist [regexp -all -inline {(?:blue|green|yellow|red) (?:\d|draw two|reverse)|wild draw four|wild} $cardstr]
This would yield a list with the 7 cards in $cardlist.
B
Bewedesign
Voice
Posts: 3
Joined: Wed Jan 31, 2024 8:27 am

Re: How do I make the x data variable into the y data variable?

Post by Bewedesign »

Dasbrain, you are absolutely right... Thank you..
B
Bewedesign
Voice
Posts: 3
Joined: Wed Jan 31, 2024 8:27 am

Re: How do I make the x data variable into the y data variable?

Post by Bewedesign »

Please try error:

Code: Select all

set UnoChan "#Bewedesign"
set UnoRobot "UNOer"
set UnoPlayer "Concelta"
set Unomaxsearch "1"
set UnoVersion "0.98.9 Pro"
set UnoCards "/home/Bewe/eggdrop/UnoCards.txt"
set UnoLogo "\002\0033U\00312N\00313O\00308!\002\003"

bind pubm - "*stopped by*" startUno
proc startUno {nick uhost hand chan txt} {
 global UnoChan UnoRobot
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   utimer 15 [list putserv "PRIVMSG $UnoChan :!uno"]
  }
 }
}

bind pubm - "*to join uno*" joinUno
proc joinUno {nick uhost hand chan txt} {
 global UnoChan UnoRobot
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   utimer 15 [list putserv "PRIVMSG $UnoChan :jo"]
  }
 }
}

bind pubm - "*$UnoPlayer plays*top card is*" pubfirstUno
proc pubfirstUno {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 end]]
   set card [lindex $txt 7]
   set numb [lindex $txt 8]
   utimer 20 [list findCard $card $numb]
  }
 }
}

bind pubm - "*plays*to $UnoPlayer*" pubPlays
proc pubPlays {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 end]]
   set card [lindex $txt 2]
   set numb [lindex $txt 3]
   utimer 20 [list findCard $card $numb]
  }
 }
}

bind pubm - "*passes to $UnoPlayer*" pubPasses
proc pubPasses {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   utimer 5 [list bind pubm - "*Card in play*" pubinPlay]
   utimer 10 [list putserv "PRIVMSG $UnoChan :cd"]
  }
 }
}

bind pubm - "*plays*and skips*to $UnoPlayer*" pubskips
proc pubskips {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan 
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 3]]
   set card [lindex $txt 2]
   set numb [lindex $txt 3]
   utimer 20 [list findCard $card $numb]
  }
 }
}

bind pubm - "*Card in play*" pubinPlay
proc pubinPlay {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 end]]
   set card [lindex $txt 4]
   if {[string match "" [lindex $txt 5]]} {
    set numb ""
   } else {
    set numb [lindex $txt 5]
   }
   utimer 20 [list findCard $card $numb]
   utimer 25 [list unbind pubm - "*Card in play*" pubinPlay]
  }
 }
}

bind pubm - "*was the current player*continuing with $UnoPlayer*" pubContinuing
proc pubContinuing {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   utimer 10 [list putserv "PRIVMSG $UnoChan :cd"]
  }
 }
}

bind pubm - "*plays*choose a color $UnoPlayer*" pubChoosecolor

bind pubm - "*plays*draws*and is skipped... Choose a color $UnoPlayer*" pubChoosecolor
proc pubChoosecolor {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan Unomaxsearch
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set r "red"
   set g "green"
   set b "blue"
   set y "yellow"
   set count "0"
   set rfile [open "$UnoCards" "r"]
   while {![eof $rfile]} {
    gets $rfile line
    if {[string match "*[string map {\x20 *} $r]*" $line]} {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :co r"]
     incr count
	 if {$count == $Unomaxsearch} { break }
    } elseif {[string match "*[string map {\x20 *} $g]*" $line]} {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :co g"]
     incr count
	 if {$count == $Unomaxsearch} { break }
    } elseif {[string match "*[string map {\x20 *} $b]*" $line]} {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :co b"]
     incr count
	 if {$count == $Unomaxsearch} { break }
    } elseif {[string match "*[string map {\x20 *} $y]*" $line]} {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :co y"]
     incr count
	 if {$count == $Unomaxsearch} { break }
    }
   }
   close $rfile
   if {$count == 0} {
    return 0
   }
   if {$count != 0} {
    return 1
   }
  }
 }
}

bind pubm - "*chose*play continues with $UnoPlayer*" pubChoseplay
proc pubChoseplay {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 end]]
   set card [lindex $txt 2]
   set numb ""
   utimer 20 [list findCard $card $numb]
  }
 }
}

bind pubm - "*plays*and chooses*Current player $UnoPlayer*" pubchooses
proc pubchooses {nick uhost hand chan txt} {
 global UnoPlayer UnoRobot UnoCards UnoChan
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set txt [string tolower [lrange $txt 0 end]]
   set card [lindex $txt 6]
   set numb ""
   utimer 20 [list findCard $card $numb]
  }
 }
}

bind pubm - "*Card Totals*" pubCardtotals
proc pubCardtotals {nick uhost hand chan txt} {
 global UnoLogo UnoRobot UnoChan UnoCards
 if {[lsearch -exact $UnoChan [string tolower $chan]]} {
  if {[string match -nocase "*$UnoRobot*" "$nick"]} {
   set wfile [open $UnoCards "w"]
   puts $wfile ""
   close $wfile
   rehash
   killTimers
   putlog "\[$UnoLogo\] Killing all timer..."
  }
 }
}
 
proc findCard {card numb} {
 global UnoChan UnoCards Unomaxsearch
 set count "0"
 set rfile [open "$UnoCards" "r"]
 while {![eof $rfile]} {
  gets $rfile line
  if {[string match "*[string map {\x20 *} $card]*" $line]} {
   switch -exact -- $line {
    "red 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl br"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl ys"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl yr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl ydt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
   }
  }
 }
 close $rfile
 if {$count == 0} {
  utimer 5 [list findNumb $numb]
  return 0
 }
 if {$count != 0} {
  return 1
 }
}

proc findNumb {numb} {
 global UnoChan UnoCards Unomaxsearch
 set count "0"
 set rfile [open "$UnoCards" "r"]
 while {![eof $rfile]} {
  gets $rfile line
  if {[string match "*[string map {\x20 *} $numb]*" $line]} {
   switch -exact -- $line {
    "red 0" {
     utimer 5 [list putserv "PRIVMSG $UnoChan :pl r0"]
     incr count
     if {$count == $Unomaxsearch} { break }
    }
    "red 1" {
     utimer 5 [list putserv "PRIVMSG $UnoChan :pl r1"]
     incr count
     if {$count == $Unomaxsearch} { break }
    }
	"red 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"red draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"green draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bs"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl br"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"blue draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bdt"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y0"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y1"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y2"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y3"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y4"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y5"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y6"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y7"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y8"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y9"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl ys"]
	 incr count
     if {$count == $Unomaxsearch} { break }
	}
	"yellow reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl yr"]
	 incr count
     if {$count == $Unomaxsearch} { break }
    }
    "yellow draw two" {
     utimer 5 [list putserv "PRIVMSG $UnoChan :pl ydt"]
     incr count
     if {$count == $Unomaxsearch} { break }
	}
   }
  }
 }
 close $rfile
 if {$count == 0} {
  utimer 5 [list findWdf]
  return 0
 }
 if {$count != 0} {
  return 1
 }
}

proc findWdf {} {
 global UnoChan UnoCards Unomaxsearch
 set count "0"
 set wdf "wild draw four"
 set rfile [open "$UnoCards" "r"]
 while {![eof $rfile]} {
  gets $rfile line
  if {[string match -nocase "*[string map {\x20 *} $wdf]*" $line]} {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl wdf"]
   incr count
   if {$count == $Unomaxsearch} { break }
  }
 }
 close $rfile
 if {$count == 0} {
  utimer 5 [list findWild]
  return 0
 }
 if {$count != 0} {
  return 1
 }
}

proc findWild {} {
 global UnoChan UnoCards Unomaxsearch
 set count "0"
 set w "wild"
 set rfile [open "$UnoCards" "r"]
 while {![eof $rfile]} {
  gets $rfile line
  if {[string match -nocase "*[string map {\x20 *} $w]*" $line]} {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl w"]
   incr count
   if {$count == $Unomaxsearch} { break }
  }
 }
 close $rfile
 if {$count == 0} {
  utimer 5 [list putserv "PRIVMSG $UnoChan :dr"]
  return 0
 }
 if {$count != 0} {
  return 1
 }
}

bind notc - "*playable card*" notcPlayable
proc notcPlayable {nick uhost hand txt dest} {
 global UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :cd"]
 }
}

bind notc - "Draw *" notcDraw
proc notcDraw {nick uhost hand txt dest} {
 global UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  set txt [string tolower [lrange $txt 0 end]]
  set line [lrange $txt 1 end]
  utimer 20 [list findSwitch $line]
 }
}

bind notc - "*or play another" notcdraworPlay
proc notcdraworPlay {nick uhost hand txt dest} {
 global UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :pa"]
 }
}

bind notc - "*play a card or pass*" notcPlayorpass
proc notcPlayorpass {nick uhost hand txt dest} {
 global UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :pa"]
 }
}

bind notc - "*was the current player, continuing with $UnoPlayer*" notcContinuing
proc notcContinuing {nick uhost hand txt dest} {
 global UnoPlayer UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :cd"]
 }
}

bind notc - "*draw a card before you can pass, $UnoPlayer*" notcDrawacard
proc notcDrawacard {nick uhost hand txt dest} {
 global UnoPlayer UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :dr"]
 }
}

bind notc - "*have a valid color card in-hand, $UnoPlayer*" notcValidcolor
proc notcValidcolor {nick uhost hand txt dest} {
 global UnoPlayer UnoRobot UnoChan
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  utimer 10 [list putserv "PRIVMSG $UnoChan :cd"]
 }
}

proc findSwitch {line} {
 global UnoChan Unomaxsearch
 set count "0"
 switch -exact -- $line {
  "red 0" {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl r0"]
   incr count
   if {$count == $Unomaxsearch} { return 0 }
  }
  "red 1" {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl r1"]
   incr count
   if {$count == $Unomaxsearch} { return 0 }
  }
	"red 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r2"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r3"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r4"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r5"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r6"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r7"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r8"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl r9"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rs"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rr"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"red draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl rdt"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g0"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g1"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g2"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g3"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g4"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g5"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g6"]
	 set count [expr $count+1]
	}
	"green 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g7"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g8"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl g9"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gs"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gr"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"green draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl gdt"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b0"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b1"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b2"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b3"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b4"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b5"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b6"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b7"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b8"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl b9"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bs"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl br"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"blue draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl bdt"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 0" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y0"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 1" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y1"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 2" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y2"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 3" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y3"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 4" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y4"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 5" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y5"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 6" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y6"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 7" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y7"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 8" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y8"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow 9" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl y9"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow skip" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl ys"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow reverse" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl yr"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
	}
	"yellow draw two" {
	 utimer 5 [list putserv "PRIVMSG $UnoChan :pl ydt"]
	 incr count
     if {$count == $Unomaxsearch} { return 0 }
  }
  "wild" {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl w"]
   incr count
   if {$count == $Unomaxsearch} { return 0 }
  }
   "wild draw four" {
   utimer 5 [list putserv "PRIVMSG $UnoChan :pl wdf"]
   incr count
   if {$count == $Unomaxsearch} { return 0 }
  }
 }
}
  
bind notc - * notcUno
proc notcUno {nick uhost hand txt dest} {
 global UnoLogo UnoRobot UnoCards
 if {[string match -nocase "*$UnoRobot*" "$nick"]} {
  set txt [string tolower [lrange $txt 0 end]]
  set cardlist [regexp -all -inline {(?:red|green|blue|yellow) (?:\d|draw two|reverse|skip)|wild draw four|wild} $txt]
  set d "draw"
  set warn1 "*you don't have that card*"
  set warn2 "*you have a valid color card in-hand*"
  set warn3 "*Oops! Not a valid card*"
  set warn4 "*You must draw a card before you can pass*"
  set warn5 "*You've already drawn a card*"
  set warn6 "*you have a playable card in your hand already*"
  if {[string match -nocase "*$warn1*" [lrange $txt 0 4]] || [string match -nocase "*$warn2*" [lrange $txt 0 6]] || [string match -nocase "*$warn3*" [lrange $txt 0 4]] || [string match -nocase "*$warn4*" [lrange $txt 0 8]] || [string match -nocase "*$warn5*" [lrange $txt 0 4]] || [string match -nocase "*$warn6*" [lrange $txt 0 8]]} {
   putlog "\[$UnoLogo\] Warning..."
   return 0
  } elseif {[string match -nocase "*$d*" [lindex $txt 0]]} {
   set txt [string tolower [lrange $txt 1 end]]
   set afile [open $UnoCards "a"]
   puts $afile "$txt"
   close $afile
   return 0
  } else {
   set txt $cardlist
   set txt1 [lindex $txt 0]
   set txt2 [lindex $txt 1]
   set txt3 [lindex $txt 2]
   set txt4 [lindex $txt 3]
   set txt5 [lindex $txt 4]
   set txt6 [lindex $txt 5]
   set txt7 [lindex $txt 6]
   set txt8 [lindex $txt 7]
   set txt9 [lindex $txt 8]
   set txt10 [lindex $txt 9]
   set txt11 [lindex $txt 10]
   set txt12 [lindex $txt 11]
   set txt13 [lindex $txt 12]
   set txt14 [lindex $txt 13]
   set wfile [open $UnoCards "w"]
   puts $wfile "$txt1"
   puts $wfile "$txt2"
   puts $wfile "$txt3"
   puts $wfile "$txt4"
   puts $wfile "$txt5"
   puts $wfile "$txt6"
   puts $wfile "$txt7"
   puts $wfile "$txt8"
   puts $wfile "$txt9"
   puts $wfile "$txt10"
   puts $wfile "$txt11"
   puts $wfile "$txt12"
   puts $wfile "$txt13"
   puts $wfile "$txt14"
   close $wfile
  }
 }
}

proc killTimers {} {
 global UnoChan
 foreach j [utimers] {
  if {[string match *putserv* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
  if {[string match *findCard* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
  if {[string match *findNumb* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
  if {[string match *findwdf* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
  if {[string match *findw* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
  if {[string match *findSwitch* [lindex $j 1]]} {
   killutimer [lindex $j 2]
  }
 }
 return 0
}

catch {unbind raw - PRIVMSG *raw:irc:msg}
catch {unbind raw - PRIVMSG *raw:PRIVMSG}

bind raw - PRIVMSG striprivmsg
proc striprivmsg {f k a} {
  set a [string map [list \017 ""] [stripcodes abcgru $a]]
  *raw:irc:msg $f $k $a
  *raw:PRIVMSG $f $k $a
}

catch {unbind raw - NOTICE *raw:irc:msg}
catch {unbind raw - NOTICE *raw:NOTICE}

bind raw - NOTICE striprivmsg
proc striprivmsg {f k a} {
  set a [string map [list \017 ""] [stripcodes abcgru $a]]
  *raw:irc:msg $f $k $a
  *raw:NOTICE $f $k $a
}

putlog "Loaded Play Color Uno $UnoVersion Copyright (C) 2004-2024"
Post Reply