@@ -2,6 +2,7 @@ package main
22
33import (
44 "flag"
5+ "fmt"
56 "os"
67 "os/signal"
78 "path/filepath"
@@ -92,8 +93,14 @@ func main() {
9293 //
9394 viper .SetDefault ("irc_puppet_prejoin_commands" , []string {"MODE ${NICK} +D" })
9495 ircPuppetPrejoinCommands := viper .GetStringSlice ("irc_puppet_prejoin_commands" ) // Commands for each connection to send before joining channels
95- discordFormat := viper .GetStringMapString ("discord_format" )
96- discordFormat = setupDiscordFormat (discordFormat )
96+ rawDiscordFormat := viper .GetStringMapString ("discord_format" )
97+ var discordFormat map [string ]string
98+ if df , err := setupDiscordFormat (rawDiscordFormat ); err == nil {
99+ discordFormat = df
100+ } else {
101+ log .WithError (err ).Fatal ("discord_format setting is invalid" )
102+ return
103+ }
97104 //
98105 viper .SetDefault ("avatar_url" , "https://ui-avatars.com/api/?name=${USERNAME}" )
99106 avatarURL := viper .GetString ("avatar_url" )
@@ -226,6 +233,14 @@ func main() {
226233 }
227234 dib .Config .DiscordIgnores = discordIgnores
228235
236+ rawDiscordFormat := viper .GetStringMapString ("discord_format" )
237+ if discordFormat , err := setupDiscordFormat (rawDiscordFormat ); err == nil {
238+ dib .Config .DiscordFormat = discordFormat
239+ } else {
240+ log .WithError (err ).Error ("discord_format setting is invalid, this setting has not been updated" )
241+ }
242+ dib .Config .IRCFormat = viper .GetString ("irc_format" )
243+
229244 chans := viper .GetStringMapString ("channel_mappings" )
230245 equalChans := reflect .DeepEqual (chans , channelMappings )
231246 if ! equalChans {
@@ -266,9 +281,11 @@ func setupHostmaskMatchers(hostmasks []string) []glob.Glob {
266281 return matchers
267282}
268283
269- func setupDiscordFormat (discordFormat map [string ]string ) map [string ]string {
284+ func setupDiscordFormat (discordFormat map [string ]string ) (map [string ]string , error ) {
285+ var err error
270286 // lowercase to match that YAML lowercases it
271287 discordFormatDefaults := map [string ]string {
288+ "pm" : "${SERVER},${NICK}!${IDENT}@${HOST} - ${NICK}@${DISCRIMINATOR}: ${CONTENT}" ,
272289 "join" : "_${NICK} joined (${IDENT}@${HOST})_" ,
273290 "part" : "_${NICK} left (${IDENT}@${HOST}) - ${CONTENT}_" ,
274291 "quit" : "_${NICK} quit (${IDENT}@${HOST}) - Quit: ${CONTENT}_" ,
@@ -281,7 +298,14 @@ func setupDiscordFormat(discordFormat map[string]string) map[string]string {
281298 }
282299 }
283300
284- return discordFormat
301+ for ev := range discordFormat {
302+ if _ , ok := discordFormatDefaults [ev ]; ! ok {
303+ err = fmt .Errorf ("Unknown format key %s" , ev )
304+ break
305+ }
306+ }
307+
308+ return discordFormat , err
285309}
286310
287311func SetLogDebug (debug bool ) {
0 commit comments