Skip to content

Commit

Permalink
(GH125) Escape prefix character when evaluating messages
Browse files Browse the repository at this point in the history
Any single character can be defined as the prefix character (default is "!") that indicates to PoshBot that the incoming message is a bot command. Some of these characters are also regex special characters and we need to escape them properly so when people indicate they want to use the '.' or '^' characters for example, they are treated a literal.
  • Loading branch information
Windos authored and devblackops committed Oct 11, 2018
1 parent 246a66c commit 92e8742
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PoshBot/Classes/Bot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Bot : BaseLogger {
[bool]IsBotCommand([Message]$Message) {
$parsedCommand = [CommandParser]::Parse($Message)
foreach ($prefix in $this._PossibleCommandPrefixes ) {
$prefix = [regex]::Escape($prefix)
if ($parsedCommand.command -match "^$prefix") {
$this.LogDebug('Message is a bot command')
return $true
Expand Down Expand Up @@ -519,7 +520,8 @@ class Bot : BaseLogger {
$firstWord = ($Message.Text -split ' ')[0]

foreach ($prefix in $this._PossibleCommandPrefixes) {
if ($firstWord -match "^$prefix") {
$prefixEscaped = [regex]::Escape($prefix)
if ($firstWord -match "^$prefixEscaped") {
$Message.Text = $Message.Text.TrimStart($prefix).Trim()
}
}
Expand Down

0 comments on commit 92e8742

Please sign in to comment.