From f214e1577b301f1bef8af8d752de73c84bcb6fcd Mon Sep 17 00:00:00 2001 From: Brandon Olin Date: Thu, 28 Mar 2019 22:07:42 -0700 Subject: [PATCH] Allow $null command prefixes --- CHANGELOG.md | 3 +++ PoshBot/Classes/Bot.ps1 | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f37251..dbfd35dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/PoshBot/Classes/Bot.ps1 b/PoshBot/Classes/Bot.ps1 index 5ccefd39..46b44895 100644 --- a/PoshBot/Classes/Bot.ps1 +++ b/PoshBot/Classes/Bot.ps1 @@ -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