Skip to content

Commit

Permalink
Merge branch 'v2-develop' into 0xbbjoker/fix-pglite
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo authored Feb 25, 2025
2 parents 6a7a3c6 + 13224d6 commit 3c2fb1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type UserJoinedParams = {
user: any;
serverId: string;
channelId: string;
channelType: ChannelType,
source: string;
};

Expand Down Expand Up @@ -326,6 +327,7 @@ const syncLargeServerUsers = async (
Array.from(activeUsers),
guild.id,
channelId,
ChannelType.GROUP,
source
);
}
Expand Down Expand Up @@ -354,7 +356,7 @@ const syncLargeServerUsers = async (
}));

// Sync this batch to the general server (not channel-specific)
await syncMultipleUsers(runtime, users, guild.id, null, source);
await syncMultipleUsers(runtime, users, guild.id, null, ChannelType.WORLD, source);

// Add a delay between batches to avoid rate limits
if (i + batchSize < onlineMembersArray.length) {
Expand Down Expand Up @@ -458,7 +460,7 @@ const syncRegularServerUsers = async (
}));

// Note: null channelId means this sync is server-wide
await syncMultipleUsers(runtime, users, guild.id, null, source);
await syncMultipleUsers(runtime, users, guild.id, null, ChannelType.WORLD, source);

// Add a small delay between batches
if (i + batchSize < membersArray.length) {
Expand All @@ -480,13 +482,15 @@ const syncSingleUser = async (
user: any,
serverId: string,
channelId: string,
type: ChannelType,
source: string
) => {
logger.info(`Syncing user: ${user.username || user.id}`);

try {
const userId = stringToUuid(`${user.id}-${runtime.agentId}`);
const roomId = stringToUuid(`${channelId}-${runtime.agentId}`);
const worldId = stringToUuid(`${serverId}-${runtime.agentId}`);

// Ensure user exists
await runtime.getOrCreateUser(
Expand All @@ -495,6 +499,8 @@ const syncSingleUser = async (
user.displayName || user.username || `User${user.id}`,
source
);

await runtime.ensureRoomExists({id: roomId, source, type, channelId, serverId, worldId});

// Add user to the channel's room
await runtime.ensureParticipantInRoom(userId, roomId);
Expand All @@ -513,13 +519,14 @@ const syncMultipleUsers = async (
users: any[],
serverId: string,
channelId: string,
type: ChannelType,
source: string
) => {
logger.info(`Syncing ${users.length} users for channel ${channelId}`);

try {
const roomId = stringToUuid(`${channelId}-${runtime.agentId}`);

const worldId = stringToUuid(`${serverId}-${runtime.agentId}`);
// Process users in batches to avoid overwhelming the system
const batchSize = 10;
for (let i = 0; i < users.length; i += batchSize) {
Expand All @@ -538,6 +545,7 @@ const syncMultipleUsers = async (
source
);

await runtime.ensureRoomExists({id: roomId, source, type, channelId, serverId, worldId});
// Add user to the room
await runtime.ensureParticipantInRoom(userId, roomId);
} catch (err) {
Expand Down Expand Up @@ -588,8 +596,8 @@ const events = {
}
],
USER_JOINED: [
async ({ runtime, user, serverId, channelId, source }: UserJoinedParams) => {
await syncSingleUser(runtime, user, serverId, channelId, source);
async ({ runtime, user, serverId, channelId, channelType, source }: UserJoinedParams) => {
await syncSingleUser(runtime, user, serverId, channelId, channelType, source);
}
],
};
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export class DiscordClient extends EventEmitter implements IDiscordClient {
},
serverId: guild.id,
channelId: null, // No specific channel for server joins
channelType: ChannelType.WORLD,
source: "discord"
});

Expand All @@ -183,6 +184,7 @@ export class DiscordClient extends EventEmitter implements IDiscordClient {
},
serverId: guild.id,
channelId: channelId,
channelType: ChannelType.GROUP,
source: "discord"
});
}
Expand Down

0 comments on commit 3c2fb1c

Please sign in to comment.