TerraOceanPlugin/GoBot/main.go

48 lines
865 B
Go

package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"strings"
"syscall"
"github.com/bwmarrin/discordgo"
)
func main() {
token, _ := ioutil.ReadFile("token.txt")
dg, err := discordgo.New("Bot " + strings.TrimSpace(string(token)))
if err != nil {
panic(err)
}
dg.AddHandler(messageCreate)
if err := dg.Open(); err != nil {
panic(err)
}
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
dg.Close()
}
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
command := strings.Split(m.Content, " ")
switch command[0] {
case "!sendas":
sendAs(s, m, command)
case "!editas":
editAs(s, m, command)
case "!invite":
createInvite(s, m, command)
}
}