From acc5c8c8cdb5b5062e2f3d5c8d72b63b9b573cb8 Mon Sep 17 00:00:00 2001 From: Ali <101213422+AliSrr@users.noreply.github.com> Date: Wed, 22 May 2024 23:11:05 +0400 Subject: [PATCH 1/4] Create 0rbit-Price-Feed.lua --- price-feed-bot-AliSrr/0rbit-Price-Feed.lua | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 price-feed-bot-AliSrr/0rbit-Price-Feed.lua diff --git a/price-feed-bot-AliSrr/0rbit-Price-Feed.lua b/price-feed-bot-AliSrr/0rbit-Price-Feed.lua new file mode 100644 index 00000000..0b02e369 --- /dev/null +++ b/price-feed-bot-AliSrr/0rbit-Price-Feed.lua @@ -0,0 +1,57 @@ +-- PID 7yh2y0qk6Odp06l8vbczR6MOtR3Bn22T9nvh0FvM7SE + +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("AliSrr", + 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 225d9dd638625bc741fe5f185ea49d80055f0053 Mon Sep 17 00:00:00 2001 From: Ali <101213422+AliSrr@users.noreply.github.com> Date: Wed, 22 May 2024 23:11:32 +0400 Subject: [PATCH 2/4] Create 0rbit-Price-Feed.jpg --- price-feed-bot-AliSrr/0rbit-Price-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 price-feed-bot-AliSrr/0rbit-Price-Feed.jpg diff --git a/price-feed-bot-AliSrr/0rbit-Price-Feed.jpg b/price-feed-bot-AliSrr/0rbit-Price-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/price-feed-bot-AliSrr/0rbit-Price-Feed.jpg @@ -0,0 +1 @@ + From 36852927b7b8668ced43a30c443e0ee8c7db966a Mon Sep 17 00:00:00 2001 From: Ali <101213422+AliSrr@users.noreply.github.com> Date: Wed, 22 May 2024 23:22:22 +0400 Subject: [PATCH 3/4] Create 0rbit-News-Feed.lua --- news-feed-bot-AliSrr/0rbit-News-Feed.lua | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 news-feed-bot-AliSrr/0rbit-News-Feed.lua diff --git a/news-feed-bot-AliSrr/0rbit-News-Feed.lua b/news-feed-bot-AliSrr/0rbit-News-Feed.lua new file mode 100644 index 00000000..eb733c05 --- /dev/null +++ b/news-feed-bot-AliSrr/0rbit-News-Feed.lua @@ -0,0 +1,71 @@ +-- ao.id 2qjptUPD5kWBTyxUQDft609W4e0oS_fZ8BHu9eHrYBc + +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 5d80db002820424e71a81b27992c412504a40421 Mon Sep 17 00:00:00 2001 From: Ali <101213422+AliSrr@users.noreply.github.com> Date: Wed, 22 May 2024 23:23:54 +0400 Subject: [PATCH 4/4] Create 0rbit-News-Feed.jpg --- news-feed-bot-AliSrr/0rbit-News-Feed.jpg | 1 + 1 file changed, 1 insertion(+) create mode 100644 news-feed-bot-AliSrr/0rbit-News-Feed.jpg diff --git a/news-feed-bot-AliSrr/0rbit-News-Feed.jpg b/news-feed-bot-AliSrr/0rbit-News-Feed.jpg new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/news-feed-bot-AliSrr/0rbit-News-Feed.jpg @@ -0,0 +1 @@ +