-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.go
48 lines (43 loc) · 1.13 KB
/
handle.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
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
)
func (c *Config) CompileHandle(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if !Run[m.Author.ID] {
c.CompileRun(s, m)
} else {
s.ChannelMessageSend(m.ChannelID, "```you are running...```")
}
}
func (c *Config) CompileRun(s *discordgo.Session, m *discordgo.MessageCreate) {
if strings.HasPrefix(m.Content, ";compile") {
if len(m.Content) > 11 {
parse := m.Content[8+3:]
parse = parse[:len(parse)-3]
if strings.HasPrefix(parse, "go") {
Run[m.Author.ID] = true
if is, err := c.InfiniteLoop(parse[2:]); !is && c.isSafe(parse[2:]) {
if out, err := Compile(parse[2:]); err == nil && out != "" {
s.ChannelMessageSend(m.ChannelID, "```"+string(out)+"```")
} else {
fmt.Println(err)
}
} else {
if is && err == nil {
s.ChannelMessageSend(m.ChannelID, "```no loop```")
} else if err != nil {
fmt.Println(err)
} else {
s.ChannelMessageSend(m.ChannelID, "```you are send banned code```")
}
}
delete(Run, m.Author.ID)
}
}
}
}