summaryrefslogtreecommitdiff
path: root/roulette.go
diff options
context:
space:
mode:
Diffstat (limited to 'roulette.go')
-rw-r--r--roulette.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/roulette.go b/roulette.go
new file mode 100644
index 0000000..6b44409
--- /dev/null
+++ b/roulette.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "math/rand"
+ "time"
+
+ irc "github.com/fluffle/goirc/client"
+)
+
+type RR struct{ Command }
+
+const barrel = 6
+
+var (
+ bullet int
+ loaded int
+)
+
+func reload() {
+ loaded = rand.Intn(barrel)
+ bullet = 0
+}
+
+func trigger() bool {
+ bullet++
+ bullet %= barrel
+ return bullet == loaded
+}
+
+func (_ RR) Handle(conn *irc.Conn, line *irc.Line) {
+ if !line.Public() {
+ return
+ }
+ if trigger() {
+ conn.Kick(*room, line.Nick, "bang!")
+ conn.Notice(*room, "reload")
+ }
+}
+
+func init() {
+ rand.Seed(time.Now().Unix())
+ Register("!", &RR{
+ Command{
+ Help: "Russian roulette",
+ },
+ })
+}