-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
champion.go
80 lines (68 loc) · 3 KB
/
champion.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"discord-esports/models"
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
)
type ChampionEmbeds struct {
General discordgo.MessageEmbed
}
func ChampionCommand(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
options := interaction.ApplicationCommandData().Options
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
for _, opt := range options {
optionMap[opt.Name] = opt
}
if interaction.Type == discordgo.InteractionApplicationCommandAutocomplete {
if champion, ok := optionMap["champion"]; ok {
if champion.Focused {
autoCompleteChampionName(session, interaction, champion.StringValue())
}
}
return
}
championKey := optionMap["champion"].StringValue()
if champion, ok := championsEmbeds[championKey]; ok {
err := client.session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{&champion.General},
},
})
if err != nil {
client.logger.Error(fmt.Sprintf("Error responding with embed: %v", err))
}
return
}
respondWithMessage(interaction.Interaction, fmt.Sprintf("Champion '%v' not found.", championKey))
}
func createChampionEmbed(champion *models.Champion) ChampionEmbeds {
championEmbed := discordgo.MessageEmbed{
Title: champion.FullTitle,
URL: champion.OfficialPage,
Color: DISCORD_EMBED_COLOR,
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: champion.Icon,
},
Description: fmt.Sprintf("[Wiki](%s) - [LoLalytics](https://lolalytics.com/lol/%s/build/)\n\n%v", champion.WikiPage, strings.ToLower(champion.Key), champion.Lore),
Fields: []*discordgo.MessageEmbedField{
{Name: "HP | Regen", Value: fmt.Sprintf("%v\n%v", champion.Stats.Health, champion.Stats.HealthRegen), Inline: true},
{Name: "MP | Regen", Value: fmt.Sprintf("%v\n%v", champion.Stats.Mana, champion.Stats.ManaRegen), Inline: true},
{Name: "Armor | MR", Value: fmt.Sprintf("%v\n%v", champion.Stats.Armor, champion.Stats.MagicResistance), Inline: true},
{Name: "", Value: ""},
{Name: "Attack Range", Value: fmt.Sprintf("%v", champion.Stats.AttackRange), Inline: true},
{Name: "Attack Damage", Value: fmt.Sprintf("%v", champion.Stats.AttackDamage), Inline: true},
{Name: "Attack Speed", Value: fmt.Sprintf("%v", champion.Stats.AttackSpeed), Inline: true},
{Name: "", Value: ""},
{Name: "Movement", Value: fmt.Sprintf("%v", champion.Stats.MovementSpeed), Inline: true},
{Name: "Adaptive Type", Value: fmt.Sprintf("%v", champion.AdaptiveType), Inline: true},
{Name: "Resource", Value: champion.Resource, Inline: true},
{Name: "", Value: ""},
{Name: "Attack Type", Value: champion.AttackType, Inline: true},
{Name: "Patch last changed", Value: champion.PatchLastChanged, Inline: true},
},
Footer: &discordgo.MessageEmbedFooter{Text: strings.Join(champion.Roles, ", ")},
}
return ChampionEmbeds{General: championEmbed}
}