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)
|
|
|
|
}
|
2019-10-10 13:59:00 +07:00
|
|
|
|
2019-10-09 12:44:43 +07:00
|
|
|
dg.AddHandler(messageCreate)
|
2019-10-10 10:38:30 +07:00
|
|
|
dg.AddHandler(checkForVote)
|
2019-10-11 14:29:07 +07:00
|
|
|
dg.AddHandler(checkForTrustUpdate)
|
2019-10-10 13:59:00 +07:00
|
|
|
|
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.")
|
2019-10-10 13:59:00 +07:00
|
|
|
go listenToVoteFinishes(dg)
|
2019-10-09 12:44:43 +07:00
|
|
|
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-11 15:13:57 +07:00
|
|
|
case "!peektrust":
|
|
|
|
viewTrustLevel(s, m, command)
|
2019-10-09 14:13:59 +07:00
|
|
|
case "!invite":
|
|
|
|
createInvite(s, m, command)
|
2019-10-11 14:29:07 +07:00
|
|
|
case "!trust":
|
|
|
|
changeTrust(s, m, command)
|
2019-10-09 12:44:43 +07:00
|
|
|
}
|
|
|
|
}
|