discord-flauschbot/main.go
2018-07-26 18:47:55 +02:00

64 lines
1.9 KiB
Go

package main
import (
"fmt"
"os/signal"
"os"
"syscall"
"log"
"github.com/bwmarrin/discordgo"
)
var config = readConfig()
var commands []*Command
func main() {
dg, err := discordgo.New("Bot " + config.Token)
if err != nil {
fmt.Println("error: ", err)
return
}
defer dg.Close()
dg.AddHandler(evaluateMessage)
dg.AddHandler()
err = dg.Open()
if err != nil {
fmt.Println("No connection:\n", err)
return
}
f, err := os.OpenFile("selphybot.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil {
fmt.Println("Error opening log file:\n", err)
}
defer f.Close()
log.SetOutput(f)
dg.UpdateStatus(0, "!help")
addCommands()
fmt.Println("Bot running. selphyWoo")
log.Println("Bot running. selphyWoo")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
fmt.Println("Exiting...")
log.Println("Exiting...")
}
// I’ll just put all of the commands here for now.
func addCommands() {
// Moderation
registerCommand(Command{Trigger: "(\\s|\n|^)[nN][hH]([ ?.,\n]|$)", Output: "<@%s> „nh“ ist kein Wort, du Oboe!", DeleteInput: true, OutputIsReply: true, Type: CommandTypeRegex})
registerCommand(Command{Trigger: "einzigste", Output: "<@%s> Es heißt „einzige“, du Tuba.", DeleteInput: true, OutputIsReply: true, Type: CommandTypeContains})
// Misc
registerCommand(Command{Trigger: "<@%s> <3", Output: "<@%s> <3", Type: CommandTypeFullMatch, AdminOnly: false, OutputIsReply: true, RequiresMention: true})
registerCommand(Command{Trigger: "ist flauschig", Output: "Du bist flauschig! <3", Type: CommandTypeContains})
fmt.Printf("Successfully initialized %d commands\n", len(commands))
log.Printf("Successfully initialized %d commands", len(commands))
}