diff --git a/antam/api.go b/antam/api.go index 9fc7dd4..c7c12b4 100644 --- a/antam/api.go +++ b/antam/api.go @@ -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. @@ -42,6 +43,7 @@ func getGoldPricesFromHTML() (*GoldPrice, error) { return &GoldPrice{ Buy: buyPrice, Sell: sellPrice, + Source: "Gedung Antam Jakarta", }, nil } @@ -77,5 +79,6 @@ func getPluangGoldPricesFromHTML() (*GoldPrice, error) { return &GoldPrice{ Buy: buyPrice, Sell: sellPrice, + Source: "Pluang.com", }, nil } \ No newline at end of file diff --git a/antam/scout.go b/antam/scout.go index 6ce07f8..04ae0b2 100644 --- a/antam/scout.go +++ b/antam/scout.go @@ -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 { diff --git a/antam/telegram.go b/antam/telegram.go index 78c1e8c..14551b6 100644 --- a/antam/telegram.go +++ b/antam/telegram.go @@ -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() { @@ -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}, @@ -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,