From 96a47a60adc3301106c3f27c39c0ba03e2ebe177 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 1 May 2018 22:23:37 +0200 Subject: Add support for reloading all settings automatically after changing config except connection and gateway configuration. Closes #373 --- bridge/config/config.go | 11 +++++++++++ matterbridge.toml.sample | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/bridge/config/config.go b/bridge/config/config.go index 09f15c2e..1b92f83c 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -2,8 +2,10 @@ package config import ( "bytes" + "github.com/fsnotify/fsnotify" log "github.com/sirupsen/logrus" "github.com/spf13/viper" + prefixed "github.com/x-cray/logrus-prefixed-formatter" "os" "strings" "sync" @@ -169,9 +171,13 @@ type Config struct { } func NewConfig(cfgfile string) *Config { + log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: false}) + flog := log.WithFields(log.Fields{"prefix": "config"}) var cfg ConfigValues viper.SetConfigType("toml") + viper.SetConfigFile(cfgfile) viper.SetEnvPrefix("matterbridge") + viper.AddConfigPath(".") viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() f, err := os.Open(cfgfile) @@ -191,6 +197,11 @@ func NewConfig(cfgfile string) *Config { if cfg.General.MediaDownloadSize == 0 { cfg.General.MediaDownloadSize = 1000000 } + viper.WatchConfig() + viper.OnConfigChange(func(e fsnotify.Event) { + flog.Println("Config file changed:", e.Name) + }) + mycfg.ConfigValues = &cfg return mycfg } diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 91a87c47..f814f1a7 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -64,6 +64,9 @@ NickServPassword="secret" #OPTIONAL only used for quakenet auth NickServUsername="username" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Flood control #Delay in milliseconds between each message send to the IRC server #OPTIONAL (default 1300) @@ -184,6 +187,9 @@ Nick="xmppbot" #OPTIONAL (default false) SkipTLSVerify=true +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Nicks you want to ignore. #Messages from those users will not be sent to other bridges. #OPTIONAL @@ -265,6 +271,9 @@ Muc="conf.hipchat.com" #REQUIRED Nick="yourlogin" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Nicks you want to ignore. #Messages from those users will not be sent to other bridges. #OPTIONAL @@ -382,6 +391,9 @@ IconURL="http://youricon.png" #OPTIONAL (default false) SkipTLSVerify=true +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #how to format the list of IRC nicks when displayed in mattermost. #Possible options are "table" and "plain" #OPTIONAL (default plain) @@ -482,6 +494,9 @@ ShowTopicChange=false #REQUIRED Token="Yourtokenhere" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Nicks you want to ignore. #Messages from those users will not be sent to other bridges. #OPTIONAL @@ -577,6 +592,9 @@ WebhookBindAddress="0.0.0.0:9999" #OPTIONAL IconURL="https://robohash.org/{NICK}.png?size=48x48" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #how to format the list of IRC nicks when displayed in slack #Possible options are "table" and "plain" #OPTIONAL (default plain) @@ -680,6 +698,9 @@ Token="Yourtokenhere" #REQUIRED Server="yourservername" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Shows title, description and URL of embedded messages (sent by other bots) #OPTIONAL (default false) ShowEmbeds=false @@ -770,6 +791,9 @@ ShowTopicChange=false #REQUIRED Token="Yourtokenhere" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #OPTIONAL (default empty) #Only supported format is "HTML", messages will be sent in html parsemode. #See https://core.telegram.org/bots/api#html-style @@ -892,6 +916,9 @@ NoTLS=false #OPTIONAL (default false) SkipTLSVerify=true +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Whether to prefix messages from other bridges to rocketchat with the sender's nick. #Useful if username overrides for incoming webhooks isn't enabled on the #rocketchat server. If you set PrefixMessagesWithNick to true, each message @@ -979,6 +1006,9 @@ Password="yourpass" #OPTIONAL (default false) NoHomeServerSuffix=false +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Whether to prefix messages from other bridges to matrix with the sender's nick. #Useful if username overrides for incoming webhooks isn't enabled on the #matrix server. If you set PrefixMessagesWithNick to true, each message @@ -1060,6 +1090,9 @@ Password="yourpass" #OPTIONAL Authcode="ABCE12" +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #Whether to prefix messages from other bridges to matrix with the sender's nick. #Useful if username overrides for incoming webhooks isn't enabled on the #matrix server. If you set PrefixMessagesWithNick to true, each message @@ -1162,6 +1195,10 @@ RemoteNickFormat="{NICK}" ################################################################### # Settings here are defaults that each protocol can override [general] + +## RELOADABLE SETTINGS +## Settings below can be reloaded by editing the file + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge -- cgit v1.2.3