get PersistentMessageStorePath config properly

(also reformatted and sorted the config struct)
This commit is contained in:
Yousef Mansy 2023-03-11 15:42:42 -08:00
parent 2845740e97
commit 60219a39d1
2 changed files with 96 additions and 93 deletions

View File

@ -87,95 +87,96 @@ type ChannelMember struct {
type ChannelMembers []ChannelMember type ChannelMembers []ChannelMember
type Protocol struct { type Protocol struct {
AllowMention []string // discord AllowMention []string // discord
AuthCode string // steam AuthCode string // steam
BindAddress string // mattermost, slack // DEPRECATED BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api Buffer int // api
Charset string // irc Charset string // irc
ClientID string // msteams ClientID string // msteams
ColorNicks bool // only irc for now ColorNicks bool // only irc for now
Debug bool // general Debug bool // general
DebugLevel int // only for irc now DebugLevel int // only for irc now
DisableWebPagePreview bool // telegram DisableWebPagePreview bool // telegram
EditSuffix string // mattermost, slack, discord, telegram, gitter EditDisable bool // mattermost, slack, discord, telegram, gitter
EditDisable bool // mattermost, slack, discord, telegram, gitter EditSuffix string // mattermost, slack, discord, telegram, gitter
HTMLDisable bool // matrix HTMLDisable bool // matrix
IconURL string // mattermost, slack IconURL string // mattermost, slack
IgnoreFailureOnStart bool // general IgnoreFailureOnStart bool // general
IgnoreNicks string // all protocols IgnoreMessages string // all protocols
IgnoreMessages string // all protocols IgnoreNicks string // all protocols
Jid string // xmpp Jid string // xmpp
JoinDelay string // all protocols JoinDelay string // all protocols
Label string // all protocols Label string // all protocols
Login string // mattermost, matrix LogFile string // general
LogFile string // general Login string // mattermost, matrix
MediaDownloadBlackList []string MediaConvertTgs string // telegram
MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server. MediaConvertWebPToPNG bool // telegram
MediaDownloadSize int // all protocols MediaDownloadBlackList []string // all protocols
MediaServerDownload string MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server.
MediaServerUpload string MediaDownloadSize int // all protocols
MediaConvertTgs string // telegram MediaServerDownload string // all protocols
MediaConvertWebPToPNG bool // telegram MediaServerUpload string // all protocols
MessageDelay int // IRC, time in millisecond to wait between messages MessageDelay int // IRC, time in millisecond to wait between messages
MessageFormat string // telegram MessageFormat string // telegram
MessageLength int // IRC, max length of a message allowed MessageLength int // IRC, max length of a message allowed
MessageQueue int // IRC, size of message queue for flood control MessageQueue int // IRC, size of message queue for flood control
MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping
Muc string // xmpp Muc string // xmpp
MxID string // matrix MxID string // matrix
Name string // all protocols Name string // all protocols
Nick string // all protocols Nick string // all protocols
NickFormatter string // mattermost, slack NickFormatter string // mattermost, slack
NickServNick string // IRC NickServNick string // IRC
NickServUsername string // IRC NickServPassword string // IRC
NickServPassword string // IRC NickServUsername string // IRC
NicksPerRow int // mattermost, slack NicksPerRow int // mattermost, slack
NoHomeServerSuffix bool // matrix NoHomeServerSuffix bool // matrix
NoSendJoinPart bool // all protocols NoSendJoinPart bool // all protocols
NoTLS bool // mattermost, xmpp NoTLS bool // mattermost, xmpp
Password string // IRC,mattermost,XMPP,matrix Password string // IRC,mattermost,XMPP,matrix
PrefixMessagesWithNick bool // mattemost, slack PersistentMessageStorePath string // all protocols
PreserveThreading bool // slack PrefixMessagesWithNick bool // mattemost, slack
Protocol string // all protocols PreserveThreading bool // slack, discord, telegram, whatsapp
QuoteDisable bool // telegram Protocol string // all protocols
QuoteFormat string // telegram QuoteDisable bool // telegram
QuoteLengthLimit int // telegram QuoteFormat string // telegram
RealName string // IRC QuoteLengthLimit int // telegram
RejoinDelay int // IRC RealName string // IRC
ReplaceMessages [][]string // all protocols RejoinDelay int // IRC
ReplaceNicks [][]string // all protocols RemoteNickFormat string // all protocols
RemoteNickFormat string // all protocols ReplaceMessages [][]string // all protocols
RunCommands []string // IRC ReplaceNicks [][]string // all protocols
Server string // IRC,mattermost,XMPP,discord,matrix RunCommands []string // IRC
SessionFile string // msteams,whatsapp Server string // IRC,mattermost,XMPP,discord,matrix
ShowJoinPart bool // all protocols SessionFile string // msteams,whatsapp
ShowTopicChange bool // slack ShowEmbeds bool // discord
ShowUserTyping bool // slack ShowJoinPart bool // all protocols
ShowEmbeds bool // discord ShowTopicChange bool // slack
SkipTLSVerify bool // IRC, mattermost ShowUserTyping bool // slack
SkipVersionCheck bool // mattermost SkipTLSVerify bool // IRC, mattermost
StripNick bool // all protocols SkipVersionCheck bool // mattermost
StripMarkdown bool // irc StripMarkdown bool // irc
SyncTopic bool // slack StripNick bool // all protocols
TengoModifyMessage string // general SyncTopic bool // slack
Team string // mattermost, keybase Team string // mattermost, keybase
TeamID string // msteams TeamID string // msteams
TenantID string // msteams TenantID string // msteams
Token string // gitter, slack, discord, api, matrix TengoModifyMessage string // general
Topic string // zulip Token string // gitter, slack, discord, api, matrix
URL string // mattermost, slack // DEPRECATED Topic string // zulip
UseAPI bool // mattermost, slack URL string // mattermost, slack // DEPRECATED
UseLocalAvatar []string // discord UseAPI bool // mattermost, slack
UseSASL bool // IRC UseDiscriminator bool // discord
UseTLS bool // IRC UseFirstName bool // telegram
UseDiscriminator bool // discord UseInsecureURL bool // telegram
UseFirstName bool // telegram UseLocalAvatar []string // discord
UseUserName bool // discord, matrix, mattermost UserName string // IRC
UseInsecureURL bool // telegram UseSASL bool // IRC
UserName string // IRC UseTLS bool // IRC
VerboseJoinPart bool // IRC UseUserName bool // discord, matrix, mattermost
WebhookBindAddress string // mattermost, slack VerboseJoinPart bool // IRC
WebhookURL string // mattermost, slack WebhookBindAddress string // mattermost, slack
WebhookURL string // mattermost, slack
} }
type ChannelOptions struct { type ChannelOptions struct {

View File

@ -64,7 +64,9 @@ func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) (*Gateway, e
logger.Errorf("Failed to add configuration to gateway: %#v", err) logger.Errorf("Failed to add configuration to gateway: %#v", err)
} }
persistentMessageStorePath, usePersistent := gw.Config.GetString("PersistentMessageStorePath") persistentMessageStorePath := gw.BridgeValues().General.PersistentMessageStorePath
usePersistent := persistentMessageStorePath != ""
if usePersistent { if usePersistent {
rootPath := fmt.Sprintf("%s/%s", persistentMessageStorePath, gw.Name) rootPath := fmt.Sprintf("%s/%s", persistentMessageStorePath, gw.Name)
err := os.MkdirAll(rootPath, os.ModePerm) err := os.MkdirAll(rootPath, os.ModePerm)
@ -89,7 +91,7 @@ func New(rootLogger *logrus.Logger, cfg *config.Gateway, r *Router) (*Gateway, e
} }
func (gw *Gateway) SetMessageMap(canonicalMsgID string, msgIDs []*BrMsgID) { func (gw *Gateway) SetMessageMap(canonicalMsgID string, msgIDs []*BrMsgID) {
_, usePersistent := gw.Config.GetString("PersistentMessageStorePath") usePersistent := gw.BridgeValues().General.PersistentMessageStorePath != ""
if usePersistent { if usePersistent {
gw.setDestMessagesToStore(canonicalMsgID, msgIDs) gw.setDestMessagesToStore(canonicalMsgID, msgIDs)
} else { } else {
@ -101,7 +103,7 @@ func (gw *Gateway) SetMessageMap(canonicalMsgID string, msgIDs []*BrMsgID) {
func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string { func (gw *Gateway) FindCanonicalMsgID(protocol string, mID string) string {
ID := protocol + " " + mID ID := protocol + " " + mID
_, usePersistent := gw.Config.GetString("PersistentMessageStorePath") usePersistent := gw.BridgeValues().General.PersistentMessageStorePath != ""
if usePersistent { if usePersistent {
return gw.getCanonicalMessageFromStore(ID) return gw.getCanonicalMessageFromStore(ID)
} else { } else {
@ -306,7 +308,7 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
func (gw *Gateway) getDestMsgID(msgID string, dest *bridge.Bridge, channel *config.ChannelInfo) string { func (gw *Gateway) getDestMsgID(msgID string, dest *bridge.Bridge, channel *config.ChannelInfo) string {
var destID string var destID string
_, usePersistent := gw.Config.GetString("PersistentMessageStorePath") usePersistent := gw.BridgeValues().General.PersistentMessageStorePath != ""
if usePersistent { if usePersistent {
destID = gw.getDestMessagesFromStore(msgID, dest, channel) destID = gw.getDestMessagesFromStore(msgID, dest, channel)
} else { } else {