mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-23 11:12:02 -08:00
parent
b24e1bafa1
commit
c1c732b87a
@ -16,7 +16,11 @@ import (
|
||||
|
||||
"golang.org/x/image/webp"
|
||||
|
||||
"github.com/42wim/matterbridge/bridge"
|
||||
"github.com/42wim/matterbridge/bridge/config"
|
||||
"github.com/42wim/matterbridge/internal"
|
||||
"github.com/d5/tengo/v2"
|
||||
"github.com/d5/tengo/v2/stdlib"
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
@ -114,6 +118,62 @@ func GetAvatar(av map[string]string, userid string, general *config.Protocol) st
|
||||
return ""
|
||||
}
|
||||
|
||||
func handleDownloadTengo(br *bridge.Bridge, msg *config.Message, name string, size int64, general *config.Protocol) (bool, error) {
|
||||
var (
|
||||
res []byte
|
||||
err error
|
||||
drop bool
|
||||
)
|
||||
|
||||
filename := br.GetString("tengo.download")
|
||||
|
||||
if filename == "" {
|
||||
res, err = internal.Asset("tengo/download.tengo")
|
||||
if err != nil {
|
||||
return drop, err
|
||||
}
|
||||
} else {
|
||||
res, err = ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return drop, err
|
||||
}
|
||||
}
|
||||
|
||||
s := tengo.NewScript(res)
|
||||
|
||||
s.SetImports(stdlib.GetModuleMap(stdlib.AllModuleNames()...))
|
||||
|
||||
_ = s.Add("inAccount", msg.Account)
|
||||
_ = s.Add("inProtocol", msg.Protocol)
|
||||
_ = s.Add("inChannel", msg.Channel)
|
||||
_ = s.Add("inGateway", msg.Gateway)
|
||||
_ = s.Add("inEvent", msg.Event)
|
||||
_ = s.Add("outAccount", br.Account)
|
||||
_ = s.Add("outProtocol", br.Protocol)
|
||||
_ = s.Add("outChannel", msg.Channel)
|
||||
_ = s.Add("outEvent", msg.Event)
|
||||
_ = s.Add("msgText", msg.Text)
|
||||
_ = s.Add("msgUsername", msg.Username)
|
||||
_ = s.Add("msgDrop", drop)
|
||||
_ = s.Add("downloadName", name)
|
||||
_ = s.Add("downloadSize", size)
|
||||
|
||||
c, err := s.Compile()
|
||||
if err != nil {
|
||||
return drop, err
|
||||
}
|
||||
|
||||
if err := c.Run(); err != nil {
|
||||
return drop, err
|
||||
}
|
||||
|
||||
drop = c.Get("msgDrop").Bool()
|
||||
msg.Text = c.Get("msgText").String()
|
||||
msg.Username = c.Get("msgUsername").String()
|
||||
|
||||
return drop, nil
|
||||
}
|
||||
|
||||
// HandleDownloadSize checks a specified filename against the configured download blacklist
|
||||
// and checks a specified file-size against the configure limit.
|
||||
func HandleDownloadSize(logger *logrus.Entry, msg *config.Message, name string, size int64, general *config.Protocol) error {
|
||||
|
Loading…
Reference in New Issue
Block a user