Files
GoBunnyBot/bunnybot.go

71 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
Token string
)
func init() {
flag.StringVar(&Token, "t", "", "Bot Token")
flag.Parse()
}
func main() {
// create Discord session
dg, err := discordgo.New("Bot " + Token)
if err != nil {
fmt.Println("Error creating Discord session, ", err)
return
}
// register the message_create func as a callback for MessageCreate events
dg.AddHandler(message_create)
// open a websocket connection to Discord and begin listening
err = dg.Open()
if err != nil {
fmt.Println("Error opening connection, ", err)
return
}
// wait here until term signal
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
// cleanly close
dg.Close()
}
func message_create (s *discordgo.Session, m *discordgo.MessageCreate) {
// ignore messages by the bot
if m.Author.ID == s.State.User.ID {
return
}
// ping
if m.Content == "ping" {
s.ChannelMessageSend(m.ChannelID, "Pong!")
}
if m.Content == "pong" {
s.ChannelMessageSend(m.ChannelID, "Ping!")
}
//get_redditbooru("awwnime")
}