Skip to content

Commit

Permalink
send pluang and antam jakarta price to the channel
Browse files Browse the repository at this point in the history
  • Loading branch information
100nandoo committed Nov 15, 2024
1 parent cf77c46 commit f72072f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions antam/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type GoldPrice struct {
Buy string
Sell string
Source string
}

// Get gold prices from the website. It returns a GoldPrice struct.
Expand Down Expand Up @@ -42,6 +43,7 @@ func getGoldPricesFromHTML() (*GoldPrice, error) {
return &GoldPrice{
Buy: buyPrice,
Sell: sellPrice,
Source: "Gedung Antam Jakarta",
}, nil
}

Expand Down Expand Up @@ -77,5 +79,6 @@ func getPluangGoldPricesFromHTML() (*GoldPrice, error) {
return &GoldPrice{
Buy: buyPrice,
Sell: sellPrice,
Source: "Pluang.com",
}, nil
}
9 changes: 8 additions & 1 deletion antam/scout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ func Scouting(now bool) {
pkg.LogWithTimestamp(fmt.Sprintf("Error fetching gold prices at %s: %v", timeStr, err))
return
}
SendPrice(*price)
pricePluang, errPluang := getPluangGoldPricesFromHTML()
if errPluang != nil {
pkg.LogWithTimestamp(fmt.Sprintf("Error fetching Pluang gold prices at %s: %v", timeStr, err))
return
}
goldPrices := []GoldPrice{*price, *pricePluang}

SendPrice(goldPrices...)
}

if immediate {
Expand Down
11 changes: 8 additions & 3 deletions antam/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Emas Antam Bot dibuat dengan ❤️ oleh @crossix`

// Helper function to format the gold price response message
func formatGoldPriceResponse(price GoldPrice) string {
return fmt.Sprintf("`Harga Emas:\n\nBeli: %s\nJual: %s`", price.Buy, price.Sell)
return fmt.Sprintf("`%s\nBeli: %s\nJual: %s`", price.Source, price.Buy, price.Sell)
}

func Run() {
Expand Down Expand Up @@ -87,7 +87,7 @@ SendPrice
Send antam gold price to config.ChannelAntam channel
*/
func SendPrice(price GoldPrice) {
func SendPrice(prices ...GoldPrice) {
pref := tele.Settings{
Token: os.Getenv(config.AntamTelegramBot),
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
Expand All @@ -105,7 +105,12 @@ func SendPrice(price GoldPrice) {
return
}

responseMessage := formatGoldPriceResponse(price)

var responseMessage string

for _, price := range prices {
responseMessage += formatGoldPriceResponse(price) + "\n\n"
}

_, sendErr := b.Send(tele.ChatID(num), responseMessage, &telebot.SendOptions{
ParseMode: telebot.ModeMarkdown,
Expand Down

0 comments on commit f72072f

Please sign in to comment.