Skip to content

Commit

Permalink
Fix truncate-message to really truncate to *irc-message-max-length*
Browse files Browse the repository at this point in the history
Also raise the max length to 480 bytes.
  • Loading branch information
tlikonen committed Jul 5, 2013
1 parent cde2264 commit fb8fe80
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions eval-bot.lisp
Expand Up @@ -60,7 +60,7 @@

(defvar *eval-prefix* ",")
(defvar *local-stream* *terminal-io*)
(defvar *irc-message-max-length* 400)
(defvar *irc-message-max-length* 480)

(defclass message ()
((timestamp :reader timestamp :initform (get-universal-time))))
Expand Down Expand Up @@ -104,12 +104,16 @@
year month date hour min sec)))

(defun truncate-message (string)
(if (> (or (ignore-errors (babel:string-size-in-octets string))
(length string))
*irc-message-max-length*)
(concatenate 'string (subseq string 0 (- *irc-message-max-length* 3))
"...")
string))
(if (<= (or (ignore-errors (babel:string-size-in-octets string))
(length string))
*irc-message-max-length*)
string
(loop :for i :from 1 :upto (length string)
:for lisp := (subseq string 0 i)
:if (> (or (ignore-errors (babel:string-size-in-octets lisp))
(length lisp))
*irc-message-max-length*)
:return (concatenate 'string (subseq string 0 (1- i)) "..."))))

(defgeneric send (context message))

Expand Down

0 comments on commit fb8fe80

Please sign in to comment.