Ignore:
Timestamp:
09/15/03 14:48:58 (9 years ago)
Author:
jamesoff
Message:

optimised random user and bot selection
made get real name more robust

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/output.tcl

    r260 r261  
    465465} 
    466466 
    467 proc bMotionGetRealName { nick { host "" }} { 
     467proc OLDbMotionGetRealName { nick { host "" }} { 
    468468  bMotion_putloglev 4 * "bMotion: bMotionGetRealName($nick,$host)" 
    469469 
     
    500500  } 
    501501  putloglev 2 * "bMotion: found $handle, IRLs are $realname" 
     502  return [pickRandom $realname] 
     503} 
     504 
     505proc bMotionGetRealName { nick { host "" }} { 
     506  bMotion_putloglev 3 * "bMotion: bMotionGetRealName($nick,$host)" 
     507 
     508  if {$nick == ""} { 
     509    return "" 
     510  } 
     511 
     512  #is it me? 
     513  if [isbotnick $nick] { 
     514    return "me" 
     515  } 
     516 
     517  set handle [nick2hand $nick] 
     518  if {$handle == "*"} { 
     519    #not in bot 
     520    bMotion_putloglev 2 * "bMotion: no match, using nick" 
     521    #return [bMotionWashNick $nick] 
     522    return $nick 
     523  } 
     524 
     525  bMotion_putloglev 2 * "bMotion: $nick is handle $handle" 
     526 
     527  # found a user, now get their real name 
     528  set realname [getuser $handle XTRA irl] 
     529  if {$realname == ""} { 
     530    #not set 
     531    bMotion_putlogleg 2 * "no IRL set, using nick" 
     532    return $nick 
     533  } 
     534  putloglev 2 * "bMotion: IRLs for $handle are $realname" 
    502535  return [pickRandom $realname] 
    503536} 
     
    593626 
    594627proc bMotionChooseRandomUser { channel { conditions ""}} { 
     628  global botnick 
    595629  bMotion_putloglev 2 * "bMotion: looking for a $conditions user" 
    596   global botnick 
     630 
    597631  set users [chanlist $channel] 
    598632  if {[llength $users] < 2} { 
     
    601635 
    602636  set userslist [list] 
     637 
    603638  foreach user $users { 
     639    if [isbotnick $user] { 
     640      continue 
     641    } 
     642 
    604643    set handle [nick2hand $user] 
    605644    if [matchattr $handle b] { 
    606645      continue 
    607646    } 
     647 
    608648    if {$conditions != ""} { 
    609649      if [string match -nocase [getuser $handle XTRA gender] $conditions] { 
    610650        lappend userslist $user 
    611         bMotion_putloglev 1 * "bMotion: accepting user $handle for gender $conditions" 
     651        bMotion_putloglev 2 * "bMotion:  `- accepting nick $nick for gender $conditions" 
    612652      } else { 
    613653        if {($conditions == "like") && [bMotionLike $user [getchanhost $user]]} { 
    614654          lappend userslist $user 
    615655        } else { 
    616           bMotion_putloglev 2 * "bMotion: rejecting $handle on gender"  
     656          bMotion_putloglev 2 * "bMotion:  `- rejecting nick $nick on gender"  
    617657        } 
    618658      } 
     
    621661    } 
    622662  } 
    623   bMotion_putloglev 1 * "bMotion: found [llength $userslist] users in $channel, $userslist" 
     663 
     664  bMotion_putloglev 1 * "bMotion: found [llength $userslist] suitable users in $channel, $userslist" 
     665 
     666  #abort if no users 
    624667  set users $userslist 
    625668  if {[llength $users] == 0} { 
     
    627670  } 
    628671 
     672  #pass thru with first user if that's the only one 
    629673  if {[llength $users] == 1} { 
    630674    return [lindex $users 0] 
    631675  } 
    632676 
    633   set ruser $botnick 
    634   while {$ruser == $botnick} { 
    635     set ruser [lindex $users [rand [llength $users]]] 
    636   } 
    637   return $ruser 
     677  return [pickRandom $users] 
    638678} 
    639679 
    640680proc bMotionChooseRandomBot { channel { conditions "" }} { 
    641   bMotion_putloglev 1 * "bMotion: checking $channel" 
    642681  global botnick bMotionInfo 
     682  bMotion_putloglev 1 * "bMotion: checking $channel for bots" 
     683   
    643684  set bots [chanlist $channel] 
    644685  set botslist [list]  
     686 
    645687  foreach bot $bots { 
    646688    if [isbotnick $bot] { continue } 
    647689    set handle [nick2hand $bot $channel] 
     690 
    648691    bMotion_putloglev 1 * "bMotion: checking $bot ($handle)" 
    649692    if [matchattr [nick2hand $bot $channel] b&K $channel] { 
     
    670713  } 
    671714 
    672   set rbot $botnick 
    673   while {$rbot == $botnick} { 
    674     set rbot [lindex $bots [rand [llength $bots]]] 
    675   } 
    676   return $rbot 
     715  return [pickRandom $bots] 
    677716} 
    678717 
Note: See TracChangeset for help on using the changeset viewer.