You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB
Go

package main
import (
"flag"
"github.com/bwmarrin/discordgo"
"log"
"os"
"os/signal"
"syscall"
"strings"
)
var (
Token string
StarterPosts [7]string = [7]string{
"oh fuck, got 'em",
"damn, nice one Dad",
"got 'em",
"straight BURNT",
"shit, you ain't *eva* coming back from that one",
"got 'em *good*",
"lol nice",
}
)
const (
DadBotID string = "247852652019318795"
MyID string = "489638309098684419"
)
func init() {
flag.StringVar(&Token, "t", "", "Bot Token")
flag.Parse()
}
func main() {
if Token == "" {
flag.Usage()
return
}
discord, err := discordgo.New("Bot " + Token)
if err != nil {
log.Fatalln("couldn't launch bot:", err)
}
discord.AddHandler(onMemberAdd)
discord.AddHandler(onMessageCreate)
if err = discord.Open(); err != nil {
log.Fatalln("couldn't connect to discord:", err)
}
defer discord.Close()
log.Println("bot now running")
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT, os.Interrupt, os.Kill)
<-sig
DBConn.Close()
}
// fires when a new user has been added to a server the bot is in
func onMemberAdd(s *discordgo.Session, u discordgo.GuildMemberAdd) {
if u.User.ID == MyID {
CreateGuildTable(u.GuildID)
}
}
// fires when a new message is sent in a server the bot has joined
func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
channel, _ := s.Channel(m.ChannelID)
// if we're told to add a new quote, handle it
if strings.HasPrefix(m.Content, "!newdunk") {
text := strings.Split(m.Content, "!newdunk ")
if err := AddDunk(channel.GuildID, m.Author.ID, text[1]); err != nil {
s.ChannelMessageSend(channel.ID, "oops, I couldn't save that sick dunk :/")
} else {
s.ChannelMessageSend(channel.ID, "nice one. adding that to my list")
}
}
// if the creator was dad bot
if m.Author.ID == DadBotID && strings.HasPrefix(m.Content, "Hi ") {
s.ChannelMessageSend(m.ChannelID, GetDunk(channel.GuildID, true))
return
}
// if someone requires a good dunk, we oblige
if len(m.Mentions) > 0 {
for _, user := range m.Mentions {
if user.ID == MyID {
post := GetDunk(channel.GuildID, false)
s.ChannelMessageSend(m.ChannelID, post)
return
}
}
}
}