64 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/animenotifier/arn"
"github.com/bwmarrin/discordgo"
)
// Session provides access to the Discord session.
2019-05-05 13:00:07 +00:00
var (
discord *discordgo.Session
logChannel = "574579302843154442"
)
2017-06-20 16:06:41 +00:00
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()
2019-05-05 13:00:07 +00:00
defer discord.ChannelMessageSend(logChannel, "I'm feeling like shit today so I'm shutting down. B-baka!")
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
2019-05-05 13:00:07 +00:00
discord.ChannelMessageSend(logChannel, "Hooray, I'm up again! Did you miss me?")
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
}