Skip to content

Commit

Permalink
Revert #111 and trim CRLF from message text
Browse files Browse the repository at this point in the history
#111 broke the ability to run a command by the fully qualified command
name <plugin>:<commandname>:<version> by only testing the command name
against the possible command prefixes.
This reverts that behavior and tests the first word of the message string
but also ensures CRLF is removed.
  • Loading branch information
devblackops committed Oct 26, 2018
1 parent e2ba9a3 commit 5cadba8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions PoshBot/Classes/Bot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ class Bot : BaseLogger {
# Determine if message text is addressing the bot and should be
# treated as a bot command
[bool]IsBotCommand([Message]$Message) {
$parsedCommand = [CommandParser]::Parse($Message)
$firstWord = ($Message.Text -split ' ')[0].Trim()
foreach ($prefix in $this._PossibleCommandPrefixes ) {
$prefix = [regex]::Escape($prefix)
if ($parsedCommand.command -match "^$prefix") {
if ($firstWord -match "^$prefix") {
$this.LogDebug('Message is a bot command')
return $true
}
Expand Down Expand Up @@ -524,9 +524,7 @@ class Bot : BaseLogger {
# as we won't need them anymore.
[Message]TrimPrefix([Message]$Message) {
if (-not [string]::IsNullOrEmpty($Message.Text)) {
$Message.Text = $Message.Text.Trim()
$firstWord = ($Message.Text -split ' ')[0]

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

0 comments on commit 5cadba8

Please # to comment.