Skip to content

Commit

Permalink
Merge pull request #24 from fabriguespe/updates_v4
Browse files Browse the repository at this point in the history
Updates v4
  • Loading branch information
humanagent authored Jun 9, 2024
2 parents 7d3d2d2 + 4946fcc commit 5893454
Show file tree
Hide file tree
Showing 46 changed files with 3,341 additions and 768 deletions.
61 changes: 35 additions & 26 deletions examples/group/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const commands = [
{
name: "DegenBot",
name: "Tipping",
icon: "🎩",
description: "Send degen tipping via emoji, replies or command.",
description: "Tip tokens via emoji, replies or command.",
commands: [
{
command: "/tip [@users] [amount] [token]",
description: "Tip users in degen.",
description: "Tip users in a specified token.",
params: {
username: {
default: "",
Expand All @@ -16,19 +16,14 @@ export const commands = [
default: 10,
type: "number",
},
token: {
default: "degen",
type: "string",
values: ["degen"], // Accepted tokens
},
},
},
],
},
{
name: "BaseFrame",
name: "Base Transactions",
icon: "🖼️",
description: "Multipurpose transaction frame.",
description: "Multipurpose transaction frame built onbase.",
commands: [
{
command: "/send [amount] [token] [@username]",
Expand Down Expand Up @@ -74,11 +69,11 @@ export const commands = [
command: "/mint [collection_address] [token_id]",
description: "Create (mint) a new token or NFT.",
params: {
collection_address: {
default: "0x1234567890",
type: "string",
collection: {
default: "0x73a333cb82862d4f66f0154229755b184fb4f5b0",
type: "address",
},
token_id: {
tokenId: {
default: 1,
type: "number",
},
Expand All @@ -92,8 +87,8 @@ export const commands = [
],
},
{
name: "BaseBet",
icon: "🤖",
name: "Betting",
icon: "🎰",
description: "Betting on basebet.",
commands: [
{
Expand All @@ -117,7 +112,7 @@ export const commands = [
],
},
{
name: "GamesBot",
name: "Games",
icon: "🕹️",
description: "Provides various gaming experiences.",
commands: [
Expand All @@ -135,16 +130,30 @@ export const commands = [
],
},
{
name: "GeneralCommands",
icon: "⚙️",
description:
"General utility commands for user management and information.",
name: "Admin",
icon: "🔐",
description: "Moderate access to the group with admin commands.",
commands: [
{ command: "/tx", description: "Transaction primitive deeplink." },
{ command: "/dm", description: "Dm primitive." },
{ command: "/block", description: "Block a user." },
{ command: "/unblock", description: "Unblock a user." },
{ command: "/help", description: "Show available commands." },
{
command: "/block",
description: "Block a user.",
params: {
username: {
default: "",
type: "username",
},
},
},
{
command: "/unblock",
description: "Unblock a user.",
params: {
username: {
default: "",
type: "username",
},
},
},
],
},
];
21 changes: 21 additions & 0 deletions examples/group/src/handler/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { HandlerContext } from "@xmtp/botkit";

export async function handler(context: HandlerContext) {
const { content } = context.message;
const { content: text, command, params } = content;
switch (command) {
case "block":
// context.addMember(params.username);
context.reply("❌ you are not an admin");
break;
case "unblock":
// context.removeMember(params.username);
context.reply("❌ you are not an admin");
break;
default:
// Inform the user about unrecognized commands and provide available options
context.reply(
"Command not recognized. Available commands: block, unblock.",
);
}
}
3 changes: 0 additions & 3 deletions examples/group/src/handler/bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async function generateBetUrl(
await conv.send(
`https://base-frame-lyart.vercel.app/transaction?transaction_type=send&amount=1&token=eth&receiver=0xA45020BdA714c3F43fECDC6e38F873fFF2Dec8ec`,
);
await conv.send(
`Or use a deeplink. Place your bet tx:0xf0490b45884803924Ca84C2051ef435991D7350D`,
);
const link = `${baseUrl}${client.address}`;
return link;
}
33 changes: 20 additions & 13 deletions examples/group/src/handler/frame.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { HandlerContext } from "@xmtp/botkit";
import { users } from "../lib/users.js";

const baseUrl = "https://base-frame-lyart.vercel.app/transaction";

// Main handler function for processing commands
export function handler(context: HandlerContext) {
const { content } = context.message;
const { params, command } = content;
let url = "";

switch (command) {
case "send":
const { amount: amountSend, token: tokenSend, username } = params;
// Destructure and validate parameters for the send command
const { amount: amountSend, token: tokenSend, username } = params; // [!code hl] // [!code focus]

if (!amountSend || !tokenSend || !username) {
context.reply(
"Missing required parameters. Please provide amount, token, and username.",
);
return;
}
// Generate URL for the send transaction
url = generateFrameURL(baseUrl, "send", {
amount: amountSend,
token: tokenSend,
Expand All @@ -25,13 +27,16 @@ export function handler(context: HandlerContext) {
context.reply(`${url}`);
break;
case "swap":
const { amount, token_from, token_to } = params;
// Destructure and validate parameters for the swap command
const { amount, token_from, token_to } = params; // [!code hl] // [!code focus]

if (!amount || !token_from || !token_to) {
context.reply(
"Missing required parameters. Please provide amount, token_from, and token_to.",
);
return;
}
// Generate URL for the swap transaction
url = generateFrameURL(baseUrl, "swap", {
amount,
token_from,
Expand All @@ -40,31 +45,33 @@ export function handler(context: HandlerContext) {
context.reply(`${url}`);
break;
case "mint":
const { address: collectionAddress, numeric: tokenId } = params;
let collection =
collectionAddress || "0x73a333cb82862d4f66f0154229755b184fb4f5b0";
let token = tokenId || 1;
if (!collection || !token) {
// Destructure and provide default values for the mint command
const { collection, tokenId } = params; // [!code hl] // [!code focus]

if (!collection || !tokenId) {
context.reply(
"Missing required parameters. Please provide collection address and token id.",
);
return;
}
// Generate URL for the mint transaction
url = generateFrameURL(baseUrl, "mint", {
collection:
collectionAddress || "0x73a333cb82862d4f66f0154229755b184fb4f5b0",
token_id: tokenId || 1, // Default token ID if not specified
collection,
token_id: tokenId,
});
context.reply(url);
break;
case "show":
case "show": // [!code hl] // [!code focus]
// Show the base URL without the transaction path
context.reply(`${baseUrl.replace("/transaction", "")}`);
break;
default:
// Handle unknown commands
context.reply("Unknown command. Use help to see all available commands.");
}
}

// Function to generate a URL with query parameters for transactions
function generateFrameURL(
baseUrl: string,
transaction_type: string,
Expand Down
30 changes: 30 additions & 0 deletions examples/group/src/handler/game.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HandlerContext } from "@xmtp/botkit";

// Handler function to process game-related commands
export async function handler(context: HandlerContext) {
const { content } = context.message;
const { params } = content;
// URLs for each game type
const gameUrls: { [key: string]: string } = {
wordle: "https://openframedl.vercel.app/",
slot: "https://slot-machine-frame.vercel.app/",
guess: "https://farguessr.vercel.app/",
};

// Respond with the appropriate game URL or an error message
switch (params.type) {
case "wordle":
case "slot":
case "guess":
// Retrieve the URL for the requested game using a simplified variable assignment
const gameUrl = gameUrls[params.type];
// Send the URL for the requested game
context.reply(gameUrl);
break;
default:
// Inform the user about unrecognized commands and provide available options
context.reply(
"Command not recognized. Available games: wordle, slot, guess, or help.",
);
}
}
23 changes: 0 additions & 23 deletions examples/group/src/handler/games.ts

This file was deleted.

28 changes: 0 additions & 28 deletions examples/group/src/handler/general.ts

This file was deleted.

4 changes: 2 additions & 2 deletions examples/group/src/handler/gpt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HandlerContext } from "@xmtp/botkit";
import { users } from "../lib/users.js";
import openaiCall from "../lib/gpt.js";

export async function handler(context: HandlerContext, commands: any) {
export async function handler(context: HandlerContext) {
const { users, commands } = context.context;
const { content, senderAddress } = context.message;
const { content: text } = content;
const systemPrompt = `You are a helpful assistant that lives inside a web3 messaging group.\n
Expand Down
28 changes: 28 additions & 0 deletions examples/group/src/handler/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { HandlerContext } from "@xmtp/botkit";
import { commands } from "../commands.js"; // Assuming commands.ts is in the same directory

export async function handler(context: HandlerContext) {
const { content } = context.message;
const { content: command } = content;
switch (command.trim().replace("/", "")) {
case "tx":
context.reply("Send 1 ETH tx:0xf0490b45884803924Ca84C2051ef435991D7350D");
break;
case "dm":
context.reply("dm:/0x1CB3649469546D10b7fa4fd1d1c63e8aA3a0E667");
break;
case "help":
const intro =
"Available experiences:\n" +
commands
.flatMap((bot: any) => bot.commands)
.map((command: any) => `${command.command} - ${command.description}`)
.join("\n") +
"\nUse these commands to interact with specific bots.";
context.reply(intro);
break;
default:
context.reply("Command not found. Use /help to see available commands.");
break;
}
}
Loading

0 comments on commit 5893454

Please sign in to comment.