@@ -2,6 +2,7 @@ package main
22
33import (
44 "flag"
5+ "fmt"
56 "os"
67 "os/signal"
78 "path/filepath"
@@ -85,8 +86,14 @@ func main() {
8586 * insecure = viper .GetBool ("insecure" )
8687 }
8788 //
88- discordFormat := viper .GetStringMapString ("discord_format" )
89- discordFormat = setupDiscordFormat (discordFormat )
89+ rawDiscordFormat := viper .GetStringMapString ("discord_format" )
90+ var discordFormat map [string ]string
91+ if df , err := setupDiscordFormat (rawDiscordFormat ); err == nil {
92+ discordFormat = df
93+ } else {
94+ log .WithError (err ).Fatal ("discord_format setting is invalid" )
95+ return
96+ }
9097 //
9198 viper .SetDefault ("avatar_url" , "https://ui-avatars.com/api/?name=${USERNAME}" )
9299 avatarURL := viper .GetString ("avatar_url" )
@@ -217,6 +224,14 @@ func main() {
217224 }
218225 dib .Config .DiscordIgnores = discordIgnores
219226
227+ rawDiscordFormat := viper .GetStringMapString ("discord_format" )
228+ if discordFormat , err := setupDiscordFormat (rawDiscordFormat ); err == nil {
229+ dib .Config .DiscordFormat = discordFormat
230+ } else {
231+ log .WithError (err ).Error ("discord_format setting is invalid, this setting has not been updated" )
232+ }
233+ dib .Config .IRCFormat = viper .GetString ("irc_format" )
234+
220235 chans := viper .GetStringMapString ("channel_mappings" )
221236 equalChans := reflect .DeepEqual (chans , channelMappings )
222237 if ! equalChans {
@@ -257,7 +272,8 @@ func setupHostmaskMatchers(hostmasks []string) []glob.Glob {
257272 return matchers
258273}
259274
260- func setupDiscordFormat (discordFormat map [string ]string ) map [string ]string {
275+ func setupDiscordFormat (discordFormat map [string ]string ) (map [string ]string , error ) {
276+ var err error
261277 // lowercase to match that YAML lowercases it
262278 discordFormatDefaults := map [string ]string {
263279 "join" : "_${NICK} joined (${IDENT}@${HOST})_" ,
@@ -272,7 +288,14 @@ func setupDiscordFormat(discordFormat map[string]string) map[string]string {
272288 }
273289 }
274290
275- return discordFormat
291+ for ev := range discordFormat {
292+ if _ , ok := discordFormatDefaults [ev ]; ! ok {
293+ err = fmt .Errorf ("Unknown format key %s" , ev )
294+ break
295+ }
296+ }
297+
298+ return discordFormat , err
276299}
277300
278301func SetLogDebug (debug bool ) {
0 commit comments