poshbotio / PoshBot

Powershell-based bot framework
MIT License
540 stars 108 forks source link

Constrain bot functionality by channel #70

Closed devblackops closed 6 years ago

devblackops commented 6 years ago

Description

This PR adds support for constraining PoshBot to certain channels and also controlling what plugin commands are allowed in said channels.

This also fixed a bug where the approval configuration settings where not being saved to the bot config file correctly.

There is a new bot configuration property called ChannelRules that is a hashtable[] to control what commands are included and excluded from channels(s). Wild cards are supported so multiple channels can be covered by a single "rule". The rules are evaluated in order so the most specific ones should be added first.

The fully qualified command name :: is what is evaluated so the rule examples below are supported.

Example bot.psd1

@{
    ChannelRules= @(
        # Only builtin and admin plugin commands allowed in the admin channel
        @{
            Channel = 'admin'
            IncludeCommands = @(
                'builtin:*'
                'myadminplugin:*'
            )
        }
        # It's the wild west in random, except giphy :)
        @{
            Channel = 'random'
            IncludeCommands = @('*')
            ExcludeCommands = @('*giphy*')
        }
        # Exclude builtin commands from any "projectX" channel
        @{
            Channel = '*projectx*'
            IncludeCommands = @('*')
            ExcludeCommands = @('builtin:*')
        }
        # All commands are otherwise allowed
        @{
            Channel = '*'
            IncludeCommands = @('*')
            ExcludeCommands = @()
        }
    )
}

Related Issue

36

Motivation and Context

See #36

How Has This Been Tested?

Manually tested new functionality

Types of changes

Checklist: