commands/join: include chat name in response

This commit is contained in:
Tulir Asokan
2026-04-03 23:41:34 +03:00
parent 0bee8da0f8
commit c3216f1e4d
+22 -2
View File
@@ -22,6 +22,7 @@ import (
"slices"
"strings"
"golang.org/x/net/html"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/commands"
"maunium.net/go/mautrix/bridgev2/networkid"
@@ -141,6 +142,7 @@ func fnJoin(ce *commands.Event) {
}
t := login.Client.(*TelegramClient)
var resp tg.UpdatesClass
var chatName string
if usernameMatch := usernameLinkRe.FindStringSubmatch(ce.Args[0]); usernameMatch != nil {
resolve, err := t.client.API().ContactsResolveUsername(ce.Ctx, &tg.ContactsResolveUsernameRequest{Username: usernameMatch[1]})
if err != nil {
@@ -163,6 +165,7 @@ func fnJoin(ce *commands.Event) {
ce.Reply("Channel information not found in resolve response.")
return
}
chatName = ch.Title
resp, err = t.client.API().ChannelsJoinChannel(ce.Ctx, ch.AsInput())
if err != nil {
ce.Log.Err(err).Msg("Failed to join chat with invite link")
@@ -170,7 +173,7 @@ func fnJoin(ce *commands.Event) {
return
}
} else if inviteLinkMatch := inviteLinkRe.FindStringSubmatch(ce.Args[0]); inviteLinkMatch != nil {
_, err := t.client.API().MessagesCheckChatInvite(ce.Ctx, inviteLinkMatch[1])
resolve, err := t.client.API().MessagesCheckChatInvite(ce.Ctx, inviteLinkMatch[1])
if tgerr.Is(err, tg.ErrInviteHashInvalid) {
ce.Reply("Invalid invite link.")
return
@@ -178,6 +181,23 @@ func fnJoin(ce *commands.Event) {
ce.Reply("Invite link expired.")
return
}
switch typed := resolve.(type) {
case *tg.ChatInviteAlready:
titler, ok := typed.Chat.(interface {
GetTitle() string
})
if ok {
chatName = titler.GetTitle()
} else {
chatName = "that chat"
}
ce.Reply("You're already a member of %s", html.EscapeString(chatName))
return
case *tg.ChatInvite:
chatName = typed.Title
default:
ce.Log.Warn().Type("resolved_type", typed).Msg("Unexpected response type from MessagesCheckChatInvite")
}
resp, err = t.client.API().MessagesImportChatInvite(ce.Ctx, inviteLinkMatch[1])
if err != nil {
ce.Log.Err(err).Msg("Failed to join chat with invite link")
@@ -194,7 +214,7 @@ func fnJoin(ce *commands.Event) {
} else {
ce.Log.Debug().Msg("Finished handling updates from joining chat with invite link")
}
ce.React("\u2705\ufe0f")
ce.Reply("Successfully joined %s", html.EscapeString(chatName))
}
var cmdEmojiPack = &commands.FullHandler{