diff --git a/commands.go b/commands.go index 7fbf9b1..e070e05 100644 --- a/commands.go +++ b/commands.go @@ -288,30 +288,20 @@ func (handler *CommandHandler) CommandJoin(ce *CommandEvent) { func (handler *CommandHandler) CommandAccept(ce *CommandEvent) { if ce.Portal == nil || len(ce.ReplyTo) == 0 { ce.Reply("You must reply to a group invite message when using this command.") - return - } - evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo) - if err != nil { + } else if evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo); err != nil { handler.log.Errorln("Failed to get event %s to handle !wa accept command: %v", ce.ReplyTo, err) ce.Reply("Failed to get reply event") - return - } - meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{}) - if !ok { + } else if meta, ok := evt.Content.Raw[inviteMetaField].(map[string]interface{}); !ok { ce.Reply("That doesn't look like a group invite message.") - return - } - jid, inviter, code, expiration, ok := parseInviteMeta(meta) - if !ok { + } else if jid, inviter, code, expiration, ok := parseInviteMeta(meta); !ok { ce.Reply("That doesn't look like a group invite message.") - return - } - err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration) - if err != nil { + } else if inviter.User == ce.User.JID.User { + ce.Reply("You can't accept your own invites") + } else if err = ce.User.Client.AcceptGroupInvite(jid, inviter, code, expiration); err != nil { ce.Reply("Failed to accept group invite: %v", err) - return + } else { + ce.Reply("Successfully accepted the invite, the portal should be created momentarily") } - ce.Reply("Successfully accepted the invite, the portal should be created momentarily") } const cmdCreateHelp = `create - Create a group chat.` diff --git a/portal.go b/portal.go index 7e6bf51..ed3265b 100644 --- a/portal.go +++ b/portal.go @@ -1563,15 +1563,12 @@ func (portal *Portal) convertLocationMessage(intent *appservice.IntentAPI, msg * return &ConvertedMessage{Intent: intent, Type: event.EventMessage, Content: content} } -const inviteMsg = `%s has invited you to join %s: -
%s-The invite expires at %s. Reply to this message with
!wa accept
to accept the invite.`
+const inviteMsg = `%s!wa accept
to accept the invite.`
const inviteMetaField = "fi.mau.whatsapp.invite"
func (portal *Portal) convertGroupInviteMessage(intent *appservice.IntentAPI, info *types.MessageInfo, msg *waProto.GroupInviteMessage) *ConvertedMessage {
- puppet := portal.bridge.GetPuppetByJID(info.Sender)
expiry := time.Unix(msg.GetInviteExpiration(), 0)
- htmlMessage := fmt.Sprintf(inviteMsg, intent.UserID, html.EscapeString(puppet.Displayname), msg.GetGroupName(), html.EscapeString(msg.GetCaption()), expiry)
+ htmlMessage := fmt.Sprintf(inviteMsg, html.EscapeString(msg.GetCaption()), msg.GetGroupName(), expiry)
content := &event.MessageEventContent{
MsgType: event.MsgText,
Body: format.HTMLToText(htmlMessage),