-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
40 lines (33 loc) · 1.05 KB
/
commands.go
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
package main
import (
"github.com/bwmarrin/discordgo"
"github.com/Team-Alua/kat/userfs"
"github.com/Team-Alua/kat/umountfs"
"github.com/Team-Alua/kat/interpreter"
"github.com/Team-Alua/kat/discord"
"github.com/dop251/goja"
)
func InterpreterLoopMain(fn string, fs *umountfs.UmountFS, rw discord.ReadWriter) {
for true {
interp := interpreter.NewInterpreter(rw, fs)
ie := interp.Run(fn)
if gie, ok := ie.(*goja.InterruptedError); ok {
err := gie.Value().(error)
rw.WriteString(err.Error())
} else if ie != nil {
rw.WriteString(ie.Error())
}
break
}
}
func InterpreterLoop(req <-chan discord.ClientRequest, resp chan<- string, s *discordgo.Session, m *discordgo.MessageCreate) {
rw := discord.NewReadWriter(s, req, m.ChannelID)
fn := "default"
mfs, err := userfs.Create(m.Author.ID)
if err != nil {
rw.WriteString(err.Error())
return
}
InterpreterLoopMain(fn, mfs, rw)
resp <- m.ChannelID + "_" + m.Author.ID
}