-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
117 lines (109 loc) · 3.53 KB
/
main.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
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
108
109
110
111
112
113
114
115
116
117
package main
import (
"bufio"
"io"
"log"
"os"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/davecgh/go-spew/spew"
"github.com/mitchellh/go-wordwrap"
)
var s *discordgo.Session
var bannedFile *os.File
var banned = map[string]bool{}
func main() {
//token, err := ioutil.ReadFile("token")
token := os.Getenv("TOKEN")
if token == "" {
log.Fatalln("set env var TOKEN")
}
var err error
bannedFile, err = os.OpenFile("banned", os.O_APPEND|os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(bannedFile)
for scanner.Scan() {
banned[scanner.Text()] = true
}
s, err = discordgo.New("Bot " + string(token))
if err != nil {
panic(err)
}
if err := s.Open(); err != nil {
panic(err)
}
s.AddHandler(messageCreate)
s.UpdateGameStatus(0, "with god.")
ocrInit()
log.Println("We goin")
c := make(chan interface{})
<-c
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID || m.Author.Bot || banned[m.Author.ID] {
return
}
var prefix = "$"
if m.GuildID == "449701194881826819" {
prefix = "."
}
switch {
case strings.ToLower(m.Content) == prefix+"pacman":
s.ChannelMessageSend(m.ChannelID, "<:pacman:324163173596790786>")
case isCommand(m.Content, "botban", prefix):
permissions, err := s.State.UserChannelPermissions(m.Author.ID, m.ChannelID)
if err != nil {
log.Println(err)
return
}
if (permissions&discordgo.PermissionBanMembers) > 0 || m.Author.ID == "147077474222604288" {
if len(m.Mentions) != 1 {
s.ChannelMessageSend(m.ChannelID, prefix+"botban <usermention>")
return
}
if _, err := io.WriteString(bannedFile, m.Mentions[0].ID+"\n"); err != nil {
s.ChannelMessageSend(m.ChannelID, "Error uhh ahhh ahh uuhhhh\n```\n"+spew.Sprint(err)+"\n``` ahh uhhh ahh ahh")
}
banned[m.Mentions[0].ID] = true
}
case isCommand(m.Content, "ocr", prefix):
ocr(s, m)
case isCommand(m.Content, "listocr", prefix):
s.ChannelMessageSend(m.ChannelID, wordwrap.WrapString(strings.Join(ocrLangs, " ")+"\ntranslate these names at https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html", 80))
case isCommand(m.Content, "help", prefix):
s.ChannelMessageSend(m.ChannelID, "yerm")
case isCommand(m.Content, "ping", prefix):
s.ChannelMessageSend(m.ChannelID, "pon")
case isCommand(m.Content, "say", prefix):
if m.Author.ID == os.Getenv("OWNER") {
s.ChannelMessageDelete(m.ChannelID, m.ID)
s.ChannelMessageSend(m.ChannelID, strings.TrimPrefix(m.Content, prefix+"say"))
}
//case strings.HasPrefix(strings.ToLower(m.Content), prefix+"magick"):
// permWrap(s, m, "magick", magick)
//case strings.HasPrefix(strings.ToLower(m.Content), prefix+"squish"):
// permWrap(s, m, "magick", squish)
//case strings.HasPrefix(strings.ToLower(m.Content), prefix+"squosh"):
// permWrap(s, m, "magick", squosh)
case isCommand(m.Content, "knuckles", prefix):
s.ChannelMessageSend(m.ChannelID, "CHUCKLES")
case isCommand(m.Content, "figlet", prefix):
figlet(s, m)
case isCommand(m.Content, "nick", prefix):
c, err := s.Channel(m.ChannelID)
if err != nil {
return
}
if err := s.GuildMemberNickname(c.GuildID, "@me", strings.TrimPrefix(m.Content, prefix+"nick ")); err != nil {
s.ChannelMessageSend(m.ChannelID, err.Error())
log.Println("[NICK] Error:" + err.Error())
}
case isCommand(m.Content, "tickle", prefix):
s.ChannelMessageSend(m.ChannelID, "HEHEHEHEHEHEHE!!!")
}
}
func isCommand(test, command, prefix string) bool {
return strings.HasPrefix(strings.ToLower(test), prefix+command)
}