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-06-03 10:40:28 +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-04 00:24:34 +02:00
dg . AddHandler ( evaluateMessage )
2018-05-17 16:30:29 +02:00
dg . AddHandler ( onJoin )
err = dg . Open ( )
if err != nil {
fmt . Println ( "no connection, " , err )
return
}
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 {
fmt . Println ( "error opening log file: %v" , err )
}
defer f . Close ( )
log . SetOutput ( f )
2018-06-04 02:32:40 +02:00
// Moderation
2018-06-06 00:19:11 +02:00
registerCommand ( Command { Trigger : "^[^`]*([()|DoO];|;[()|DoOpP]|:wink:|😉)[^`]*$" , Output : "<@%s> Oboe!" , DeleteInput : true , OutputIsReply : true , Type : CommandTypeRegex } )
2018-06-04 02:32:40 +02:00
// Misc commands
2018-06-05 14:05:09 +02:00
registerCommand ( Command { Trigger : "o/" , Output : "\\o" , Type : CommandTypeFullMatch , Cooldown : 5 } )
2018-06-04 00:24:34 +02:00
registerCommand ( Command { Trigger : "\\o" , Output : "o/" , Type : CommandTypeFullMatch } )
2018-06-06 00:19:11 +02:00
registerCommand ( Command { Trigger : "\\o/" , Output : "/o\\" , Type : CommandTypeFullMatch } )
2018-06-04 02:32:40 +02:00
registerCommand ( Command { Trigger : "<:selphyDango:441001954542616576>" , Output : ":notes: Dango, Dango, Dango, Dango, Dango Daikazoku :notes:" , Type : CommandTypeFullMatch } )
2018-06-05 14:05:09 +02:00
registerCommand ( Command { Trigger : "praise the sun" , Output : "If only I could be so grossly incandescent \\\\[T]/" , Type : CommandTypeContains , IgnoreCase : true } )
registerCommand ( Command { Trigger : "echo" , Type : CommandTypePrefix , Function : echoMessage } )
2018-06-04 02:32:40 +02:00
registerCommand ( Command { Trigger : "!welcome" , OutputEmbed : getWelcomeEmbed ( ) , Type : CommandTypeFullMatch , DMOnly : true } )
registerCommand ( Command { Trigger : "<@%s> <3" , Output : "<@%s> <3" , Type : CommandTypeFullMatch , AdminOnly : true , OutputIsReply : true , RequiresMention : true } )
registerCommand ( Command { Trigger : "!complain" , Type : CommandTypePrefix , DMOnly : true , Function : redirectComplaint } )
2018-06-04 00:24:34 +02:00
2018-05-17 16:30:29 +02:00
fmt . Println ( "bot running. selphyWoo" )
sc := make ( chan os . Signal , 1 )
signal . Notify ( sc , syscall . SIGINT , syscall . SIGTERM , os . Interrupt , os . Kill )
<- sc
dg . Close ( )
}
2018-05-26 12:51:05 +02:00
/ * func undelete ( s * discordgo . Session , m * discordgo . MessageDelete ) {
channel , _ := s . State . Channel ( m . ChannelID )
message , _ := s . State . Message ( m . ChannelID , m . ID )
log . Println ( fmt . Sprintf ( "Someone deleted a message in %s: “%s”" , channel . Name , messageToString ( message ) ) )
} * /