Skip to content

Commit

Permalink
extensions: Scheme code should trim out spaces and special characters…
Browse files Browse the repository at this point in the history
… from jid
  • Loading branch information
Harshavardhana committed May 5, 2014
1 parent e08b71c commit 21d6d83
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
10 changes: 7 additions & 3 deletions extensions/hacker-romance.scm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
(message (string-join (cddr args-list))))
(if (and (> (string-length message) 0)
(> count 0))
(burst-of-romance buddy count message)))
(burst-of-romance (string-trim-right buddy #\:) count message)))
(ft-display (_ "usage: /burst-of-romance BUDDY COUNT MESSAGE")))))

(add-command! /burst-of-romance "/burst-of-romance"
Expand Down Expand Up @@ -73,7 +73,9 @@
(buddy (car args-list))
(message (cadr args-list)))
(if (> (string-length message) 0)
(ft-send-message buddy (burst message min-chars max-chars))
(ft-send-message (string-trim-right buddy #\:) (burst message
min-chars
max-chars))
(ft-display (_ "usage: /burst BUDDY MESSAGE")))))

(add-command! /burst "/burst"
Expand All @@ -83,7 +85,9 @@
(define (/greet args)
"IRC style greeting command"
(if (> (string-length args) 0)
(ft-send-message args
(ft-send-message (string-trim-right
(string-trim-right args #\space)
#\:)
(burst (car (string-split args #\@))
min-chars max-chars))
(ft-display (_ "usage: /greet BUDDY"))))
Expand Down
3 changes: 2 additions & 1 deletion extensions/history.scm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
(system (string-append history-page-cmd session-file))
; (if (= (string-length args) 1)
(system (string-append history-page-cmd history-path "/"
(string-trim-right args #\:)))))
(string-trim-right (string-trim-right
args #\space) #\:)))))

(add-command! /history "/history" "/history [BUDDY]"
"Display history page by page")
Expand Down
2 changes: 1 addition & 1 deletion extensions/pipe.scm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
(buddy (car args-list))
(cmd (cadr args-list)))
(if (> (string-length cmd) 0)
(send-message-pipe buddy cmd)
(send-message-pipe (string-trim-right buddy #\:) cmd)
(ft-display (_ "usage: /pipe BUDDY COMMAND [OPTIONS]")))))

(add-command! /pipe "/pipe"
Expand Down
22 changes: 14 additions & 8 deletions extensions/roster.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.

(define (/add args)
(define (/add args)
(if (= (string-length args) 0)
(ft-display (_ "Incomplete syntax"))
(begin
(ft-add-buddy! (sans-surrounding-whitespace args))
(ft-subscription-allow (sans-surrounding-whitespace args)))))
(ft-add-buddy! (string-trim-right (sans-surrounding-whitespace
args) #\:))
(ft-subscription-allow (string-trim-right (sans-surrounding-whitespace
args) #\:)))))

(add-command! /add "/add" "/add [USER@SERVER]" "add new buddy to list")

(define (/remove args)
(if (= (string-length args) 0)
(ft-display (_ "Incomplete syntax"))
(begin
(ft-remove-buddy! (sans-surrounding-whitespace args))
(ft-subscription-deny (sans-surrounding-whitespace args)))))
(ft-remove-buddy! (string-trim-right (sans-surrounding-whitespace
args) #\:))
(ft-subscription-deny (string-trim-right (sans-surrounding-whitespace
args) #\:)))))

(add-command! /remove "/remove" "/remove [USER@SERVER]"
"remove buddy from list")
Expand Down Expand Up @@ -80,21 +84,23 @@
(define (/allow args)
(if (= (string-length args) 0)
(ft-display (_ "Incomplete syntax"))
(ft-subscription-allow (sans-surrounding-whitespace args))))
(ft-subscription-allow (string-trim-right (sans-surrounding-whitespace
args) #\:))))

(add-command! /allow "/allow" "/allow [USER@SERVER]" "Allow buddy to see your status")

(define (/deny args)
(if (= (string-length args) 0)
(ft-display (_ "Incomplete syntax"))
(ft-subscription-deny (sans-surrounding-whitespace args))))
(ft-subscription-deny (string-trim-right (sans-surrounding-whitespace
args) #\:))))
(add-command! /deny "/deny" "/deny [USER@SERVER]" "Deny buddy permission to see your status")

(define (/alias args)
(if (= (string-length args) 0)
(ft-display (_ "Incomplete syntax"))
(apply ft-roster-set-nickname (map sans-surrounding-whitespace
(string-separate args #\Space)))))
(string-separate args #\space)))))
(add-command! /alias "/alias" "/alias buddy nickname" "Set the nickname of a buddy")

(define (subscribe-recv jid)
Expand Down
20 changes: 10 additions & 10 deletions extensions/smart-prompt.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
(let ((item '()) (nick "") (ret ""))
(if (not (string-null? jid))
(begin
(set! item (ft-roster-lookup jid))
(if (not (null? item))
(begin
(set! nick (list-ref item 2))
(if (not (null? nick))
(set! ret nick))))))
(set! item (ft-roster-lookup jid))
(if (not (null? item))
(begin
(set! nick (list-ref item 2))
(if (not (null? nick))
(set! ret nick))))))
ret))

(define (update-prompt)
Expand All @@ -50,8 +50,8 @@
(set! current-buddy (ft-get-current-buddy))
(set! nickname (jid-to-nick current-buddy))
(set! prompt-jid (cond ((not (string-null? nickname)) nickname)
((not (string-null? current-buddy)) current-buddy)
(else (ft-get-jid))))
((not (string-null? current-buddy)) current-buddy)
(else (ft-get-jid))))
(if (equal? mute-flag "yes")
(begin
(set! waiting-users-count (hash-count-wrap msgs-htable))
Expand Down Expand Up @@ -159,11 +159,11 @@
(_ " Offline"))
(if (> (string-length show-msg) 0)
(string-append " ["
(pretty-print-show-msg show-msg) "]")
(pretty-print-show-msg
show-msg) "]")
"")
(if (> (string-length status-msg) 0)
(string-append " (" status-msg ")")
"")))))))))

(add-hook! ft-presence-receive-hook presence-recv)

4 changes: 3 additions & 1 deletion extensions/url.scm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
(if (= (string-length args) 0)
(system (string-append urlview-cmd url-session-file))
; (if (= (string-length args) 1)
(system (string-append urlview-cmd url-history-path "/" args))))
(system (string-append urlview-cmd url-history-path "/"
(string-trim-right (string-trim-right
args #\space) #\:)))))

(add-command! /urlview "/urlview" "/urlview [BUDDY]" "handle URLs")
4 changes: 4 additions & 0 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ auto_complete (const char *text, int _state)
"^ */remove +[^ ]*$",
"^ */urlview +[^ ]*$",
"^ */alias +[^ ]*$",
"^ */greet +[^ ]*$",
"^ */deny +[^ ]*$",
"^ */burst +[^ ]*$",
"^ */burst-of-romance +[^ ]*$",
NULL
};

Expand Down

0 comments on commit 21d6d83

Please sign in to comment.