-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved CommandsRecognizerBot into core
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/scala/io/scalac/slack/bots/system/CommandsRecognizerBot.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.scalac.slack.bots.system | ||
|
||
import io.scalac.slack.MessageEventBus | ||
import io.scalac.slack.bots.IncomingMessageListener | ||
import io.scalac.slack.common.{BaseMessage, BotInfoKeeper, Command} | ||
|
||
class CommandsRecognizerBot(override val bus: MessageEventBus) extends IncomingMessageListener { | ||
|
||
val commandChar = '$' | ||
|
||
def receive: Receive = { | ||
|
||
case bm@BaseMessage(text, channel, user, dateTime, edited) => | ||
//COMMAND links list with bot's nam jack can be called: | ||
// jack link list | ||
// jack: link list | ||
// @jack link list | ||
// @jack: link list | ||
// $link list | ||
def changeIntoCommand(pattern: String): Boolean = { | ||
if (text.trim.startsWith(pattern)) { | ||
val tokenized = text.trim.drop(pattern.length).trim.split("\\s") | ||
publish(Command(tokenized.head, tokenized.tail.toList.filter(_.nonEmpty), bm)) | ||
true | ||
} | ||
false | ||
} | ||
|
||
//call by commad character | ||
if (!changeIntoCommand(commandChar.toString)) | ||
BotInfoKeeper.current match { | ||
case Some(bi) => | ||
//call by name | ||
changeIntoCommand(bi.name + ":") || | ||
changeIntoCommand(bi.name) || | ||
//call by ID | ||
changeIntoCommand(s"<@${bi.id}>:") || | ||
changeIntoCommand(s"<@${bi.id}>") | ||
|
||
case None => //nothing to do! | ||
} | ||
} | ||
} |