Skip to content

Commit

Permalink
Allow $null command prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
devblackops committed Mar 29, 2019
1 parent 4e6b59f commit f214e15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Strip extra newlines (\n) from messages received from Teams backend.
- Allow a `$null` command prefix. This is useful in backends like Teams that require you to @mention the bot (e.g. `@poshbot !status`).
This change removes the need for a command prefix as you are already specifying a bot command by @mentioning it.
The following syntax is now possible: `@poshbot status`

## [0.11.5] 2019-02-27

Expand Down
9 changes: 8 additions & 1 deletion PoshBot/Classes/Bot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,14 @@ class Bot : BaseLogger {
[bool]IsBotCommand([Message]$Message) {
$firstWord = ($Message.Text -split ' ')[0].Trim()
foreach ($prefix in $this._PossibleCommandPrefixes ) {
$prefix = [regex]::Escape($prefix)
# If we've elected for a $null prefix, don't escape it
# as [regex]::Escape() converts null chars into a space (' ')
if ([char]$null -eq $prefix) {
$prefix = ''
} else {
$prefix = [regex]::Escape($prefix)
}

if ($firstWord -match "^$prefix") {
$this.LogDebug('Message is a bot command')
return $true
Expand Down

0 comments on commit f214e15

Please sign in to comment.