-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord.go
130 lines (110 loc) · 3.66 KB
/
discord.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"context"
"fmt"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/disgo/webhook"
"github.com/disgoorg/snowflake/v2"
"strconv"
"strings"
"time"
)
var WebhookClient webhook.Client
func CreateWebhookClient(webhookUrl string) {
webhookArray := strings.Split(webhookUrl, "/")
id, _ := strconv.ParseUint(webhookArray[len(webhookArray)-2], 10, 64)
token := webhookArray[len(webhookArray)-1]
WebhookClient = webhook.New(snowflake.ID(id), token)
}
func SendDmarketPurchase(product *DmarketProduct, marketType string, orderId string) {
var embed = discord.NewEmbedBuilder()
embed.SetTitle("Successful Purchase: " + orderId).SetURL("https://dmarket.com/ingame-items/item-list/csgo-skins")
embed.SetTimestamp(time.Now()).SetThumbnail(product.Image)
var description string
if marketType == "dmarket" {
description = "Purchased from the DMarket bot."
} else {
description = "Purchased P2P. SEND TRADE NOW."
}
embed.SetDescription(description)
buffPrice := GetBuffPrice(product.Title, product.Extra.PhaseTitle)
numPrice, _ := strconv.ParseFloat(product.Price.USD, 32)
numPrice = numPrice / 100
inline := true
embed.SetColor(5763719)
embed.SetFields(discord.EmbedField{
Name: "Price",
Value: fmt.Sprintf("$%.2f (%.2f%%)", numPrice, PercentageDifference(numPrice, buffPrice)),
Inline: &inline,
}, discord.EmbedField{
Name: "Buff Price",
Value: fmt.Sprintf("[$%.2f](%s)", buffPrice, GetBuffUrl(product.Title)),
Inline: &inline,
})
WebhookClient.CreateEmbeds([]discord.Embed{embed.Build()})
}
func SendSkinportProduct(name string, image string, inspectLink string, price float64, purchaseUrl string, buffPrice float64, marketName string) {
var embed = discord.NewEmbedBuilder()
embed.SetTitle(marketName + ": " + name).SetURL(purchaseUrl)
embed.SetTimestamp(time.Now()).SetThumbnail(image)
inline := true
embed.SetFields(discord.EmbedField{
Name: "Price",
Value: fmt.Sprintf("$%.2f (%.2f%%)", price, PercentageDifference(price, buffPrice)),
Inline: &inline,
}, discord.EmbedField{
Name: "Buff Price",
Value: fmt.Sprintf("[$%.2f](%s)", buffPrice, GetBuffUrl(name)),
Inline: &inline,
})
WebhookClient.CreateEmbeds([]discord.Embed{embed.Build()})
}
func ReportATC() {
webhookArray := strings.Split(config.Webhook, "/")
id, _ := strconv.ParseUint(webhookArray[len(webhookArray)-2], 10, 64)
token := webhookArray[len(webhookArray)-1]
atcClient := webhook.New(snowflake.ID(id), token)
atcClient.CreateMessage(discord.WebhookMessageCreate{Content: "Item ATCd: https://skinport.com/cart"})
}
func ReportError(err error) {
WebhookClient.CreateMessage(discord.WebhookMessageCreate{Content: "Error encountered: " + err.Error()})
}
func GetUserInput(message string) string {
input := ""
client, err := disgo.New(config.BotToken,
// set gateway options
bot.WithGatewayConfigOpts(
// set enabled intents
gateway.WithIntents(
gateway.IntentGuildMessages,
gateway.IntentMessageContent,
),
),
bot.WithEventListenerFunc(func(event *events.MessageCreate) {
if event.Message.Author.Bot || event.Message.ChannelID.String() != config.InputChannel {
return
}
input = event.Message.Content
}),
)
if err != nil {
panic(err)
}
// connect to the gateway
if err = client.OpenGateway(context.TODO()); err != nil {
panic(err)
}
channelId, _ := snowflake.Parse(config.InputChannel)
client.Rest().CreateMessage(channelId, discord.NewMessageCreateBuilder().SetContent(message).Build())
for true {
if input != "" {
break
}
time.Sleep(time.Second)
}
return input
}