Skip to content
70 changes: 70 additions & 0 deletions news-feed-bot-thecoldblooded/0rbit-News-Feed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- ao.id n8X1Uyxx4bkvrdci5OnwT8l8ZkhU-kP-GPXO3vPNgc4

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
)
Binary file added news-feed-bot-thecoldblooded/0rbit-News-Feed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions price-feed-bot-thecoldblooded/0rbit-Price-Feed.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- PID zhDPIMGs9wQE5-ap5msNw9SgFC3i955OcDkTu1YOdAA

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("thecoldblooded",
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
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.