| 1 | # bMotion - friendship handler |
|---|
| 2 | # |
|---|
| 3 | |
|---|
| 4 | ############################################################################### |
|---|
| 5 | # bMotion - an 'AI' TCL script for eggdrops |
|---|
| 6 | # Copyright (C) James Michael Seward 2000-2008 |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, but |
|---|
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | # General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program; if not, write to the Free Software |
|---|
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | ############################################################################### |
|---|
| 22 | |
|---|
| 23 | # get a nick's friendship rating, or 50 if we couldn't find them (or if they don't |
|---|
| 24 | # have a friendship yet |
|---|
| 25 | proc getFriendship { nick } { |
|---|
| 26 | if {![validuser $nick]} { |
|---|
| 27 | set handle [nick2hand $nick] |
|---|
| 28 | if {($handle == "*") || ($handle == "")} { |
|---|
| 29 | bMotion_putloglev 1 * "friendship: couldn't find a handle for $nick to get friendship." |
|---|
| 30 | return 50 |
|---|
| 31 | } |
|---|
| 32 | } else { |
|---|
| 33 | set handle $nick |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | set friendship 50 |
|---|
| 37 | |
|---|
| 38 | if {$handle != "*"} { |
|---|
| 39 | set friendship [getuser $handle XTRA friend] |
|---|
| 40 | if {$friendship == ""} { |
|---|
| 41 | setFriendship $nick 50 |
|---|
| 42 | set friendship 50 |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | return $friendship |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | # get a handle's friendship, or 50 if unknown |
|---|
| 49 | proc getFriendshipHandle { handle } { |
|---|
| 50 | set friendship 50 |
|---|
| 51 | |
|---|
| 52 | set friendship [getuser $handle XTRA friend] |
|---|
| 53 | if {$friendship == ""} { |
|---|
| 54 | setFriendship $handle 50 |
|---|
| 55 | set friendship 50 |
|---|
| 56 | } |
|---|
| 57 | return $friendship |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | # set friendship on a handle |
|---|
| 61 | proc setFriendshipHandle { handle friendship } { |
|---|
| 62 | if {$friendship > 100} { |
|---|
| 63 | bMotion_putloglev 2 * "friendship: friendship for $handle went over 100, capping back to 90" |
|---|
| 64 | set friendship 90 |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | if {$friendship < 1} { |
|---|
| 68 | bMotion_putloglev 2 * "friendship: friendship for $handle went under 1, capping back to 10" |
|---|
| 69 | set friendship 10 |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | setuser $handle XTRA friend $friendship |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | # set friendship on a nick, if we can find a matching handle for them |
|---|
| 76 | proc setFriendship { nick friendship } { |
|---|
| 77 | bMotion_putloglev 4 * "friendship: setFriendship: nick = $nick, friendship = $friendship" |
|---|
| 78 | |
|---|
| 79 | set handle [nick2hand $nick] |
|---|
| 80 | |
|---|
| 81 | if {($handle == "*") || ($handle == "")} { |
|---|
| 82 | #perhaps it was already a handle |
|---|
| 83 | if {![validuser $nick]} { |
|---|
| 84 | bMotion_putloglev 1 * "friendship: couldn't find a handle for $nick to set friendship." |
|---|
| 85 | return 0 |
|---|
| 86 | } |
|---|
| 87 | set handle $nick |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | setFriendshipHandle $handle $friendship |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | # drift someone's friendship by a given amount |
|---|
| 94 | proc driftFriendship { nick drift } { |
|---|
| 95 | bMotion_putloglev 4 * "friendship: driftFriendship: nick = $nick, drift = $drift" |
|---|
| 96 | set handle [nick2hand $nick] |
|---|
| 97 | if {($handle == "*") || ($handle == "")} { |
|---|
| 98 | bMotion_putloglev 1 * "friendship: couldn't find a handle for $nick to drift friendship." |
|---|
| 99 | return 50 |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | set friendship [getFriendship $handle] |
|---|
| 103 | incr friendship $drift |
|---|
| 104 | setFriendship $nick $friendship |
|---|
| 105 | bMotion_putloglev 2 * "friendship: drifting friendship for $nick by $drift, now $friendship" |
|---|
| 106 | return $friendship |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | # get all users with friendship values |
|---|
| 110 | proc getFriendsList { } { |
|---|
| 111 | set users [userlist] |
|---|
| 112 | set r "" |
|---|
| 113 | set best(name) "" |
|---|
| 114 | set best(val) 0 |
|---|
| 115 | set worst(name) "" |
|---|
| 116 | set worst(val) 100 |
|---|
| 117 | set count 0 |
|---|
| 118 | |
|---|
| 119 | foreach user $users { |
|---|
| 120 | set f [getuser $user XTRA friend] |
|---|
| 121 | if {$f != ""} { |
|---|
| 122 | append r "$user:$f " |
|---|
| 123 | } |
|---|
| 124 | if {$f > $best(val)} { |
|---|
| 125 | set best(val) $f |
|---|
| 126 | set best(name) $user |
|---|
| 127 | } |
|---|
| 128 | if {($f < $worst(val)) && ($f > 0)} { |
|---|
| 129 | set worst(val) $f |
|---|
| 130 | set worst(name) $user |
|---|
| 131 | } |
|---|
| 132 | incr count |
|---|
| 133 | if {$count % 10 == 0} { |
|---|
| 134 | append r "\r\n" |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | if {$count == 0} { |
|---|
| 138 | return "No friends :( so lonely" |
|---|
| 139 | } |
|---|
| 140 | if {$count == 1} { |
|---|
| 141 | set r "Only 1 friend :(\r\n$r" |
|---|
| 142 | return $r |
|---|
| 143 | } |
|---|
| 144 | set r "$count friends; Best friend: $best(name), worst friend: $worst(name). \r\n$r" |
|---|
| 145 | return $r |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | # check if someone is liked enough to be a friend |
|---|
| 149 | proc bMotionIsFriend { nick } { |
|---|
| 150 | set friendship [getFriendship $nick] |
|---|
| 151 | bMotion_putloglev 2 * "friendship: friendship for $nick is $friendship" |
|---|
| 152 | if {$friendship <= 40} { |
|---|
| 153 | return 0 |
|---|
| 154 | } |
|---|
| 155 | return 1 |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | # tick everyone's friendship back a bit |
|---|
| 159 | proc bMotion_friendship_tick { min hr a b c } { |
|---|
| 160 | bMotion_putloglev 3 * "friendship: bMotion_friendship_tick" |
|---|
| 161 | |
|---|
| 162 | bMotion_putloglev d * "friendship tick" |
|---|
| 163 | |
|---|
| 164 | set users [userlist] |
|---|
| 165 | foreach user $users { |
|---|
| 166 | set f [getuser $user XTRA friend] |
|---|
| 167 | if {$f != ""} { |
|---|
| 168 | bMotion_putloglev 4 * "friendship: $user is $f" |
|---|
| 169 | if {$f > 60} { |
|---|
| 170 | setuser $user XTRA friend [expr $f - 1] |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if {$f < 40} { |
|---|
| 174 | setuser $user XTRA friend [expr $f + 1] |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | bind time - "00 * * * *" bMotion_friendship_tick |
|---|
| 181 | |
|---|
| 182 | bMotion_putloglev d * "friendship: friendship module loaded" |
|---|