/
get.go
47 lines (39 loc) · 1.33 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"gorm.io/gorm/clause"
"github.com/nint8835/scribe/database"
)
type GetArgs struct {
ID int `description:"ID of the quote to display."`
}
func GetQuoteCommand(_ *discordgo.Session, interaction *discordgo.InteractionCreate, args GetArgs) {
var quote database.Quote
result := database.Instance.Model(&database.Quote{}).Preload(clause.Associations).First("e, args.ID)
if result.Error != nil {
Bot.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Error getting quote.\n```\n%s\n```", result.Error),
},
})
return
}
embed, err := MakeQuoteEmbed("e, interaction.GuildID)
if err != nil {
Bot.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Error getting quote.\n```\n%s\n```", err),
},
})
return
}
Bot.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{embed},
},
})
}