Skip to content

Commit

Permalink
[fix] drop the bot username when passed as command
Browse files Browse the repository at this point in the history
Telegram applications suffix the commands with the bot name handle eg.
`/foo@bot-name ...`.
  • Loading branch information
zenlor committed Sep 6, 2023
1 parent d2ceaf0 commit 119ac6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/moolite/bot/parse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
(ns moolite.bot.parse
(:require [instaparse.core :as insta]
[taoensso.timbre :as timbre :refer [info debug]]))
(:require [instaparse.core :as insta]))

(def text-lang
(insta/parser
Expand All @@ -14,7 +13,7 @@
<space> : <' '>
command : <'/'>
callout : <'!'>
abraxas : #'[-a-zA-Z0-9]+'
abraxas : #'[-a-zA-Z0-9]+' <('@' #'[a-zA-Z0-9-]+')?>
del : <'rm'|'rem'|'del'|'rimuovi'|'cancella'|'dd'|'-'>
add : <'add'|'aggiungi'|'nuovo'|'crea'|'new'|'+'>
url : #'https?://[^ ]+'
Expand All @@ -28,3 +27,6 @@
(if (insta/failure? results)
[]
results)))

(comment
(insta/parse text-lang "/cmd@marrano-bot fooo bar"));; => [:message [:command] [:abraxas "cmd"] [:text "fooo bar"]]
5 changes: 5 additions & 0 deletions test/moolite/bot/parse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
:else (is false))

(match (#'p/text-lang "/d20 4d6k2")
[_ [:command] [:abraxas "d20"] [:text text]]
(is text "4d6k2")
:else (is false))

(match (#'p/text-lang "/d20@marrano-bot 4d6k2")
[_ [:command] [:abraxas "d20"] [:text text]]
(is text "4d6k2")
:else (is false)))
Expand Down

0 comments on commit 119ac6d

Please sign in to comment.