Browse Source

Okay the last commit was a *huge* mistake

master
eta 3 years ago
parent
commit
91aa515361
  1. 9
      binproto.lisp
  2. 2
      message.lisp
  3. 11
      whatscl.lisp

9
binproto.lisp

@ -88,6 +88,15 @@ @@ -88,6 +88,15 @@
(let ((hostname (if (equal hostname "s.whatsapp.net") "c.us" hostname)))
(concatenate 'string localpart "@" hostname))))
(defun jid-to-message-target (jid)
"Convert JID to a string, for use in making a message target."
(with-slots (localpart hostname) jid
;; Here's a funny story: having an invalid JID hostname here sends
;; WhatsApp into a crash loop (!), requiring a reinstall.
;; 4 reinstalls later and I figured out the bug...
(let ((hostname (if (equal hostname "g.us") "g.us" "s.whatsapp.net")))
(concatenate 'string localpart "@" hostname))))
(defun nibble-to-denary-char (nib)
"Converts NIB, a nibble, into a character representing that value in denary (with some punctuation exceptions as well)."
(declare (type (integer 0 16) nib))

2
message.lisp

@ -391,7 +391,7 @@ Returns the message object as first value, and its ID as second." @@ -391,7 +391,7 @@ Returns the message object as first value, and its ID as second."
(key (make-instance 'wpb:message-key))
(contents (make-instance 'wpb:message))
(ret (make-instance 'wpb:web-message-info)))
(setf (wpb:remote-jid key) (pb:string-field (jid-to-string to-jid)))
(setf (wpb:remote-jid key) (pb:string-field (jid-to-message-target to-jid)))
(setf (wpb:from-me key) t)
(setf (wpb:id key) (pb:string-field id))
(setf (wpb:key ret) key)

11
whatscl.lisp

@ -136,12 +136,6 @@ CALLBACK, if provided, specifies a function to run with the reply sent by WhatsA @@ -136,12 +136,6 @@ CALLBACK, if provided, specifies a function to run with the reply sent by WhatsA
(defun send-simple-text-message (conn to-jid text &optional callback)
"Send a simple text message to the JID TO-JID, containing TEXT. Returns the message's ID. The CALLBACK will be called with CONN as first argument and the server's response: an alist, which should on success contain the key :STATUS with value 200."
(declare (type jid to-jid) (type string text))
(let ((hn (jid-hostname to-jid)))
;; Here's a funny story: having an invalid JID hostname here sends
;; WhatsApp into a crash loop (!), requiring a reinstall.
;; 4 reinstalls later and I figured out the bug...
(unless (or (equal hn "s.whatsapp.net") (equal hn "g.us"))
(error "Invalid JID hostname ~A" hn)))
(multiple-value-bind (msg msgid)
(make-simple-text-message to-jid text)
(send-ws-node-message conn `(:action ((:type . :relay)) ((:message () ,(encode-message msg)))) :message
@ -169,10 +163,13 @@ CALLBACK, if provided, specifies a function to run with the reply sent by WhatsA @@ -169,10 +163,13 @@ CALLBACK, if provided, specifies a function to run with the reply sent by WhatsA
(funcall callback conn (when result
(cassoc :eurl result))))))
(defun replace-surrogates (str)
(substitute-if #\uFFFD (lambda (ch) (<= #xD800 (char-code ch) #xDFFF)) str))
(defun fix-cl-json-string (string)
"Fixes the STRING returned by CL-JSON, properly decoding any UTF-16 surrogate pairs instead of passing them through as invalid characters.
FIXME: We should ideally just use a better JSON library..."
(map 'string #'code-char (whatscl/utf16-hacks::decode-utf-16 (map 'vector #'char-code string))))
(replace-surrogates (map 'string #'code-char (whatscl/utf16-hacks::decode-utf-16 (map 'vector #'char-code string)))))
(defun get-profile-status (conn jid callback)
"Try and get the status text set by JID. Calls CALLBACK with CONN as first argument and then the status text (or NIL if none could be found)"

Loading…
Cancel
Save