mirror of
https://github.com/Penguin-71630/meme-bot-frontend-dc.git
synced 2026-03-12 12:30:15 +08:00
- Introduce tracing - Introduce cobra / viper framework - Introduce resty client - Seperate files in api/ and bot/ - Trim unused functions
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package bot
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Penguin-71630/meme-bot-frontend-dc/tracing"
|
|
"github.com/bwmarrin/discordgo"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (b *Bot) handleSlashWeb(
|
|
s *discordgo.Session,
|
|
i *discordgo.InteractionCreate,
|
|
) {
|
|
var userID string
|
|
if i.Member != nil {
|
|
userID = i.Member.User.ID
|
|
} else if i.User != nil {
|
|
userID = i.User.ID
|
|
}
|
|
|
|
// Call backend API
|
|
loginURL, err := b.apiClient.PostGenLoginURL(userID)
|
|
if err != nil {
|
|
tracing.Logger.Ctx(context.Background()).
|
|
Error("failed to generate login url",
|
|
zap.Error(err))
|
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: "❌ Failed to generate login URL",
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
|
|
content := "🔗 **Click here to access the web page:**\n"+
|
|
loginURL + "\n\n"
|
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: content,
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
}
|