Skip to content

Commit

Permalink
feat: ability to restrict usage to certain channels
Browse files Browse the repository at this point in the history
When this is specified, Robos won't respond to messages even if they're mentioned unless the interaction takes place in one of these channels.

Ref: #191
  • Loading branch information
Pkmmte committed Jan 13, 2024
1 parent f80ce66 commit 86cd358
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-laws-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@roboplay/plugin-ai': patch
---

feat: ability to restrict usage to certain channels
5 changes: 5 additions & 0 deletions packages/plugin-ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export default {
// Knowledge injection & long-term memory. (boolean; default: true)
insights: true,

// If specified, your AI will only respond to messages in these channels. (object with array of string IDs)
restrict: {
channelIds: ['channelID3']
},

// Special channels where Robo talks freely. (object with array of string IDs)
whitelist: {
channelIds: ['channelID1', 'channelID2']
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-ai/src/events/_start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface PluginOptions {
insight?: boolean
maxTokens?: number
model?: string
restrict?: {
channelIds: string[]
}
systemMessage?: string
whitelist?: {
channelIds: string[]
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-ai/src/events/messageCreate/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export default async (message: Message) => {
return
}

// Restrict to specific channels if specified
const isRestricted = pluginOptions.restrict?.channelIds?.length
if (isRestricted && !pluginOptions.restrict?.channelIds?.includes(message.channelId)) {
logger.debug(`Message received in channel ${message.channelId} but restricted to specific channels`)
return
}

// Don't respond unless mentioned unless in whitelisted channel or DM
const isOpenConvo = pluginOptions.whitelist?.channelIds?.includes(message.channel.id) || message.channel.isDMBased()
if (!message.mentions.users.has(client.user?.id ?? '') && !isOpenConvo) {
Expand Down

1 comment on commit 86cd358

@vercel
Copy link

@vercel vercel bot commented on 86cd358 Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.