Skip to content

Commit 4ad11c4

Browse files
committed
remove people, fix wallet issues
2 parents 62e7417 + c04310f commit 4ad11c4

File tree

10 files changed

+177
-87
lines changed

10 files changed

+177
-87
lines changed

.env.example

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ LARGE_HEURIST_LANGUAGE_MODEL=
8585
HEURIST_IMAGE_MODEL=
8686

8787
# EVM
88-
EVM_PRIVATE_KEY=EXAMPLE_WALLET_PRIVATE_KEY
89-
EVM_PUBLIC_KEY=EXAMPLE_WALLET_PUBLIC_KEY
88+
EVM_PRIVATE_KEY=
89+
EVM_PUBLIC_KEY=
9090

9191
# Solana
92-
SOLANA_PRIVATE_KEY=EXAMPLE_WALLET_PRIVATE_KEY
93-
SOLANA_PUBLIC_KEY=EXAMPLE_WALLET_PUBLIC_KEY
92+
SOLANA_PRIVATE_KEY=
93+
SOLANA_PUBLIC_KEY=
9494

9595
# Fallback Wallet Configuration (deprecated)
96-
WALLET_PRIVATE_KEY=EXAMPLE_WALLET_PRIVATE_KEY
97-
WALLET_PUBLIC_KEY=EXAMPLE_WALLET_PUBLIC_KEY
96+
WALLET_PRIVATE_KEY=
97+
WALLET_PUBLIC_KEY=
9898

9999
BIRDEYE_API_KEY=
100100

