summaryrefslogtreecommitdiffstats
path: root/decision.tcl
blob: 80f7d6ccf69c04bdc6ae3e63d3346a326ce4d93b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# decision.tcl by lookshe (v 1.1)
#
# todo: little bit better coding style
#
# usage: [ ] decision1 [ ] decision2 [ ] desicion3 ...
#   no need for space after "]" but before "["
#
# Changelog:
# 
# 1.0
#  - first working version
#
# 1.1
#  - remember answers for 60 minutes


bind pub - \[ proc_decision

proc proc_decision {nick host hand chan arguments} {

global do_dec
if {[info exists do_dec($nick:$chan)]} {
   if {$nick == "lookshe"} {
      unset do_dec($nick:$chan)
   } else {
      set act_do_dec $do_dec($nick:$chan)
      if {$act_do_dec < 3} {
         incr act_do_dec
         set do_dec($nick:$chan) $act_do_dec
      } else {
         putserv "NOTICE $nick :no flooding!"
         return 0
      }
   }
} else {
   if {$nick != "lookshe"} {
      set do_dec($nick:$chan) 1
      timer 10 "unset do_dec($nick:$chan)"
   }
}

   set allargs [string map {" " _} $arguments]
   set arguments [split $arguments]
   set count 1
   set klammer_count 0
   if {([lindex $arguments 0] == "]") || ([string first "]" [lindex $arguments 0]] == 0)} {
      incr klammer_count
   } else {
      return
   }
   while {$count != [llength $arguments]} { 
      if {[lindex $arguments $count] == "\["} {
         set tmp $count
         incr tmp
         if {([lindex $arguments $tmp] == "]") || ([string first "]" [lindex $arguments $tmp]] == 0)} {
            incr klammer_count
         }
      }
      incr count
   }
   if {$klammer_count == 1} {
      return
   }
   set count 0
   set myrand [rand $klammer_count]
   if {[info exists do_dec($allargs)]} {
      set myrand $do_dec($allargs)
      timer 60 "unset do_dec($allargs)"
   } else {
      set do_dec($allargs) $myrand
      timer 60 "unset do_dec($allargs)"
   }
   set klammer_count 0
   if {$myrand == 0} {
      set output "\[X"
      while {$count != [llength $arguments]} {
         set output "$output[lindex $arguments $count] "
         incr count
      }
   } else {
      set output "\["
      while {$count != [llength $arguments]} { 
         if {[lindex $arguments $count] == "\["} {
            set tmp $count
            incr tmp
            if {([lindex $arguments $tmp] == "]") || ([string first "]" [lindex $arguments $tmp]] == 0)} {
               incr klammer_count
            }
         }
         if {$klammer_count == $myrand} {
            if {([lindex $arguments $count] == "]") || ([string first "]" [lindex $arguments $count]] == 0)} {
               set output "[string range $output 0 end]X"
            } else {
               set output "$output "
            }
         } else {
            set output "$output "
         }
         set output "$output[lindex $arguments $count]"
         incr count
      }
      
   }
   putserv "PRIVMSG $chan :$output"
}

putlog "decision by lookshe loaded"