[BUGFIX] do not answer of history (+ improve logging)

This commit is contained in:
Martin/Geno 2018-09-06 13:40:56 +02:00
parent 73c4a38940
commit 1a129edd21
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 20 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
xmpp_client "dev.sum7.eu/genofire/yaja/client" xmpp_client "dev.sum7.eu/genofire/yaja/client"
xmpp "dev.sum7.eu/genofire/yaja/xmpp" xmpp "dev.sum7.eu/genofire/yaja/xmpp"
"dev.sum7.eu/genofire/yaja/xmpp/base" "dev.sum7.eu/genofire/yaja/xmpp/base"
"dev.sum7.eu/genofire/yaja/xmpp/x/muc"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -20,6 +21,8 @@ const (
nickname = "logmania" nickname = "logmania"
) )
var historyMaxChars = 0
var logger = log.WithField("output", proto) var logger = log.WithField("output", proto)
type Output struct { type Output struct {
@ -44,7 +47,13 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
} }
channels := make(map[string]bool) channels := make(map[string]bool)
client, err := xmpp_client.NewClient(xmppbase.NewJID(config.JID), config.Password) jid := xmppbase.NewJID(config.JID)
client := &xmpp_client.Client{
JID: jid,
Logging: logger.WithField("jid", jid.String()),
}
err := client.Connect(config.Password)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
return nil return nil
@ -132,6 +141,11 @@ func Init(configInterface interface{}, db *database.DB, bot *bot.Bot) output.Out
toJID.Resource = nickname toJID.Resource = nickname
err := client.Send(&xmpp.PresenceClient{ err := client.Send(&xmpp.PresenceClient{
To: toJID, To: toJID,
MUC: &xmuc.Base{
History: &xmuc.History{
MaxChars: &historyMaxChars,
},
},
}) })
if err != nil { if err != nil {
logger.Error("xmpp could not join ", toJID.String(), " error:", err) logger.Error("xmpp could not join ", toJID.String(), " error:", err)
@ -180,6 +194,11 @@ func (out *Output) Send(e *log.Entry, to *database.Notify) bool {
toJID.Resource = nickname toJID.Resource = nickname
err := out.client.Send(&xmpp.PresenceClient{ err := out.client.Send(&xmpp.PresenceClient{
To: toJID, To: toJID,
MUC: &xmuc.Base{
History: &xmuc.History{
MaxChars: &historyMaxChars,
},
},
}) })
if err != nil { if err != nil {
logger.Error("xmpp could not join ", toJID.String(), " error:", err) logger.Error("xmpp could not join ", toJID.String(), " error:", err)