Skip to content

Commit c4e8601

Browse files
authoredNov 15, 2024··
Merge pull request #336 from vivoidos/client-settings
added clientConfig to optionally ignore bots and DMs
2 parents 9013a94 + 08a7c1d commit c4e8601

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed
 

‎packages/client-discord/src/messages.ts

+29-13
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,26 @@ export class MessageManager {
341341
if (
342342
message.interaction ||
343343
message.author.id ===
344-
this.client.user?.id /* || message.author?.bot*/
344+
this.client.user?.id /* || message.author?.bot*/
345345
)
346346
return;
347+
348+
if (
349+
this.runtime.character.clientConfig?.discord
350+
?.shouldIgnoreBotMessages &&
351+
message.author?.bot
352+
) {
353+
return;
354+
}
355+
356+
if (
357+
this.runtime.character.clientConfig?.discord
358+
?.shouldIgnoreDirectMessages &&
359+
message.channel.type === ChannelType.DM
360+
) {
361+
return;
362+
}
363+
347364
const userId = message.author.id as UUID;
348365
const userName = message.author.username;
349366
const name = message.author.displayName;
@@ -389,10 +406,10 @@ export class MessageManager {
389406
url: message.url,
390407
inReplyTo: message.reference?.messageId
391408
? stringToUuid(
392-
message.reference.messageId +
393-
"-" +
394-
this.runtime.agentId
395-
)
409+
message.reference.messageId +
410+
"-" +
411+
this.runtime.agentId
412+
)
396413
: undefined,
397414
};
398415

@@ -503,11 +520,9 @@ export class MessageManager {
503520
}
504521
if (message.channel.type === ChannelType.GuildVoice) {
505522
// For voice channels, use text-to-speech
506-
const audioStream = await (
507-
this.runtime.getService(
508-
ServiceType.SPEECH_GENERATION
509-
)
510-
).getInstance<ISpeechService>()
523+
const audioStream = await this.runtime
524+
.getService(ServiceType.SPEECH_GENERATION)
525+
.getInstance<ISpeechService>()
511526
.generate(this.runtime, content.text);
512527
await this.voiceManager.playAudioStream(
513528
userId,
@@ -659,14 +674,15 @@ export class MessageManager {
659674

660675
for (const url of urls) {
661676
if (
662-
this.runtime.getService(ServiceType.VIDEO)
677+
this.runtime
678+
.getService(ServiceType.VIDEO)
663679
.getInstance<IVideoService>()
664680
.isVideoUrl(url)
665681
) {
666-
const videoInfo = await (this.runtime
682+
const videoInfo = await this.runtime
667683
.getService(ServiceType.VIDEO)
668684
.getInstance<IVideoService>()
669-
.processVideo(url));
685+
.processVideo(url);
670686
attachments.push({
671687
id: `youtube-${Date.now()}`,
672688
url: url,

‎packages/client-telegram/src/messageManager.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,20 @@ export class MessageManager {
318318
return; // Exit if no message or sender info
319319
}
320320

321-
// TODO: Handle commands?
322-
// if (ctx.message.text?.startsWith("/")) {
323-
// return;
324-
// }
321+
if (
322+
this.runtime.character.clientConfig?.telegram
323+
?.shouldIgnoreBotMessages &&
324+
ctx.from.is_bot
325+
) {
326+
return;
327+
}
328+
if (
329+
this.runtime.character.clientConfig?.telegram
330+
?.shouldIgnoreDirectMessages &&
331+
ctx.chat?.type === "private"
332+
) {
333+
return;
334+
}
325335

326336
const message = ctx.message;
327337

@@ -482,4 +492,4 @@ export class MessageManager {
482492
console.error("Error sending message:", error);
483493
}
484494
}
485-
}
495+
}

‎packages/core/src/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ export type Character = {
352352
model?: string;
353353
embeddingModel?: string;
354354
};
355+
clientConfig?: {
356+
discord?: {
357+
shouldIgnoreBotMessages?: boolean;
358+
shouldIgnoreDirectMessages?: boolean;
359+
};
360+
telegram?: {
361+
shouldIgnoreBotMessages?: boolean;
362+
shouldIgnoreDirectMessages?: boolean;
363+
};
364+
};
355365
style: {
356366
all: string[];
357367
chat: string[];

0 commit comments

Comments
 (0)
Please sign in to comment.