mirror of
https://github.com/Penguin-71630/meme-bot-frontend-dc.git
synced 2026-03-12 20:40:16 +08:00
Refactor: cleanup
- Introduce tracing - Introduce cobra / viper framework - Introduce resty client - Seperate files in api/ and bot/ - Trim unused functions
This commit is contained in:
47
bot/handleSlashWeb.go
Normal file
47
bot/handleSlashWeb.go
Normal file
@@ -0,0 +1,47 @@
|
||||
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,
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user