Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other plugins overriding protections against ai activation #168

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ func (p *Plugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) {
}
}

const (
ActivateAIProp = "activate_ai"
FromWebhookProp = "from_webhook"
FromBotProp = "from_bot"
FromPluginProp = "from_plugin"
)

// handleMessages Handled messages posted. Returns true if a response was posted.
func (p *Plugin) handleMessages(post *model.Post) error {
// Don't respond to ouselves
Expand All @@ -214,13 +221,13 @@ func (p *Plugin) handleMessages(post *model.Post) error {
return fmt.Errorf("not responding to remote posts: %w", ErrNoResponse)
}

// Don't respond to plugins
if post.GetProp("from_plugin") != nil {
// Don't respond to plugins unless they ask for it
if post.GetProp(FromPluginProp) != nil && post.GetProp(ActivateAIProp) == nil {
return fmt.Errorf("not responding to plugin posts: %w", ErrNoResponse)
}

// Don't respond to webhooks
if post.GetProp("from_webhook") != nil {
if post.GetProp(FromWebhookProp) != nil {
return fmt.Errorf("not responding to webhook posts: %w", ErrNoResponse)
}

Expand All @@ -234,8 +241,8 @@ func (p *Plugin) handleMessages(post *model.Post) error {
return err
}

// Don't respond to other bots
if postingUser.IsBot || post.GetProp("from_bot") != nil {
// Don't respond to other bots unless they ask for it
if (postingUser.IsBot || post.GetProp(FromBotProp) != nil) && post.GetProp(ActivateAIProp) == nil {
return fmt.Errorf("not responding to other bots: %w", ErrNoResponse)
}

Expand Down
Loading