| 1 | # bMotion - Flood checking |
|---|
| 2 | # |
|---|
| 3 | # $Id$ |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # bMotion - an 'AI' TCL script for eggdrops |
|---|
| 8 | # Copyright (C) James Michael Seward 2000-2002 |
|---|
| 9 | # |
|---|
| 10 | # This program is free software; you can redistribute it and/or modify |
|---|
| 11 | # it under the terms of the GNU General Public License as published by |
|---|
| 12 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | # (at your option) any later version. |
|---|
| 14 | # |
|---|
| 15 | # This program is distributed in the hope that it will be useful, but |
|---|
| 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 18 | # General Public License for more details. |
|---|
| 19 | # |
|---|
| 20 | # You should have received a copy of the GNU General Public License |
|---|
| 21 | # along with this program; if not, write to the Free Software |
|---|
| 22 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | ############################################################################### |
|---|
| 24 | |
|---|
| 25 | # We're going to track flooding PER NICK globally, not per channel |
|---|
| 26 | # If someone's flooding us in one place, we'll handle it for all channels |
|---|
| 27 | # to stop them being annoying |
|---|
| 28 | |
|---|
| 29 | # HOW IT WORKS |
|---|
| 30 | # |
|---|
| 31 | # Track a score for each nick |
|---|
| 32 | # Reduce the scores by 1 every 30 seconds |
|---|
| 33 | # Matching a plugin is one point |
|---|
| 34 | # Matching the SAME plugin as before is 3 |
|---|
| 35 | # Going over 7 will make the bot ignore 50% of what you would trigger |
|---|
| 36 | # Going over 15 cuts you out completely |
|---|
| 37 | |
|---|
| 38 | if {![info exists bMotion_flood_info]} { |
|---|
| 39 | set bMotion_flood_info(_) 0 |
|---|
| 40 | set bMotion_flood_last(_) "" |
|---|
| 41 | set bMotion_flood_lasttext(_) "" |
|---|
| 42 | set bMotion_flood_note "" |
|---|
| 43 | set bMotion_flood_undo 0 |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | proc bMotion_flood_tick { min hr a b c } { |
|---|
| 47 | bMotion_putloglev 4 * "bMotion: flood tick" |
|---|
| 48 | #tick all values down one, to zero |
|---|
| 49 | global bMotion_flood_info bMotion_flood_last bMotion_flood_lasttext |
|---|
| 50 | set stats "" |
|---|
| 51 | foreach element [array names bMotion_flood_info] { |
|---|
| 52 | set val $bMotion_flood_info($element) |
|---|
| 53 | incr val -2 |
|---|
| 54 | if {$val < 0} { |
|---|
| 55 | catch { |
|---|
| 56 | unset bMotion_flood_info($element) |
|---|
| 57 | } |
|---|
| 58 | catch { |
|---|
| 59 | unset bMotion_flood_last($element) |
|---|
| 60 | } |
|---|
| 61 | catch { |
|---|
| 62 | unset bMotion_flood_lasttext($element) |
|---|
| 63 | } |
|---|
| 64 | bMotion_putloglev 2 * "bMotion: flood tick: $element removed" |
|---|
| 65 | } else { |
|---|
| 66 | append stats "$element:\002$val\002 " |
|---|
| 67 | set bMotion_flood_info($element) $val |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | if {$stats != ""} { |
|---|
| 71 | bMotion_putloglev 2 * "bMotion: flood tick: $stats" |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | proc bMotion_flood_add { nick { callback "" } { text "" } } { |
|---|
| 76 | global bMotion_flood_info bMotion_flood_last bMotion_flood_lasttext bMotion_flood_last bMotion_flood_undo |
|---|
| 77 | set val 1 |
|---|
| 78 | if [validuser $nick] { |
|---|
| 79 | set handle $nick |
|---|
| 80 | } else { |
|---|
| 81 | set handle [nick2hand $nick] |
|---|
| 82 | if {$handle == "*"} { |
|---|
| 83 | set handle $nick |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | set lastCallback "" |
|---|
| 87 | catch { |
|---|
| 88 | set lastCallback $bMotion_flood_last($handle) |
|---|
| 89 | } |
|---|
| 90 | if {$callback != ""} { |
|---|
| 91 | set bMotion_flood_last($handle) $callback |
|---|
| 92 | if {$lastCallback == $callback} { |
|---|
| 93 | #naughty |
|---|
| 94 | set val 3 |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | set lastText "" |
|---|
| 99 | catch { |
|---|
| 100 | set lastText $bMotion_flood_lasttext($handle) |
|---|
| 101 | } |
|---|
| 102 | if {$text != ""} { |
|---|
| 103 | set bMotion_flood_lasttext($handle) $text |
|---|
| 104 | #putlog "now: $text, last: $lastText" |
|---|
| 105 | if {$lastText == $text} { |
|---|
| 106 | #naughty |
|---|
| 107 | incr val 2 |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | set flood 0 |
|---|
| 112 | catch { |
|---|
| 113 | set flood $bMotion_flood_info($handle) |
|---|
| 114 | } |
|---|
| 115 | incr flood $val |
|---|
| 116 | bMotion_putloglev 1 * "bMotion: flood added $val to $nick, now $flood" |
|---|
| 117 | set bMotion_flood_info($handle) $flood |
|---|
| 118 | set bMotion_flood_undo $val |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | proc bMotion_flood_remove { nick } { |
|---|
| 122 | global bMotion_flood_info |
|---|
| 123 | set val 1 |
|---|
| 124 | if [validuser $nick] { |
|---|
| 125 | set handle $nick |
|---|
| 126 | } else { |
|---|
| 127 | set handle [nick2hand $nick] |
|---|
| 128 | if {$handle == "*"} { |
|---|
| 129 | set handle $nick |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | set flood 0 |
|---|
| 133 | catch { |
|---|
| 134 | set flood $bMotion_flood_info($handle) |
|---|
| 135 | } |
|---|
| 136 | incr flood -1 |
|---|
| 137 | if {$flood < 0} { |
|---|
| 138 | return 0 |
|---|
| 139 | } |
|---|
| 140 | bMotion_putloglev 1 * "bMotion: flood removed 1 from $nick, now $flood" |
|---|
| 141 | set bMotion_flood_info($handle) $flood |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | proc bMotion_flood_undo { nick } { |
|---|
| 145 | global bMotion_flood_undo bMotion_flood_info bMotion_flood_lasttext |
|---|
| 146 | set val $bMotion_flood_undo |
|---|
| 147 | |
|---|
| 148 | #don't knock off the whole value |
|---|
| 149 | incr val -1 |
|---|
| 150 | |
|---|
| 151 | if [validuser $nick] { |
|---|
| 152 | set handle $nick |
|---|
| 153 | } else { |
|---|
| 154 | set handle [nick2hand $nick] |
|---|
| 155 | if {$handle == "*"} { |
|---|
| 156 | set handle $nick |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | set flood 0 |
|---|
| 161 | catch { |
|---|
| 162 | set flood $bMotion_flood_info($handle) |
|---|
| 163 | } |
|---|
| 164 | incr flood [expr 0 - $val] |
|---|
| 165 | if {$flood < 0} { |
|---|
| 166 | set flood 0 |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | set bMotion_flood_info($handle) $flood |
|---|
| 170 | set bMotion_flood_lasttext($handle) "" |
|---|
| 171 | set bMotion_flood_undo 1 |
|---|
| 172 | bMotion_putloglev 1 * "bMotion: undid flood from $nick, now $flood" |
|---|
| 173 | return 0 |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | proc bMotion_flood_get { nick } { |
|---|
| 177 | global bMotion_flood_info |
|---|
| 178 | if [validuser $nick] { |
|---|
| 179 | set handle $nick |
|---|
| 180 | } else { |
|---|
| 181 | set handle [nick2hand $nick] |
|---|
| 182 | if {$handle == "*"} { |
|---|
| 183 | set handle $nick |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | set flood 0 |
|---|
| 187 | catch { |
|---|
| 188 | set flood $bMotion_flood_info($handle) |
|---|
| 189 | } |
|---|
| 190 | return $flood |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | bind time - "* * * * *" bMotion_flood_tick |
|---|
| 194 | |
|---|
| 195 | #TODO: overnight, clear the array of 0-value elements |
|---|