2018-05-17 16:30:29 +02:00
package main
import (
"fmt"
"os/signal"
2018-06-03 10:40:28 +02:00
"os"
2018-05-17 16:30:29 +02:00
"syscall"
2018-05-26 12:51:05 +02:00
"log"
2018-05-17 16:30:29 +02:00
"github.com/bwmarrin/discordgo"
)
var config = readConfig ( )
2018-07-16 10:39:48 +02:00
var commands [ ] * Command
2018-05-17 16:30:29 +02:00
func main ( ) {
dg , err := discordgo . New ( "Bot " + config . Token )
if err != nil {
fmt . Println ( "error: " , err )
return
}
2018-06-29 16:50:28 +02:00
defer dg . Close ( )
2018-06-11 18:05:47 +02:00
2018-06-04 00:24:34 +02:00
dg . AddHandler ( evaluateMessage )
2018-07-26 18:47:55 +02:00
dg . AddHandler ( )
2018-05-17 16:30:29 +02:00
err = dg . Open ( )
if err != nil {
2018-06-10 21:32:06 +02:00
fmt . Println ( "No connection:\n" , err )
2018-05-17 16:30:29 +02:00
return
}
2018-06-11 18:05:47 +02:00
2018-05-26 12:51:05 +02:00
f , err := os . OpenFile ( "selphybot.log" , os . O_RDWR | os . O_CREATE | os . O_APPEND , 0666 )
if err != nil {
2018-06-10 21:32:06 +02:00
fmt . Println ( "Error opening log file:\n" , err )
2018-05-26 12:51:05 +02:00
}
defer f . Close ( )
log . SetOutput ( f )
2018-07-22 19:18:24 +02:00
dg . UpdateStatus ( 0 , "!help" )
2018-06-06 17:28:43 +02:00
addCommands ( )
2018-06-04 02:32:40 +02:00
2018-06-10 21:32:06 +02:00
fmt . Println ( "Bot running. selphyWoo" )
log . Println ( "Bot running. selphyWoo" )
2018-06-06 17:28:43 +02:00
sc := make ( chan os . Signal , 1 )
signal . Notify ( sc , syscall . SIGINT , syscall . SIGTERM , os . Interrupt , os . Kill )
<- sc
2018-06-05 14:05:09 +02:00
2018-06-10 21:32:06 +02:00
fmt . Println ( "Exiting..." )
log . Println ( "Exiting..." )
2018-06-06 17:28:43 +02:00
}
2018-06-05 14:05:09 +02:00
2018-06-06 17:28:43 +02:00
// I’ll just put all of the commands here for now.
func addCommands ( ) {
// Moderation
2018-07-25 23:48:07 +02:00
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 } )
2018-06-05 14:05:09 +02:00
2018-07-26 18:47:55 +02:00
// 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 } )
2018-07-22 15:43:46 +02:00
2018-06-10 21:32:06 +02:00
fmt . Printf ( "Successfully initialized %d commands\n" , len ( commands ) )
log . Printf ( "Successfully initialized %d commands" , len ( commands ) )
2018-05-17 16:30:29 +02:00
}