Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 6c79df9034fc48df86ea75af3ba3b36fbb1ca1a9 Author: Wim <wim@42.be> Date: Tue May 01 22:23:37 2018 +0000 Add support for reloading all settings automatically after changing config except connection and gateway configuration. Closes #373 diff --git a/bridge/config/config.go b/bridge/config/config.go index 09f15c2..1b92f83 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -28 +210 @@ 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" @@ -1699 +17113 @@ 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) @@ -1916 +19711 @@ 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 91a87c4..f814f1a 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -646 +649 @@ 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) @@ -1846 +1879 @@ 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 @@ -2656 +2719 @@ 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 @@ -3826 +3919 @@ 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) @@ -4826 +4949 @@ 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 @@ -5776 +5929 @@ 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) @@ -6806 +6989 @@ 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 @@ -7706 +7919 @@ 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 @@ -8926 +9169 @@ 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 @@ -9796 +10069 @@ 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 @@ -10606 +10909 @@ 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 @@ -11626 +119510 @@ 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