Merge branch 'develop'

This commit is contained in:
zhaoYangguang 2020-12-17 16:55:58 +08:00
commit ec15c6cb69
3 changed files with 16 additions and 5 deletions

View File

@ -50,11 +50,11 @@ type CommandEvent struct {
func (ce *CommandEvent) Reply(msg string, args ...interface{}) { func (ce *CommandEvent) Reply(msg string, args ...interface{}) {
content := format.RenderMarkdown(fmt.Sprintf(msg, args...), true, false) content := format.RenderMarkdown(fmt.Sprintf(msg, args...), true, false)
content.MsgType = event.MsgNotice content.MsgType = event.MsgNotice
room := ce.User.ManagementRoom intent := ce.Bot
if len(room) == 0 { if ce.Portal != nil && ce.Portal.IsPrivateChat() {
room = ce.RoomID intent = ce.Portal.MainIntent()
} }
_, err := ce.Bot.SendMessageEvent(room, event.EventMessage, content) _, err := intent.SendMessageEvent(ce.RoomID, event.EventMessage, content)
if err != nil { if err != nil {
ce.Handler.log.Warnfln("Failed to reply to command from %s: %v", ce.User.MXID, err) ce.Handler.log.Warnfln("Failed to reply to command from %s: %v", ce.User.MXID, err)
} }

View File

@ -1044,7 +1044,8 @@ func (portal *Portal) getBridgeInfo() (string, BridgeInfoContent) {
AvatarURL: portal.AvatarURL.CUString(), AvatarURL: portal.AvatarURL.CUString(),
}, },
} }
bridgeInfoStateKey := fmt.Sprintf("net.maunium.whatsapp://whatsapp/%s", portal.Key.JID) // bridgeInfoStateKey := fmt.Sprintf("net.maunium.whatsapp://whatsapp/%s", portal.Key.JID) ??
bridgeInfoStateKey := portal.Key.JID
return bridgeInfoStateKey, bridgeInfo return bridgeInfoStateKey, bridgeInfo
} }
@ -1337,6 +1338,10 @@ func (portal *Portal) HandleMessageRevokeSkype(user *User, message skype.Resourc
} }
_, err := intent.RedactEvent(portal.MXID, msg.MXID) _, err := intent.RedactEvent(portal.MXID, msg.MXID)
if err != nil { if err != nil {
// TODO Maybe there is a better implementation
if strings.Index(err.Error(), "M_FORBIDDEN") > -1 {
_, err = portal.MainIntent().RedactEvent(portal.MXID, msg.MXID)
}
portal.log.Errorln("Failed to redact %s: %v", msg.JID, err) portal.log.Errorln("Failed to redact %s: %v", msg.JID, err)
return return
} }
@ -2290,6 +2295,9 @@ func (portal *Portal) Cleanup(puppetsOnly bool) {
} else if !puppetsOnly { } else if !puppetsOnly {
_, err = intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: member, Reason: "Deleting portal"}) _, err = intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: member, Reason: "Deleting portal"})
if err != nil { if err != nil {
content := format.RenderMarkdown("Error leaving room(Deleting portal from skype), you can leave this room manually.", true, false)
content.MsgType = event.MsgNotice
_, _ = portal.MainIntent().SendMessageEvent(portal.MXID, event.EventMessage, content)
portal.log.Errorln("Error kicking user while cleaning up portal:", err) portal.log.Errorln("Error kicking user while cleaning up portal:", err)
} }
} }

View File

@ -372,6 +372,9 @@ func (user *User) Login(ce *CommandEvent, name string, password string) (err err
if len(user.Conn.UserProfile.LastName) > 0 { if len(user.Conn.UserProfile.LastName) > 0 {
username = username + user.Conn.UserProfile.LastName username = username + user.Conn.UserProfile.LastName
} }
if username == "" {
username = user.Conn.UserProfile.Username
}
ce.Reply("Successfully logged in as @" + username) ce.Reply("Successfully logged in as @" + username)
user.Conn.Subscribes() // subscribe basic event user.Conn.Subscribes() // subscribe basic event