Support message placeholders and configuration of message
This commit is contained in:
		
							
								
								
									
										10
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.go
									
									
									
									
									
								
							@ -21,10 +21,14 @@ var (
 | 
			
		||||
func setupConfiguration() {
 | 
			
		||||
	viper.SetDefault("prohibitedPhrases", "")
 | 
			
		||||
	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.SetConfigName("ottomate")
 | 
			
		||||
	viper.AddConfigPath("/etc/ottomate/")
 | 
			
		||||
	viper.AddConfigPath("$HOME/.ottomate")
 | 
			
		||||
	viper.AddConfigPath(".")
 | 
			
		||||
 | 
			
		||||
	viper.ReadInConfig()
 | 
			
		||||
}
 | 
			
		||||
@ -154,7 +158,11 @@ func messageCreate(e *gateway.MessageCreateEvent) {
 | 
			
		||||
		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 {
 | 
			
		||||
		// Unable to send message
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user