2019-10-09 12:44:43 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strings"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
|
|
|
|
2019-10-10 12:35:53 +07:00
|
|
|
const voteSuggestionChannel = "627164561644191744"
|
|
|
|
|
2019-10-09 12:44:43 +07:00
|
|
|
func main() {
|
|
|
|
token, _ := ioutil.ReadFile("token.txt")
|
|
|
|
dg, err := discordgo.New("Bot " + strings.TrimSpace(string(token)))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
dg.AddHandler(messageCreate)
|
2019-10-10 10:38:30 +07:00
|
|
|
dg.AddHandler(checkForVote)
|
2019-10-09 12:44:43 +07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-10-10 12:35:53 +07:00
|
|
|
if m.ChannelID == voteSuggestionChannel {
|
|
|
|
voteSuggestion(s, m)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-09 12:44:43 +07:00
|
|
|
command := strings.Split(m.Content, " ")
|
|
|
|
switch command[0] {
|
|
|
|
case "!sendas":
|
|
|
|
sendAs(s, m, command)
|
|
|
|
case "!editas":
|
|
|
|
editAs(s, m, command)
|
2019-10-09 14:13:59 +07:00
|
|
|
case "!invite":
|
|
|
|
createInvite(s, m, command)
|
2019-10-09 12:44:43 +07:00
|
|
|
}
|
|
|
|
}
|