Skip to content

Commit

Permalink
Merge pull request #336 from vivoidos/client-settings
Browse files Browse the repository at this point in the history
added clientConfig to optionally ignore bots and DMs
  • Loading branch information
lalalune authored Nov 15, 2024
2 parents 9013a94 + 08a7c1d commit c4e8601
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
42 changes: 29 additions & 13 deletions packages/client-discord/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,26 @@ export class MessageManager {
if (
message.interaction ||
message.author.id ===
this.client.user?.id /* || message.author?.bot*/
this.client.user?.id /* || message.author?.bot*/
)
return;

if (
this.runtime.character.clientConfig?.discord
?.shouldIgnoreBotMessages &&
message.author?.bot
) {
return;
}

if (
this.runtime.character.clientConfig?.discord
?.shouldIgnoreDirectMessages &&
message.channel.type === ChannelType.DM
) {
return;
}

const userId = message.author.id as UUID;
const userName = message.author.username;
const name = message.author.displayName;
Expand Down Expand Up @@ -389,10 +406,10 @@ export class MessageManager {
url: message.url,
inReplyTo: message.reference?.messageId
? stringToUuid(
message.reference.messageId +
"-" +
this.runtime.agentId
)
message.reference.messageId +
"-" +
this.runtime.agentId
)
: undefined,
};

Expand Down Expand Up @@ -503,11 +520,9 @@ export class MessageManager {
}
if (message.channel.type === ChannelType.GuildVoice) {
// For voice channels, use text-to-speech
const audioStream = await (
this.runtime.getService(
ServiceType.SPEECH_GENERATION
)
).getInstance<ISpeechService>()
const audioStream = await this.runtime
.getService(ServiceType.SPEECH_GENERATION)
.getInstance<ISpeechService>()
.generate(this.runtime, content.text);
await this.voiceManager.playAudioStream(
userId,
Expand Down Expand Up @@ -659,14 +674,15 @@ export class MessageManager {

for (const url of urls) {
if (
this.runtime.getService(ServiceType.VIDEO)
this.runtime
.getService(ServiceType.VIDEO)
.getInstance<IVideoService>()
.isVideoUrl(url)
) {
const videoInfo = await (this.runtime
const videoInfo = await this.runtime
.getService(ServiceType.VIDEO)
.getInstance<IVideoService>()
.processVideo(url));
.processVideo(url);
attachments.push({
id: `youtube-${Date.now()}`,
url: url,
Expand Down
20 changes: 15 additions & 5 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,20 @@ export class MessageManager {
return; // Exit if no message or sender info
}

// TODO: Handle commands?
// if (ctx.message.text?.startsWith("/")) {
// return;
// }
if (
this.runtime.character.clientConfig?.telegram
?.shouldIgnoreBotMessages &&
ctx.from.is_bot
) {
return;
}
if (
this.runtime.character.clientConfig?.telegram
?.shouldIgnoreDirectMessages &&
ctx.chat?.type === "private"
) {
return;
}

const message = ctx.message;

Expand Down Expand Up @@ -482,4 +492,4 @@ export class MessageManager {
console.error("Error sending message:", error);
}
}
}
}
10 changes: 10 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ export type Character = {
model?: string;
embeddingModel?: string;
};
clientConfig?: {
discord?: {
shouldIgnoreBotMessages?: boolean;
shouldIgnoreDirectMessages?: boolean;
};
telegram?: {
shouldIgnoreBotMessages?: boolean;
shouldIgnoreDirectMessages?: boolean;
};
};
style: {
all: string[];
chat: string[];
Expand Down

0 comments on commit c4e8601

Please sign in to comment.