56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"syscall"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
const voteSuggestionChannel = "627164561644191744"
|
|
|
|
func main() {
|
|
token, _ := ioutil.ReadFile("token.txt")
|
|
dg, err := discordgo.New("Bot " + strings.TrimSpace(string(token)))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
dg.AddHandler(messageCreate)
|
|
dg.AddHandler(checkForVote)
|
|
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
|
|
}
|
|
|
|
if m.ChannelID == voteSuggestionChannel {
|
|
voteSuggestion(s, m)
|
|
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)
|
|
}
|
|
}
|