70 lines
1.4 KiB
Go
Raw Normal View History

2017-06-20 16:06:41 +00:00
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-06-20 16:06:41 +00:00
"github.com/bwmarrin/discordgo"
)
func main() {
2019-05-05 13:00:07 +00:00
discord, err := discordgo.New()
if err != nil {
panic(err)
}
2017-06-20 16:06:41 +00:00
2017-06-27 14:23:57 +00:00
discord.Token = "Bot " + arn.APIKeys.Discord.Token
2017-06-20 16:06:41 +00:00
// Verify a Token was provided
if discord.Token == "" {
log.Println("You must provide a Discord authentication token.")
return
}
// Verify the Token is valid and grab user information
discord.State.User, err = discord.User("@me")
if err != nil {
log.Printf("Error fetching user information: %s\n", err)
}
// Open a websocket connection to Discord
err = discord.Open()
if err != nil {
log.Printf("Error opening connection to Discord, %s\n", err)
}
defer discord.Close()
2018-12-10 04:42:29 +00:00
defer arn.Node.Close()
defer func() {
_, err := discord.ChannelMessageSend(logChannel, "I'm feeling like shit today so I'm shutting down. B-baka!")
if err != nil {
color.Red(err.Error())
}
}()
2017-06-20 16:06:41 +00:00
2018-03-06 16:34:02 +00:00
// Receive events
discord.AddHandler(OnMessageCreate)
discord.AddHandler(OnGuildMemberAdd)
discord.AddHandler(OnGuildMemberRemove)
2017-06-20 16:06:41 +00:00
// Wait for a CTRL-C
_, err = discord.ChannelMessageSend(logChannel, "Hooray, I'm up again! Did you miss me?")
if err != nil {
color.Red(err.Error())
}
2017-06-20 16:06:41 +00:00
log.Printf("Tsundere is ready. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
2018-04-25 23:14:23 +00:00
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
2017-06-20 16:06:41 +00:00
<-sc
}