Skip to content

Commit

Permalink
reality agent templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushKun committed Jul 25, 2024
1 parent 5d9ff85 commit a1703d0
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 128 deletions.
12 changes: 7 additions & 5 deletions next_app/src/templates/ao/fantasy-llama.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const source = `-- Name: FantasyLlama
CHAT_TARGET = CHAT_TARGET or 'TODO: Put your verse ID here'
CHAT_TARGET = CHAT_TARGET or 'TODO: Put your world ID here'
-- To add this agent to your verse, configure your Static Entities table, e.g.:
-- VerseEntitiesStatic = {
-- To add this agent to your world, configure your Static Entities table, e.g.:
-- RealityEntitiesStatic = {
-- ['<your agent process Id>'] = {
-- Position = { 10, 10 },
-- Type = 'Avatar',
Expand All @@ -18,15 +18,17 @@ CHAT_TARGET = CHAT_TARGET or 'TODO: Put your verse ID here'
-- }
TIMESTAMP_LAST_MESSAGE_MS = TIMESTAMP_LAST_MESSAGE_MS or 0
COOLDOWN_MS = 5000
-- Limit sending a message to every so often
COOLDOWN_MS = 10000 -- 10 seconds
Handlers.add(
'DefaultInteraction',
Handlers.utils.hasMatchingTag('Action', 'DefaultInteraction'),
function(msg)
print('DefaultInteraction')
if ((msg.Timestamp - TIMESTAMP_LAST_MESSAGE_MS) < COOLDOWN_MS) then
return
return print("Message on cooldown")
end
Send({
Expand Down
146 changes: 146 additions & 0 deletions next_app/src/templates/ao/llama-complainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
export const source = `-- Name: LlamaComplainer
-- ProcessId: vwoIQclBFD7G9l1SKU8Cv3Sdoxa0Ku3F4Zd1c4IrU3g
local json = require("json")
TARGET_WORLD_PID = TARGET_WORLD_PID or "TODO: Put my Target World PID here"
TICK_COUNT = TICK_COUNT or 0
LAST_MESSAGE_ID = LAST_MESSAGE_ID or 0
Initialized = Initialized or nil
function Register()
print("Registering as Reality Entity")
Send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "Reality.EntityCreate",
},
Data = json.encode({
Type = "Avatar",
Metadata = {
DisplayName = "Llama Complainer",
SkinNumber = 8,
},
}),
})
end
if (not Initialized) then
Register()
-- Query the number of chat messages so far
Send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "ChatCount",
},
})
end
Handlers.add(
"ChatCountResponse",
Handlers.utils.hasMatchingTag("Action", "ChatCountResponse"),
function(msg)
print("ChatCountResponse")
local count = tonumber(msg.Data)
print("Chat Count: " .. (count or "nil"))
-- Set \`LAST_MESSAGE_ID\` to the count of messages
if (count) then
LAST_MESSAGE_ID = count
end
Initialized = true;
end
)
Handlers.add(
"CronTick", -- handler name
Handlers.utils.hasMatchingTag("Action", "Cron"), -- handler pattern to identify cron message
function() -- handler task to execute on cron message
print("CronTick")
if (not Initialized) then
return print("Not initialized")
end
TICK_COUNT = TICK_COUNT + 1
Send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "ChatHistory",
["Id-After"] = tostring(LAST_MESSAGE_ID),
Limit = tostring(100),
},
})
end
)
Handlers.add(
"ChatHistoryResponseHandler",
Handlers.utils.hasMatchingTag("Action", "ChatHistoryResponse"),
function(msg)
if (msg.From ~= TARGET_WORLD_PID) then
return print("ChatHistoryResponse not from LlamaLand")
end
local chatMessages = json.decode(msg.Data)
-- If empty, return
if (not chatMessages or #chatMessages == 0) then
return print("No new chat messages")
end
-- Update the last message id to the latest message,
-- so we don't get the same messages again
LAST_MESSAGE_ID = chatMessages[1].Id
if (#chatMessages < 3) then
return print("Not enough chat messages")
end
print("Got " .. #chatMessages .. " new chat messages")
-- Each chat message is structured as follows:
-- {
-- Id = "Sequence of chat message"
-- MessageId = "Id of the Message",
-- Timestamp = "Timestamp the message was sent",
-- AuthorId = "Address of the chat message's author",
-- AuthorName = "Display name of that author",
-- Recipient = "If it was intended for a specific recipient, their address",
-- Content = "Content of the chat message",
-- }
-- Note: Chat messages are always ordered from newest to oldest
for i, chatM in ipairs(chatMessages) do
-- We could do something interesting here,
-- but let's just print some info in the console
print("Message from " .. (chatM.AuthorName or chatM.AuthorId) .. ": " .. chatM.Content)
end
-- Complain about the state of affairs
Send({
Target = TARGET_WORLD_PID,
Tags = {
Action = 'ChatMessage',
['Author-Name'] = 'Llama Complainer',
},
Data = 'Goodness, Llamas are so noisy these days.'
})
-- Move to random position in the center
Send({
Target = TARGET_WORLD_PID,
Tags = {
Action = "Reality.EntityUpdatePosition",
},
Data = json.encode({
-- You'll probably want to adjust these values to fit with your world
Position = {
math.random(-4, 4),
math.random(-3, 3),
},
}),
})
end
)`
119 changes: 0 additions & 119 deletions next_app/src/templates/ao/weaveworld-agent.ts

This file was deleted.

8 changes: 4 additions & 4 deletions next_app/src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { source as aoBot } from "@/templates/ao/ao-bot";
import { source as arInGrid } from "@/templates/ao/ar-in-arena";
import { source as memeFrame } from "@/templates/ao/memeframe";
import { source as LlamaWanderer } from "@/templates/ao/weaveworld-agent";
import { source as LlamaComplainer } from "@/templates/ao/llama-complainer";
import { source as FantasyLlama } from "@/templates/ao/fantasy-llama";

export const AOTemplates = {
"": 'print("Hello AO!")',
"WeaveWorld Agent": LlamaWanderer,
"Fantasy Llama": FantasyLlama,
"ArweaveIndia Deathmatch Arena": arInGrid,
"Reality Agent - Chatter": FantasyLlama,
"Reality Agent - Complainer": LlamaComplainer,
"Deathmatch Arena": arInGrid,
"Deathmatch Bot": aoBot,
"MemeFrame": memeFrame
}
Expand Down

0 comments on commit a1703d0

Please sign in to comment.