Support message placeholders and configuration of message

This commit is contained in:
Tyler 2020-12-17 18:56:51 -05:00
parent 00377f7670
commit 05e12f4436
1 changed files with 19 additions and 11 deletions

10
main.go
View File

@ -21,10 +21,14 @@ var (
func setupConfiguration() { func setupConfiguration() {
viper.SetDefault("prohibitedPhrases", "") viper.SetDefault("prohibitedPhrases", "")
viper.SetDefault("channels", "") viper.SetDefault("channels", "")
viper.SetDefault("message", "Hi {username}, you've posted a message that was automatically removed for matching a filter. If you need help, please use the correct channel.")
viper.AutomaticEnv() viper.AutomaticEnv()
viper.SetConfigName("ottomate") viper.SetConfigName("ottomate")
viper.AddConfigPath("/etc/ottomate/")
viper.AddConfigPath("$HOME/.ottomate")
viper.AddConfigPath(".")
viper.ReadInConfig() viper.ReadInConfig()
} }
@ -154,7 +158,11 @@ func messageCreate(e *gateway.MessageCreateEvent) {
return return
} }
_, err = s.SendText(ch.ID, "") message := viper.GetString("message")
replacer := strings.NewReplacer("{username}", e.Author.Username, "{message}", e.Content)
_, err = s.SendText(ch.ID, replacer.Replace(message))
if err != nil { if err != nil {
// Unable to send message // Unable to send message