This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
/
price.go
executable file
·79 lines (68 loc) · 1.92 KB
/
price.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
package command
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/notmeta/osrs.cx/util"
"strings"
"time"
)
func (m *Mux) Price(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
query := strings.Join(ctx.Fields[1:], " ")
msg, _ := ds.ChannelMessageSendEmbed(dm.ChannelID, &discordgo.MessageEmbed{
Timestamp: time.Now().Format(time.RFC3339),
Footer: &discordgo.MessageEmbedFooter{
Text: "osrs.cx",
},
Description: fmt.Sprintf("Finding prices for `%s`...", query),
Color: 0xFFFF00,
})
itemId := util.FindBestMatchItemId(query)
if itemId == nil {
noItemFoundResponse := &discordgo.MessageEmbed{
Timestamp: time.Now().Format(time.RFC3339),
Footer: &discordgo.MessageEmbedFooter{
Text: "osrs.cx",
},
Description: fmt.Sprintf("Couldn't find prices for `%s`!", query),
Color: 0xFF0000,
}
_, _ = ds.ChannelMessageEditEmbed(dm.ChannelID, msg.ID, noItemFoundResponse)
return
}
item := util.RunescapeItemForId(*itemId).Item
itemPrice := util.GetOSBPrice(*itemId)
resp := &discordgo.MessageEmbed{
Timestamp: time.Now().Format(time.RFC3339),
Author: &discordgo.MessageEmbedAuthor{
Name: item.Name,
IconURL: item.Icon,
},
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: item.IconLarge,
},
Description: "_" + item.Description + "_",
Color: 0x00FF00,
Footer: &discordgo.MessageEmbedFooter{
Text: "osrs.cx | RuneLite/OSBuddy API",
},
Fields: []*discordgo.MessageEmbedField{
{
Name: "Buy Price",
Value: util.RenderInteger("#,###.", itemPrice.BuyAverage) + " gp",
Inline: true,
},
{
Name: "Overall Price",
Value: util.RenderInteger("#,###.", itemPrice.OverallAverage) + " gp",
Inline: true,
},
{
Name: "Sell Price",
Value: util.RenderInteger("#,###.", itemPrice.SellAverage) + " gp",
Inline: false,
},
},
}
_, _ = ds.ChannelMessageEditEmbed(dm.ChannelID, msg.ID, resp)
return
}