Skip to content

Commit a5b1006

Browse files
committed
Remove some discord state deps
1 parent 5ff1eb8 commit a5b1006

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

bun.lockb

654 Bytes
Binary file not shown.

packages/core/src/runtime.ts

+9
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@ export class AgentRuntime implements IAgentRuntime {
807807
]);
808808
}
809809

810+
/**
811+
* Get a world by ID.
812+
* @param worldId - The ID of the world to get.
813+
* @returns The world.
814+
*/
815+
async getWorld(worldId: UUID) {
816+
return await this.databaseAdapter.getWorld(worldId);
817+
}
818+
810819
/**
811820
* Ensure the existence of a world.
812821
*/

packages/core/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ export interface IAgentRuntime {
10851085

10861086
getUserProfile(userId: UUID): Promise<Account | null>;
10871087

1088+
getWorld(worldId: UUID): Promise<WorldData | null>;
1089+
10881090
ensureWorldExists({
10891091
id,
10901092
name,

packages/plugin-discord/src/actions/voiceJoin.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ export default {
125125
});
126126
return true;
127127
}
128-
const member = (discordMessage as DiscordMessage)
129-
.member as GuildMember;
128+
const guild = client.guilds.cache.get(serverId);
129+
const members = guild?.members.cache;
130+
131+
// get the member who's stringTouuid(id) === message userId
132+
const member = members?.find((member) => stringToUuid(member.id) === message.userId);
133+
134+
console.log("member", member);
135+
130136
if (member?.voice?.channel) {
131137
joinVoiceChannel({
132138
channelId: member.voice.channel.id,

packages/plugin-discord/src/providers/voiceState.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getVoiceConnection } from "@discordjs/voice";
2-
import { type Message as DiscordMessage, ChannelType as DiscordChannelType } from "discord.js";
32
import type { IAgentRuntime, Memory, Provider, State } from "@elizaos/core";
43
import { ChannelType } from "@elizaos/core";
54
const voiceStateProvider: Provider = {
@@ -27,17 +26,28 @@ const voiceStateProvider: Provider = {
2726
return `${agentName} is not currently in a voice channel`;
2827
}
2928

30-
const channel = (
31-
state?.discordMessage as DiscordMessage
32-
)?.guild?.channels?.cache?.get(
33-
connection.joinConfig.channelId as string
34-
);
29+
const worldId = room.worldId;
3530

36-
if (!channel || channel.type !== DiscordChannelType.GuildVoice) {
31+
// get the world from the runtime.getWorld
32+
const world = await runtime.getWorld(worldId);
33+
34+
if (!world) {
35+
throw new Error("No world found");
36+
}
37+
38+
const worldName = world.name;
39+
40+
const roomType = room.type;
41+
42+
const channelId = room.channelId
43+
44+
const channelName = room.name;
45+
46+
if (!channelId) {
3747
return `${agentName} is in an invalid voice channel`;
3848
}
3949

40-
return `${agentName} is currently in the voice channel: ${channel.name} (ID: ${channel.id})`;
50+
return `${agentName} is currently in the voice channel: ${channelName} (ID: ${channelId})`;
4151
},
4252
};
4353

packages/plugin-twitter/src/post.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ export class TwitterPostClient {
304304
"twitter"
305305
);
306306

307-
const topics = this.runtime.character.topics.join(", ");
307+
const topics = this.runtime.character.topics
308+
.sort(() => 0.5 - Math.random())
309+
.slice(0, 10)
310+
.join(", ")
308311
const state = await this.runtime.composeState(
309312
{
310313
userId: this.runtime.agentId,

0 commit comments

Comments
 (0)