agent/src/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ export function parseArguments(): {
5555
character?: string;
5656
characters?: string;
5757
} {
58+
console.log("parsing arguments")
59+
console.log("process.argv", process.argv)
5860
try {
59-
return yargs(process.argv.slice(2))
61+
return yargs(process.argv.slice(3))
6062
.option("character", {
6163
type: "string",
6264
description: "Path to the character JSON file",
@@ -88,8 +90,10 @@ export async function loadCharacters(
8890
?.split(",")
8991
.map((filePath) => filePath.trim());
9092
const loadedCharacters = [];
93+
console.log("****characterPaths", characterPaths)
9194

9295
if (characterPaths?.length > 0) {
96+
console.log("has characters")
9397
for (const characterPath of characterPaths) {
9498
let content = null;
9599
let resolvedPath = "";
@@ -115,6 +119,7 @@ export async function loadCharacters(
115119
content = tryLoadFile(tryPath);
116120
if (content !== null) {
117121
resolvedPath = tryPath;
122+
console.log("resolvedPath", resolvedPath)
118123
break;
119124
}
120125
}
@@ -131,6 +136,7 @@ export async function loadCharacters(
131136
try {
132137
const character = JSON.parse(content);
133138
validateCharacterConfig(character);
139+
console.log("character is", character)
134140

135141
// Handle plugins
136142
if (character.plugins) {
@@ -371,7 +377,8 @@ async function startAgent(character: Character, directClient) {
371377
fs.mkdirSync(dataDir, { recursive: true });
372378
}
373379

374-
db = initializeDatabase(dataDir);
380+
db = initializeDatabase(dataDir) as IDatabaseAdapter &
381+
IDatabaseCacheAdapter;
375382

376383
await db.init();
377384

@@ -403,6 +410,7 @@ const startAgents = async () => {
403410
const args = parseArguments();
404411

405412
let charactersArg = args.characters || args.character;
413+
console.log("charactersArg is", charactersArg)
406414

407415
let characters = [defaultCharacter];
408416

characters/eternalai.character.json

-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@
210210
"vaguely offensive but also hilarious",
211211
"schizo-autist"
212212
],
213-
"people": [],
214213
"topics": [
215214
"metaphysics",
216215
"quantum physics",

characters/tate.character.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"model": "en_US-male-medium"
99
}
1010
},
11-
"people": [],
1211
"plugins": [],
1312
"bio": [
1413
"Andrew Tate is a former kickboxer, entrepreneur, and self-proclaimed misogynist.",

characters/trump.character.json

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"model": "en_US-male-medium"
99
}
1010
},
11-
"people": ["Kamala Harris", "Joe Biden", "Sleepy Joe"],
1211
"plugins": [],
1312
"bio": [
1413
"SAVED America from the China Virus (while they let cities burn)",

packages/client-discord/src/index.ts

+156-71
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { MessageManager } from "./messages.ts";
2222
import channelStateProvider from "./providers/channelState.ts";
2323
import voiceStateProvider from "./providers/voiceState.ts";
2424
import { VoiceManager } from "./voice.ts";
25-
import { validateDiscordConfig } from "./enviroment.ts";
25+
import { PermissionsBitField } from "discord.js";
2626

2727
export class DiscordClient extends EventEmitter {
2828
apiToken: string;
@@ -34,6 +34,7 @@ export class DiscordClient extends EventEmitter {
3434

3535
constructor(runtime: IAgentRuntime) {
3636
super();
37+
3738
this.apiToken = runtime.getSetting("DISCORD_API_TOKEN") as string;
3839
this.client = new Client({
3940
intents: [
@@ -112,85 +113,173 @@ export class DiscordClient extends EventEmitter {
112113

113114
private async onClientReady(readyClient: { user: { tag: any; id: any } }) {
114115
elizaLogger.success(`Logged in as ${readyClient.user?.tag}`);
116+
117+
// Register slash commands
118+
const commands = [
119+
{
120+
name: "joinchannel",
121+
description: "Join a voice channel",
122+
options: [
123+
{
124+
name: "channel",
125+
type: 7, // CHANNEL type
126+
description: "The voice channel to join",
127+
required: true,
128+
channel_types: [2], // GuildVoice type
129+
},
130+
],
131+
},
132+
{
133+
name: "leavechannel",
134+
description: "Leave the current voice channel",
135+
},
136+
];
137+
138+
try {
139+
await this.client.application?.commands.set(commands);
140+
elizaLogger.success("Slash commands registered");
141+
} catch (error) {
142+
console.error("Error registering slash commands:", error);
143+
}
144+
145+
// Required permissions for the bot
146+
const requiredPermissions = [
147+
// Text Permissions
148+
PermissionsBitField.Flags.ViewChannel,
149+
PermissionsBitField.Flags.SendMessages,
150+
PermissionsBitField.Flags.SendMessagesInThreads,
151+
PermissionsBitField.Flags.CreatePrivateThreads,
152+
PermissionsBitField.Flags.CreatePublicThreads,
153+
PermissionsBitField.Flags.EmbedLinks,
154+
PermissionsBitField.Flags.AttachFiles,
155+
PermissionsBitField.Flags.AddReactions,
156+
PermissionsBitField.Flags.UseExternalEmojis,
157+
PermissionsBitField.Flags.UseExternalStickers,
158+
PermissionsBitField.Flags.MentionEveryone,
159+
PermissionsBitField.Flags.ManageMessages,
160+
PermissionsBitField.Flags.ReadMessageHistory,
161+
// Voice Permissions
162+
PermissionsBitField.Flags.Connect,
163+
PermissionsBitField.Flags.Speak,
164+
PermissionsBitField.Flags.UseVAD,
165+
PermissionsBitField.Flags.PrioritySpeaker,
166+
].reduce((a, b) => a | b, 0n);
167+
115168
elizaLogger.success("Use this URL to add the bot to your server:");
116169
elizaLogger.success(
117-
`https://discord.com/api/oauth2/authorize?client_id=${readyClient.user?.id}&permissions=0&scope=bot%20applications.commands`
170+
`https://discord.com/api/oauth2/authorize?client_id=${readyClient.user?.id}&permissions=${requiredPermissions}&scope=bot%20applications.commands`
118171
);
119172
await this.onReady();
120173
}
121174

122175
async handleReactionAdd(reaction: MessageReaction, user: User) {
123-
elizaLogger.log("Reaction added");
124-
// if (user.bot) return;
125-
126-
let emoji = reaction.emoji.name;
127-
if (!emoji && reaction.emoji.id) {
128-
emoji = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
129-
}
176+
try {
177+
elizaLogger.log("Reaction added");
130178

131-
// Fetch the full message if it's a partial
132-
if (reaction.partial) {
133-
try {
134-
await reaction.fetch();
135-
} catch (error) {
136-
console.error(
137-
"Something went wrong when fetching the message:",
138-
error
139-
);
179+
// Early returns
180+
if (!reaction || !user) {
181+
elizaLogger.warn("Invalid reaction or user");
140182
return;
141183
}
142-
}
143184

144-
const messageContent = reaction.message.content;
145-
const truncatedContent =
146-
messageContent.length > 100
147-
? messageContent.substring(0, 100) + "..."
148-
: messageContent;
185+
// Get emoji info
186+
let emoji = reaction.emoji.name;
187+
if (!emoji && reaction.emoji.id) {
188+
emoji = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
189+
}
149190

150-
const reactionMessage = `*<${emoji}>: "${truncatedContent}"*`;
191+
// Fetch full message if partial
192+
if (reaction.partial) {
193+
try {
194+
await reaction.fetch();
195+
} catch (error) {
196+
elizaLogger.error(
197+
"Failed to fetch partial reaction:",
198+
error
199+
);
200+
return;
201+
}
202+
}
151203

152-
const roomId = stringToUuid(
153-
reaction.message.channel.id + "-" + this.runtime.agentId
154-
);
155-
const userIdUUID = stringToUuid(user.id + "-" + this.runtime.agentId);
204+
// Generate IDs with timestamp to ensure uniqueness
205+
const timestamp = Date.now();
206+
const roomId = stringToUuid(
207+
`${reaction.message.channel.id}-${this.runtime.agentId}`
208+
);
209+
const userIdUUID = stringToUuid(
210+
`${user.id}-${this.runtime.agentId}`
211+
);
212+
const reactionUUID = stringToUuid(
213+
`${reaction.message.id}-${user.id}-${emoji}-${timestamp}-${this.runtime.agentId}`
214+
);
215+
216+
// Validate IDs
217+
if (!userIdUUID || !roomId) {
218+
elizaLogger.error("Invalid user ID or room ID", {
219+
userIdUUID,
220+
roomId,
221+
});
222+
return;
223+
}
156224

157-
// Generate a unique UUID for the reaction
158-
const reactionUUID = stringToUuid(
159-
`${reaction.message.id}-${user.id}-${emoji}-${this.runtime.agentId}`
160-
);
225+
// Process message content
226+
const messageContent = reaction.message.content || "";
227+
const truncatedContent =
228+
messageContent.length > 100
229+
? `${messageContent.substring(0, 100)}...`
230+
: messageContent;
231+
const reactionMessage = `*<${emoji}>: "${truncatedContent}"*`;
232+
233+
// Get user info
234+
const userName = reaction.message.author?.username || "unknown";
235+
const name = reaction.message.author?.displayName || userName;
236+
237+
// Ensure connection
238+
await this.runtime.ensureConnection(
239+
userIdUUID,
240+
roomId,
241+
userName,
242+
name,
243+
"discord"
244+
);
245+
246+
// Create memory with retry logic
247+
const memory = {
248+
id: reactionUUID,
249+
userId: userIdUUID,
250+
agentId: this.runtime.agentId,
251+
content: {
252+
text: reactionMessage,
253+
source: "discord",
254+
inReplyTo: stringToUuid(
255+
`${reaction.message.id}-${this.runtime.agentId}`
256+
),
257+
},
258+
roomId,
259+
createdAt: timestamp,
260+
embedding: getEmbeddingZeroVector(this.runtime),
261+
};
161262

162-
// ensure the user id and room id are valid
163-
if (!userIdUUID || !roomId) {
164-
console.error("Invalid user id or room id");
165-
return;
263+
try {
264+
await this.runtime.messageManager.createMemory(memory);
265+
elizaLogger.debug("Reaction memory created", {
266+
reactionId: reactionUUID,
267+
emoji,
268+
userId: user.id,
269+
});
270+
} catch (error) {
271+
if (error.code === "23505") {
272+
// Duplicate key error
273+
elizaLogger.warn("Duplicate reaction memory, skipping", {
274+
reactionId: reactionUUID,
275+
});
276+
return;
277+
}
278+
throw error; // Re-throw other errors
279+
}
280+
} catch (error) {
281+
elizaLogger.error("Error handling reaction:", error);
166282
}
167-
const userName = reaction.message.author.username;
168-
const name = reaction.message.author.displayName;
169-
170-
await this.runtime.ensureConnection(
171-
userIdUUID,
172-
roomId,
173-
userName,
174-
name,
175-
"discord"
176-
);
177-
178-
// Save the reaction as a message
179-
await this.runtime.messageManager.createMemory({
180-
id: reactionUUID, // This is the ID of the reaction message
181-
userId: userIdUUID,
182-
agentId: this.runtime.agentId,
183-
content: {
184-
text: reactionMessage,
185-
source: "discord",
186-
inReplyTo: stringToUuid(
187-
reaction.message.id + "-" + this.runtime.agentId
188-
), // This is the ID of the original message
189-
},
190-
roomId,
191-
createdAt: Date.now(),
192-
embedding: getEmbeddingZeroVector(this.runtime),
193-
});
194283
}
195284

196285
async handleReactionRemove(reaction: MessageReaction, user: User) {
@@ -298,12 +387,8 @@ export function startDiscord(runtime: IAgentRuntime) {
298387
}
299388

300389
export const DiscordClientInterface: ElizaClient = {
301-
start: async (runtime: IAgentRuntime) => {
302-
await validateDiscordConfig(runtime);
303-
304-
return new DiscordClient(runtime);
305-
},
306-
stop: async (_runtime: IAgentRuntime) => {
390+
start: async (runtime: IAgentRuntime) => new DiscordClient(runtime),
391+
stop: async (runtime: IAgentRuntime) => {
307392
console.warn("Discord client does not support stopping yet");
308393
},
309-
};
394+
};

packages/core/src/defaultCharacter.ts

-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ export const defaultCharacter: Character = {
213213
"vaguely offensive but also hilarious",
214214
"schizo-autist",
215215
],
216-
people: [],
217216
topics: [
218217
// broad topics
219218
"metaphysics",

packages/core/src/enviroment.ts

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export const CharacterSchema = z.object({
7474
lore: z.array(z.string()),
7575
messageExamples: z.array(z.array(MessageExampleSchema)),
7676
postExamples: z.array(z.string()),
77-
people: z.array(z.string()),
7877
topics: z.array(z.string()),
7978
adjectives: z.array(z.string()),
8079
knowledge: z.array(z.string()).optional(),

0 commit comments

Comments
 (0)