diff --git a/bridge/irc_manager.go b/bridge/irc_manager.go index 916cea6..4484173 100644 --- a/bridge/irc_manager.go +++ b/bridge/irc_manager.go @@ -361,15 +361,7 @@ func (m *IRCManager) SendMessage(channel string, msg *DiscordMessage) { // Person is appearing offline (or the bridge is running in Simple Mode) if !ok { - // length := len(msg.Author.Username) for _, line := range strings.Split(content, "\n") { - // m.bridge.ircListener.Privmsg(channel, fmt.Sprintf( - // "<%s#%s> %s", - // msg.Author.Username[:1]+"\u200B"+msg.Author.Username[1:length], - // msg.Author.Discriminator, - // line, - // )) - m.bridge.ircListener.Privmsg(channel, m.formatIRCMessage(msg, line)) } return diff --git a/main.go b/main.go index 686df34..042f3df 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "os" "os/signal" "path/filepath" @@ -92,8 +93,14 @@ func main() { // viper.SetDefault("irc_puppet_prejoin_commands", []string{"MODE ${NICK} +D"}) ircPuppetPrejoinCommands := viper.GetStringSlice("irc_puppet_prejoin_commands") // Commands for each connection to send before joining channels - discordFormat := viper.GetStringMapString("discord_format") - discordFormat = setupDiscordFormat(discordFormat) + rawDiscordFormat := viper.GetStringMapString("discord_format") + var discordFormat map[string]string + if df, err := setupDiscordFormat(rawDiscordFormat); err == nil { + discordFormat = df + } else { + log.WithError(err).Fatal("discord_format setting is invalid") + return + } // viper.SetDefault("avatar_url", "https://ui-avatars.com/api/?name=${USERNAME}") avatarURL := viper.GetString("avatar_url") @@ -226,6 +233,14 @@ func main() { } dib.Config.DiscordIgnores = discordIgnores + rawDiscordFormat := viper.GetStringMapString("discord_format") + if discordFormat, err := setupDiscordFormat(rawDiscordFormat); err == nil { + dib.Config.DiscordFormat = discordFormat + } else { + log.WithError(err).Error("discord_format setting is invalid, this setting has not been updated") + } + dib.Config.IRCFormat = viper.GetString("irc_format") + chans := viper.GetStringMapString("channel_mappings") equalChans := reflect.DeepEqual(chans, channelMappings) if !equalChans { @@ -266,7 +281,8 @@ func setupHostmaskMatchers(hostmasks []string) []glob.Glob { return matchers } -func setupDiscordFormat(discordFormat map[string]string) map[string]string { +func setupDiscordFormat(discordFormat map[string]string) (map[string]string, error) { + var err error // lowercase to match that YAML lowercases it discordFormatDefaults := map[string]string{ "join": "_${NICK} joined (${IDENT}@${HOST})_", @@ -281,7 +297,14 @@ func setupDiscordFormat(discordFormat map[string]string) map[string]string { } } - return discordFormat + for ev := range discordFormat { + if _, ok := discordFormatDefaults[ev]; !ok { + err = fmt.Errorf("Unknown format key %s", ev) + break + } + } + + return discordFormat, err } func SetLogDebug(debug bool) {