/
listBoxesCommand.go
94 lines (81 loc) · 2.26 KB
/
listBoxesCommand.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cmd
import (
"../framework"
"../config"
"../htb"
"encoding/json"
"io/ioutil"
"github.com/bwmarrin/discordgo"
"fmt"
"strconv"
"strings"
)
func ListBoxesCommand(ctx framework.Context) {
/*
Send info about the last HTB box
TODO :
- Add flag remaining for user
- Add flag to display only one difficulty
*/
// Read json data from file
plan, err := ioutil.ReadFile("boxes.json")
if err != nil {
fmt.Println(err.Error())
}
var boxes []config.Box
err = json.Unmarshal(plan, &boxes)
if err != nil {
fmt.Println(err.Error())
}
var lineEasy, lineMedium, lineHard, lineInsane string
var numEasy, numMedium, numHard, numInsane int
for _, box := range boxes{
if !box.Retired{
info := htb.GetBoxInfo(box)
var line, customEmoji string
for _, c := range ctx.Guild.Emojis{
if c.Name == strings.ToLower(box.Os){
customEmoji = c.MessageFormat()
}
}
line = customEmoji +" • **"+box.Name+"** (⭐ "+box.Rating+") (🛡️ "+info["difficultyRating"]+"/10)\n"
switch box.Points{
case 20:
numEasy += 1
lineEasy += strconv.Itoa(numEasy)+"."+line
case 30:
numMedium += 1
lineMedium += strconv.Itoa(numMedium)+"."+line
case 40:
numHard += 1
lineHard += strconv.Itoa(numHard)+"."+line
case 50:
numInsane += 1
lineInsane += strconv.Itoa(numInsane)+"."+line
}
}
}
embed := &discordgo.MessageEmbed{
Color: 0x69c0ce,
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "Easy",
Value: lineEasy,
},
&discordgo.MessageEmbedField{
Name: "Medium",
Value: lineMedium,
},
&discordgo.MessageEmbedField{
Name: "Hard",
Value: lineHard,
},
&discordgo.MessageEmbedField{
Name: "Insane",
Value: lineInsane,
},
},
Title: "Active boxes 💻",
}
ctx.ReplyEmbed( embed )
}