@elizaos/plugin-discord 1.0.0-beta.3 → 1.0.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/index.js +20 -25
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025 Shaw Walters
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.js
CHANGED
|
@@ -2062,23 +2062,6 @@ import {
|
|
|
2062
2062
|
PermissionsBitField,
|
|
2063
2063
|
ThreadChannel
|
|
2064
2064
|
} from "discord.js";
|
|
2065
|
-
function getWavHeader(audioLength, sampleRate, channelCount = 1, bitsPerSample = 16) {
|
|
2066
|
-
const wavHeader = Buffer.alloc(44);
|
|
2067
|
-
wavHeader.write("RIFF", 0);
|
|
2068
|
-
wavHeader.writeUInt32LE(36 + audioLength, 4);
|
|
2069
|
-
wavHeader.write("WAVE", 8);
|
|
2070
|
-
wavHeader.write("fmt ", 12);
|
|
2071
|
-
wavHeader.writeUInt32LE(16, 16);
|
|
2072
|
-
wavHeader.writeUInt16LE(1, 20);
|
|
2073
|
-
wavHeader.writeUInt16LE(channelCount, 22);
|
|
2074
|
-
wavHeader.writeUInt32LE(sampleRate, 24);
|
|
2075
|
-
wavHeader.writeUInt32LE(sampleRate * bitsPerSample * channelCount / 8, 28);
|
|
2076
|
-
wavHeader.writeUInt16LE(bitsPerSample * channelCount / 8, 32);
|
|
2077
|
-
wavHeader.writeUInt16LE(bitsPerSample, 34);
|
|
2078
|
-
wavHeader.write("data", 36);
|
|
2079
|
-
wavHeader.writeUInt32LE(audioLength, 40);
|
|
2080
|
-
return wavHeader;
|
|
2081
|
-
}
|
|
2082
2065
|
var MAX_MESSAGE_LENGTH = 1900;
|
|
2083
2066
|
async function sendMessageInChunks(channel, content, _inReplyTo, files) {
|
|
2084
2067
|
const sentMessages = [];
|
|
@@ -2207,6 +2190,9 @@ var MessageManager = class {
|
|
|
2207
2190
|
if (this.runtime.character.settings?.discord?.shouldIgnoreDirectMessages && message.channel.type === DiscordChannelType2.DM) {
|
|
2208
2191
|
return;
|
|
2209
2192
|
}
|
|
2193
|
+
if (this.runtime.character.settings?.discord?.shouldRespondOnlyToMentions && !message.mentions.users?.has(this.client.user?.id)) {
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2210
2196
|
const entityId = createUniqueUuid4(this.runtime, message.author.id);
|
|
2211
2197
|
const userName = message.author.bot ? `${message.author.username}#${message.author.discriminator}` : message.author.username;
|
|
2212
2198
|
const name = message.author.displayName;
|
|
@@ -2432,6 +2418,7 @@ import {
|
|
|
2432
2418
|
ChannelType as ChannelType8,
|
|
2433
2419
|
ModelType as ModelType8,
|
|
2434
2420
|
createUniqueUuid as createUniqueUuid5,
|
|
2421
|
+
getWavHeader,
|
|
2435
2422
|
logger as logger5
|
|
2436
2423
|
} from "@elizaos/core";
|
|
2437
2424
|
import {
|
|
@@ -2872,8 +2859,7 @@ var VoiceManager = class extends EventEmitter {
|
|
|
2872
2859
|
* @param {BaseGuildVoiceChannel} channel - The voice channel the user is in.
|
|
2873
2860
|
* @param {Readable} audioStream - The audio stream to monitor.
|
|
2874
2861
|
*/
|
|
2875
|
-
async handleUserStream(
|
|
2876
|
-
const entityId = createUniqueUuid5(this.runtime, userId);
|
|
2862
|
+
async handleUserStream(entityId, name, userName, channel, audioStream) {
|
|
2877
2863
|
logger5.debug(`Starting audio monitor for user: ${entityId}`);
|
|
2878
2864
|
if (!this.userStates.has(entityId)) {
|
|
2879
2865
|
this.userStates.set(entityId, {
|
|
@@ -2965,9 +2951,10 @@ var VoiceManager = class extends EventEmitter {
|
|
|
2965
2951
|
return { text: "", actions: ["IGNORE"] };
|
|
2966
2952
|
}
|
|
2967
2953
|
const roomId = createUniqueUuid5(this.runtime, channelId);
|
|
2954
|
+
const uniqueEntityId = createUniqueUuid5(this.runtime, entityId);
|
|
2968
2955
|
const type = await this.getChannelType(channel);
|
|
2969
2956
|
await this.runtime.ensureConnection({
|
|
2970
|
-
entityId,
|
|
2957
|
+
entityId: uniqueEntityId,
|
|
2971
2958
|
roomId,
|
|
2972
2959
|
userName,
|
|
2973
2960
|
name,
|
|
@@ -2979,7 +2966,7 @@ var VoiceManager = class extends EventEmitter {
|
|
|
2979
2966
|
const memory = {
|
|
2980
2967
|
id: createUniqueUuid5(this.runtime, `${channelId}-voice-message-${Date.now()}`),
|
|
2981
2968
|
agentId: this.runtime.agentId,
|
|
2982
|
-
entityId,
|
|
2969
|
+
entityId: uniqueEntityId,
|
|
2983
2970
|
roomId,
|
|
2984
2971
|
content: {
|
|
2985
2972
|
text: message,
|
|
@@ -3009,7 +2996,7 @@ var VoiceManager = class extends EventEmitter {
|
|
|
3009
2996
|
createdAt: Date.now()
|
|
3010
2997
|
};
|
|
3011
2998
|
if (responseMemory.content.text?.trim()) {
|
|
3012
|
-
await this.runtime.createMemory(responseMemory);
|
|
2999
|
+
await this.runtime.createMemory(responseMemory, "messages");
|
|
3013
3000
|
const responseStream = await this.runtime.useModel(
|
|
3014
3001
|
ModelType8.TEXT_TO_SPEECH,
|
|
3015
3002
|
content.text
|
|
@@ -3301,6 +3288,11 @@ var DiscordService = class _DiscordService extends Service {
|
|
|
3301
3288
|
logger6.error(`Error handling interaction: ${error}`);
|
|
3302
3289
|
}
|
|
3303
3290
|
});
|
|
3291
|
+
this.client.on("userStream", (entityId, name, userName, channel, opusDecoder) => {
|
|
3292
|
+
if (entityId !== this.client?.user?.id) {
|
|
3293
|
+
this.voiceManager.handleUserStream(entityId, name, userName, channel, opusDecoder);
|
|
3294
|
+
}
|
|
3295
|
+
});
|
|
3304
3296
|
}
|
|
3305
3297
|
/**
|
|
3306
3298
|
* Handles the event when a new member joins a guild.
|
|
@@ -3312,10 +3304,12 @@ var DiscordService = class _DiscordService extends Service {
|
|
|
3312
3304
|
logger6.log(`New member joined: ${member.user.username}`);
|
|
3313
3305
|
const guild = member.guild;
|
|
3314
3306
|
const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
|
|
3307
|
+
const worldId = createUniqueUuid6(this.runtime, guild.id);
|
|
3308
|
+
const entityId = createUniqueUuid6(this.runtime, member.id);
|
|
3315
3309
|
this.runtime.emitEvent([EventType2.ENTITY_JOINED], {
|
|
3316
3310
|
runtime: this.runtime,
|
|
3317
|
-
entityId
|
|
3318
|
-
worldId
|
|
3311
|
+
entityId,
|
|
3312
|
+
worldId,
|
|
3319
3313
|
source: "discord",
|
|
3320
3314
|
metadata: {
|
|
3321
3315
|
originalId: member.id,
|
|
@@ -3327,7 +3321,8 @@ var DiscordService = class _DiscordService extends Service {
|
|
|
3327
3321
|
});
|
|
3328
3322
|
this.runtime.emitEvent(["DISCORD_USER_JOINED" /* ENTITY_JOINED */], {
|
|
3329
3323
|
runtime: this.runtime,
|
|
3330
|
-
entityId
|
|
3324
|
+
entityId,
|
|
3325
|
+
worldId,
|
|
3331
3326
|
member,
|
|
3332
3327
|
guild
|
|
3333
3328
|
});
|