forked from jshiffer/matterbridge
Refactor and add MediaDownloadSize to General
This commit is contained in:
parent
4a4a29c9f6
commit
265457b451
@ -13,11 +13,9 @@ import (
|
||||
)
|
||||
|
||||
type Api struct {
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
Messages ring.Ring
|
||||
sync.RWMutex
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
type ApiMessage struct {
|
||||
@ -35,14 +33,11 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Api {
|
||||
b := &Api{}
|
||||
func New(cfg *config.BridgeConfig) *Api {
|
||||
b := &Api{BridgeConfig: cfg}
|
||||
e := echo.New()
|
||||
b.Messages = ring.Ring{}
|
||||
b.Messages.SetCapacity(cfg.Buffer)
|
||||
b.Config = &cfg
|
||||
b.Account = account
|
||||
b.Remote = c
|
||||
b.Messages.SetCapacity(b.Config.Buffer)
|
||||
if b.Config.Token != "" {
|
||||
e.Use(middleware.KeyAuth(func(key string, c echo.Context) (bool, error) {
|
||||
return key == b.Config.Token, nil
|
||||
@ -52,7 +47,7 @@ func New(cfg config.Protocol, account string, c chan config.Message) *Api {
|
||||
e.GET("/api/stream", b.handleStream)
|
||||
e.POST("/api/message", b.handlePostMessage)
|
||||
go func() {
|
||||
flog.Fatal(e.Start(cfg.BindAddress))
|
||||
flog.Fatal(e.Start(b.Config.BindAddress))
|
||||
}()
|
||||
return b
|
||||
}
|
||||
|
@ -46,46 +46,47 @@ func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Brid
|
||||
b.Protocol = protocol
|
||||
b.Account = bridge.Account
|
||||
b.Joined = make(map[string]bool)
|
||||
bridgeConfig := &config.BridgeConfig{General: &cfg.General, Account: bridge.Account, Remote: c}
|
||||
|
||||
// override config from environment
|
||||
config.OverrideCfgFromEnv(cfg, protocol, name)
|
||||
switch protocol {
|
||||
case "mattermost":
|
||||
b.Config = cfg.Mattermost[name]
|
||||
b.Bridger = bmattermost.New(cfg.Mattermost[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Mattermost[name]
|
||||
b.Bridger = bmattermost.New(bridgeConfig)
|
||||
case "irc":
|
||||
b.Config = cfg.IRC[name]
|
||||
b.Bridger = birc.New(cfg.IRC[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.IRC[name]
|
||||
b.Bridger = birc.New(bridgeConfig)
|
||||
case "gitter":
|
||||
b.Config = cfg.Gitter[name]
|
||||
b.Bridger = bgitter.New(cfg.Gitter[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Gitter[name]
|
||||
b.Bridger = bgitter.New(bridgeConfig)
|
||||
case "slack":
|
||||
b.Config = cfg.Slack[name]
|
||||
b.Bridger = bslack.New(cfg.Slack[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Slack[name]
|
||||
b.Bridger = bslack.New(bridgeConfig)
|
||||
case "xmpp":
|
||||
b.Config = cfg.Xmpp[name]
|
||||
b.Bridger = bxmpp.New(cfg.Xmpp[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Xmpp[name]
|
||||
b.Bridger = bxmpp.New(bridgeConfig)
|
||||
case "discord":
|
||||
b.Config = cfg.Discord[name]
|
||||
b.Bridger = bdiscord.New(cfg.Discord[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Discord[name]
|
||||
b.Bridger = bdiscord.New(bridgeConfig)
|
||||
case "telegram":
|
||||
b.Config = cfg.Telegram[name]
|
||||
b.Bridger = btelegram.New(cfg.Telegram[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Telegram[name]
|
||||
b.Bridger = btelegram.New(bridgeConfig)
|
||||
case "rocketchat":
|
||||
b.Config = cfg.Rocketchat[name]
|
||||
b.Bridger = brocketchat.New(cfg.Rocketchat[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Rocketchat[name]
|
||||
b.Bridger = brocketchat.New(bridgeConfig)
|
||||
case "matrix":
|
||||
b.Config = cfg.Matrix[name]
|
||||
b.Bridger = bmatrix.New(cfg.Matrix[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Matrix[name]
|
||||
b.Bridger = bmatrix.New(bridgeConfig)
|
||||
case "steam":
|
||||
b.Config = cfg.Steam[name]
|
||||
b.Bridger = bsteam.New(cfg.Steam[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Steam[name]
|
||||
b.Bridger = bsteam.New(bridgeConfig)
|
||||
case "sshchat":
|
||||
b.Config = cfg.Sshchat[name]
|
||||
b.Bridger = bsshchat.New(cfg.Sshchat[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Sshchat[name]
|
||||
b.Bridger = bsshchat.New(bridgeConfig)
|
||||
case "api":
|
||||
b.Config = cfg.Api[name]
|
||||
b.Bridger = api.New(cfg.Api[name], bridge.Account, c)
|
||||
bridgeConfig.Config = cfg.Api[name]
|
||||
b.Bridger = api.New(bridgeConfig)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ type Protocol struct {
|
||||
IgnoreMessages string // all protocols
|
||||
Jid string // xmpp
|
||||
Login string // mattermost, matrix
|
||||
MediaDownloadSize int // all protocols
|
||||
MediaServerDownload string
|
||||
MediaServerUpload string
|
||||
MessageDelay int // IRC, time in millisecond to wait between messages
|
||||
@ -147,6 +148,13 @@ type Config struct {
|
||||
SameChannelGateway []SameChannelGateway
|
||||
}
|
||||
|
||||
type BridgeConfig struct {
|
||||
Config Protocol
|
||||
General *Protocol
|
||||
Account string
|
||||
Remote chan Message
|
||||
}
|
||||
|
||||
func NewConfig(cfgfile string) *Config {
|
||||
var cfg Config
|
||||
if _, err := toml.DecodeFile(cfgfile, &cfg); err != nil {
|
||||
|
@ -12,9 +12,6 @@ import (
|
||||
|
||||
type bdiscord struct {
|
||||
c *discordgo.Session
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
Channels []*discordgo.Channel
|
||||
Nick string
|
||||
UseChannelID bool
|
||||
@ -24,6 +21,7 @@ type bdiscord struct {
|
||||
webhookToken string
|
||||
channelInfoMap map[string]*config.ChannelInfo
|
||||
sync.RWMutex
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -33,11 +31,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *bdiscord {
|
||||
b := &bdiscord{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
func New(cfg *config.BridgeConfig) *bdiscord {
|
||||
b := &bdiscord{BridgeConfig: cfg}
|
||||
b.userMemberMap = make(map[string]*discordgo.Member)
|
||||
b.channelInfoMap = make(map[string]*config.ChannelInfo)
|
||||
if b.Config.WebhookURL != "" {
|
||||
|
@ -10,12 +10,10 @@ import (
|
||||
|
||||
type Bgitter struct {
|
||||
c *gitter.Gitter
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
User *gitter.User
|
||||
Users []gitter.User
|
||||
Rooms []gitter.Room
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -25,12 +23,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bgitter {
|
||||
b := &Bgitter{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
return b
|
||||
func New(cfg *config.BridgeConfig) *Bgitter {
|
||||
return &Bgitter{BridgeConfig: cfg}
|
||||
}
|
||||
|
||||
func (b *Bgitter) Connect() error {
|
||||
|
@ -25,12 +25,11 @@ type Birc struct {
|
||||
i *girc.Client
|
||||
Nick string
|
||||
names map[string][]string
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
connected chan struct{}
|
||||
Local chan config.Message // local queue for flood control
|
||||
Account string
|
||||
FirstConnection bool
|
||||
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -40,13 +39,11 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Birc {
|
||||
func New(cfg *config.BridgeConfig) *Birc {
|
||||
b := &Birc{}
|
||||
b.Config = &cfg
|
||||
b.BridgeConfig = cfg
|
||||
b.Nick = b.Config.Nick
|
||||
b.Remote = c
|
||||
b.names = make(map[string][]string)
|
||||
b.Account = account
|
||||
b.connected = make(chan struct{})
|
||||
if b.Config.MessageDelay == 0 {
|
||||
b.Config.MessageDelay = 1300
|
||||
|
@ -15,12 +15,10 @@ import (
|
||||
|
||||
type Bmatrix struct {
|
||||
mc *matrix.Client
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
UserID string
|
||||
RoomMap map[string]string
|
||||
sync.RWMutex
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -30,12 +28,9 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bmatrix {
|
||||
b := &Bmatrix{}
|
||||
func New(cfg *config.BridgeConfig) *Bmatrix {
|
||||
b := &Bmatrix{BridgeConfig: cfg}
|
||||
b.RoomMap = make(map[string]string)
|
||||
b.Config = &cfg
|
||||
b.Account = account
|
||||
b.Remote = c
|
||||
return b
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ type Bmattermost struct {
|
||||
Remote chan config.Message
|
||||
TeamId string
|
||||
Account string
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -45,11 +46,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bmattermost {
|
||||
b := &Bmattermost{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
func New(cfg *config.BridgeConfig) *Bmattermost {
|
||||
b := &Bmattermost{BridgeConfig: cfg}
|
||||
b.mmMap = make(map[string]string)
|
||||
return b
|
||||
}
|
||||
|
@ -14,9 +14,7 @@ type MMhook struct {
|
||||
|
||||
type Brocketchat struct {
|
||||
MMhook
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -26,12 +24,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Brocketchat {
|
||||
b := &Brocketchat{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
return b
|
||||
func New(cfg *config.BridgeConfig) *Brocketchat {
|
||||
return &Brocketchat{BridgeConfig: cfg}
|
||||
}
|
||||
|
||||
func (b *Brocketchat) Command(cmd string) string {
|
||||
|
@ -27,14 +27,12 @@ type MMMessage struct {
|
||||
type Bslack struct {
|
||||
mh *matterhook.Client
|
||||
sc *slack.Client
|
||||
Config *config.Protocol
|
||||
rtm *slack.RTM
|
||||
Plus bool
|
||||
Remote chan config.Message
|
||||
Users []slack.User
|
||||
Account string
|
||||
si *slack.Info
|
||||
channels []slack.Channel
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -44,12 +42,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bslack {
|
||||
b := &Bslack{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
return b
|
||||
func New(cfg *config.BridgeConfig) *Bslack {
|
||||
return &Bslack{BridgeConfig: cfg}
|
||||
}
|
||||
|
||||
func (b *Bslack) Command(cmd string) string {
|
||||
@ -161,7 +155,7 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
|
||||
np.AsUser = true
|
||||
}
|
||||
np.Username = nick
|
||||
np.IconURL = config.GetIconURL(&msg, b.Config)
|
||||
np.IconURL = config.GetIconURL(&msg, &b.Config)
|
||||
if msg.Avatar != "" {
|
||||
np.IconURL = msg.Avatar
|
||||
}
|
||||
|
@ -12,9 +12,7 @@ import (
|
||||
type Bsshchat struct {
|
||||
r *bufio.Scanner
|
||||
w io.WriteCloser
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -24,12 +22,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bsshchat {
|
||||
b := &Bsshchat{}
|
||||
b.Config = &cfg
|
||||
b.Account = account
|
||||
b.Remote = c
|
||||
return b
|
||||
func New(cfg *config.BridgeConfig) *Bsshchat {
|
||||
return &Bsshchat{BridgeConfig: cfg}
|
||||
}
|
||||
|
||||
func (b *Bsshchat) Connect() error {
|
||||
|
@ -16,11 +16,9 @@ import (
|
||||
type Bsteam struct {
|
||||
c *steam.Client
|
||||
connected chan struct{}
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
userMap map[steamid.SteamId]string
|
||||
sync.RWMutex
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -30,11 +28,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bsteam {
|
||||
b := &Bsteam{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
func New(cfg *config.BridgeConfig) *Bsteam {
|
||||
b := &Bsteam{BridgeConfig: cfg}
|
||||
b.userMap = make(map[steamid.SteamId]string)
|
||||
b.connected = make(chan struct{})
|
||||
return b
|
||||
|
@ -13,9 +13,7 @@ import (
|
||||
|
||||
type Btelegram struct {
|
||||
c *tgbotapi.BotAPI
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -25,12 +23,8 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Btelegram {
|
||||
b := &Btelegram{}
|
||||
b.Config = &cfg
|
||||
b.Remote = c
|
||||
b.Account = account
|
||||
return b
|
||||
func New(cfg *config.BridgeConfig) *Btelegram {
|
||||
return &Btelegram{BridgeConfig: cfg}
|
||||
}
|
||||
|
||||
func (b *Btelegram) Connect() error {
|
||||
|
@ -14,9 +14,7 @@ import (
|
||||
type Bxmpp struct {
|
||||
xc *xmpp.Client
|
||||
xmppMap map[string]string
|
||||
Config *config.Protocol
|
||||
Remote chan config.Message
|
||||
Account string
|
||||
*config.BridgeConfig
|
||||
}
|
||||
|
||||
var flog *log.Entry
|
||||
@ -26,12 +24,9 @@ func init() {
|
||||
flog = log.WithFields(log.Fields{"module": protocol})
|
||||
}
|
||||
|
||||
func New(cfg config.Protocol, account string, c chan config.Message) *Bxmpp {
|
||||
b := &Bxmpp{}
|
||||
func New(cfg *config.BridgeConfig) *Bxmpp {
|
||||
b := &Bxmpp{BridgeConfig: cfg}
|
||||
b.xmppMap = make(map[string]string)
|
||||
b.Config = &cfg
|
||||
b.Account = account
|
||||
b.Remote = c
|
||||
return b
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user