From 5297d2134dcfe3966b9d61e54f45bb9f3a016be9 Mon Sep 17 00:00:00 2001 From: 0xKullanici <101899265+0xKullanici@users.noreply.github.com> Date: Tue, 21 May 2024 15:07:43 +0300 Subject: [PATCH 1/5] Create Orbit-Price-Feed.Lua --- .../Orbit-Price-Feed.Lua | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua diff --git a/price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua b/price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua new file mode 100644 index 00000000..c4a887f4 --- /dev/null +++ b/price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua @@ -0,0 +1,57 @@ +-- PID maPaIGMfQccsdk0eFNSBIDyg73BWp5Lc5ECL1htNCuI + +local json = require("json") + +_ORBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s" + +function handleError(msg, errorMessage) + ao.send({ + Target = msg.From, + Tags = { + Action = "Error", + ["Message-Id"] = msg.Id, + Error = errorMessage + } + }) +end + +Handlers.add("https://github.com/0xKullanici", + Handlers.utils.hasMatchingTag("Action", "Sponsored-Get-Request"), + function(msg) + local token = msg.Tags.Token + if not token then + handleError(msg, "Token not provided") + return + end + + local url = "https://api.coingecko.com/api/v3/simple/price?ids=" .. token .. "&vs_currencies=usd" + ao.send({ + Target = _ORBIT, + Action = "Get-Real-Data", + Url = url + }) + print("Pricefetch request sent for " .. token) + end +) + +Handlers.add("ReceiveData", + Handlers.utils.hasMatchingTag("Action", "Receive-Response"), + function(msg) + print("Received data: " .. msg.Data) + local res = json.decode(msg.Data) + local token = msg.Tags.Token + if res[token] and res[token].usd then + ao.send({ + Target = msg.From, + Tags = { + Action = "Price-Response", + ["Message-Id"] = msg.Id, + Price = res[token].usd + } + }) + print("Price of " .. token .. " is " .. res[token].usd) + else + handleError(msg, "Failed to fetch price") + end + end +) From 585efb049ac932b2dd9a674f8f378033092eebb5 Mon Sep 17 00:00:00 2001 From: 0xKullanici <101899265+0xKullanici@users.noreply.github.com> Date: Tue, 21 May 2024 15:23:47 +0300 Subject: [PATCH 2/5] Create 0rbit-Price-Feed.jpg --- price-feed-bot-0xKullanici/0rbit-Price-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 price-feed-bot-0xKullanici/0rbit-Price-Feed.jpg diff --git a/price-feed-bot-0xKullanici/0rbit-Price-Feed.jpg b/price-feed-bot-0xKullanici/0rbit-Price-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/price-feed-bot-0xKullanici/0rbit-Price-Feed.jpg @@ -0,0 +1 @@ + From bf128192e75007fcd9207cb473346f2b408e5a60 Mon Sep 17 00:00:00 2001 From: 0xKullanici <101899265+0xKullanici@users.noreply.github.com> Date: Tue, 21 May 2024 15:24:55 +0300 Subject: [PATCH 3/5] Rename Orbit-Price-Feed.Lua to Orbit-Price-Feed.lua --- .../{Orbit-Price-Feed.Lua => Orbit-Price-Feed.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename price-feed-bot-0xKullanici/{Orbit-Price-Feed.Lua => Orbit-Price-Feed.lua} (100%) diff --git a/price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua b/price-feed-bot-0xKullanici/Orbit-Price-Feed.lua similarity index 100% rename from price-feed-bot-0xKullanici/Orbit-Price-Feed.Lua rename to price-feed-bot-0xKullanici/Orbit-Price-Feed.lua From bb84e7e328cd25f30e6f9fafbef19dc426fb2512 Mon Sep 17 00:00:00 2001 From: 0xKullanici <101899265+0xKullanici@users.noreply.github.com> Date: Tue, 21 May 2024 15:26:59 +0300 Subject: [PATCH 4/5] Create Orbit-News-Feed-Bot.lua --- .../Orbit-News-Feed-Bot.lua | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 news-feed-bot-0xKullanici/Orbit-News-Feed-Bot.lua diff --git a/news-feed-bot-0xKullanici/Orbit-News-Feed-Bot.lua b/news-feed-bot-0xKullanici/Orbit-News-Feed-Bot.lua new file mode 100644 index 00000000..57bed51d --- /dev/null +++ b/news-feed-bot-0xKullanici/Orbit-News-Feed-Bot.lua @@ -0,0 +1,71 @@ +-- ao.id u2eMqGKU1aQojw6W3gQECYzUtdAxVUaVVKcfnpX0Fmg + +local json = require("json") +local _0RBIT = "WSXUI2JjYUldJ7CKq9wE1MGwXs-ldzlUlHOQszwQe0s" +local URL = "https://api.theblockbeats.news/v1/open-api/open-flash?size=5&page=1&type=push" +ReceivedData = ReceivedData or {} + +Handlers.add( + "Get-Request", + Handlers.utils.hasMatchingTag("Action", "Sponsored-Get-Request"), + function(msg) + Send({ + Target = _0RBIT, + Action = "Get-Real-Data", + Url = URL + }) + print("GET Request sent to the 0rbit process.") + end +) + +Handlers.add( + "Receive-Data", + Handlers.utils.hasMatchingTag("Action", "Receive-Response"), + function(msg) + if not msg.Data then + print("No data received.") + return + end + + local res = json.decode(msg.Data) + + ReceivedData1 = res.data.data + local extractedData = {} + for k, v in ipairs(ReceivedData1) do + table.insert(extractedData, { + title = v.title, + description = v.content + }) + ReceivedData = extractedData + + end + print("Processed data: " .. json.encode(ReceivedData1)) + end +) + +local function getLatestData(msg) + local data = json.encode(ReceivedData) + Handlers.utils.reply(data)(msg) + print("Latest data sent: " .. data) +end + +Handlers.add( + "GetLatestData", + Handlers.utils.hasMatchingTag("Action", "Get-Latest-Data"), + getLatestData +) + +local function fetchNewsPeriodically() + Send({ + Target = _0RBIT, + Action = "Get-Real-Data", + Url = URL + }) + print("Periodic GET Request sent to the 0rbit process.") +end + +Handlers.add( + "CronTick", + Handlers.utils.hasMatchingTag("Action", "Cron"), + fetchNewsPeriodically +) From 7bf85103ea93a618e9706fb90fab50d4ab3b688c Mon Sep 17 00:00:00 2001 From: 0xKullanici <101899265+0xKullanici@users.noreply.github.com> Date: Tue, 21 May 2024 15:29:14 +0300 Subject: [PATCH 5/5] Create Orbit-News-Feed.jpg --- news-feed-bot-0xKullanici/Orbit-News-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 news-feed-bot-0xKullanici/Orbit-News-Feed.jpg diff --git a/news-feed-bot-0xKullanici/Orbit-News-Feed.jpg b/news-feed-bot-0xKullanici/Orbit-News-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/news-feed-bot-0xKullanici/Orbit-News-Feed.jpg @@ -0,0 +1 @@ +