summaryrefslogtreecommitdiff
path: root/ivy.go
blob: dc27a92ccc3d9a9d495573f5210caac203ab3889 (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
package main

import (
	"strings"

	irc "github.com/fluffle/goirc/client"
	ivy "robpike.io/ivy/mobile"
)

type Ivy struct {
	Command
}

func (_ Ivy) WithArgs(_ int) bool { return true }

func (_ Ivy) Handle(conn *irc.Conn, line *irc.Line) {
	switch q := strings.SplitN(line.Text(), " ", 2); len(q) {
	case 1:
		ivy.Reset()
	case 2:
		result, err := ivy.Eval(q[1])
		if err != nil {
			result = err.Error()
		}
		conn.Notice(line.Target(), result)
	}
}

func (_ Ivy) Help() string {
	return "interpreter for an APL-like language"
}

func init() {
	Register("!", &Ivy{})
}