Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar-local base-url "https://discordapp.com/api/v6")
- (defvar token "mfa.vUSb8-RKwu9yJ5SgbkbcB-ftH4T6qI5wu7dSdvDTCb3ZCAg5eYn16kLvylVyhGSHMViVDKxwyosamhzfhGEn")
- (defvar-local user-agent "emacs")
- (defun get-discord-ws-gateway ()
- "Gets discord's websocket gateway"
- (let* (
- (url-request-method "GET")
- (url-request-extra-headers `(("User-Agent" . ,user-agent)))
- )
- (url-retrieve )
- )
- )
- (defun login-with-token (token)
- "Login using a defined token"
- (interactive)
- (setq url-request-method "GET")
- (setq url-request-extra-headers `(("User-Agent" . ,user-agent)
- ("Authorization" . ,token)))
- (url-retrieve "https://discordapp.com/api/v6/users/@me" 'handle-http-request `((handle-login)(,token)))
- )
- ;IchI1HjgKwG5JFj%93tb
- (defun login-with-email-passwd (email passwd)
- "Login using an email/password set(No 2FA)"
- (interactive "sUsername: \nsPassword: ")
- (let* ((url-request-method "POST")
- (url-request-extra-headers '(("Content-Type" . "application/json")))
- (url-request-data (json-encode-list `(("email" . ,email) ("password" . ,passwd))))
- )
- (url-retrieve "https://discordapp.com/api/v6/auth/login" 'handle-http-request '((get-token)(nil)))
- )
- )
- (defun handle-login (list-of-string token)
- "Check if we logged in successfully using a token"
- (let* ((json-key-type 'string)
- (json-object-type 'hash-table)
- (st (car (car list-of-string)))
- (json (json-read-from-string st)))
- (if (eq (gethash "id" json) json-null)
- (progn (message "Error! Couldn't confirm ID. Try again."))
- (progn
- (setq discord-token token)
- (setq discord-id (gethash "id" json))
- (setq discord-discriminator (gethash "discriminator" json))
- (setq discord-email (gethash "email" json))
- (setq discord-username (gethash "username" json))
- (message
- (concat "Success! Username: " discord-username "#" discord-discriminator)
- )
- )
- )
- )
- )
- (defun get-token (list-of-string &rest spare)
- "Get the user token from an email/passwd login"
- (let* ((json-key-type 'string)
- (json-object-type 'hash-table)
- (st (car (car list-of-string)))
- (json (json-read-from-string st))
- )
- (if (and (gethash "mfa" json) (eq (gethash "token" json) json-null))
- (progn (message "Error! 2FA required. Please log in directly with a token."))
- (progn (if (eq gethash "token" json) json-null)
- (message "Error! Couldn't get token")
- (progn (message "Success! Attempting to log in via token")
- (login-with-token (gethash "token" json))))
- ))
- )
- (defun get-bad-request-reason (list-of-string)
- (let* ((json-key-type 'string)
- (json-object-type 'alist)
- (st (car (car list-of-string)))
- (json (json-read-from-string st))
- )
- (message (concat "Reason: " (aref (cdr (car (last json) ) )0)))
- )
- )
- (defun handle-http-request (status f args)
- "Switch to the buffer returned by `url-retreive'.
- The buffer contains the raw HTTP response sent by the server."
- (forward-word 4)
- (setq return-code (string-to-number (word-at-point)))
- (goto-char (+ 1 url-http-end-of-headers))
- (let* ((response (thing-at-point 'line t)))
- (cond
- ((= return-code 400)
- (message "Bad request")
- (get-bad-request-reason `((,response)))
- )
- ((= return-code 201)
- (message "Bad auth"))
- ((and (< return-code 300) (> return-code 199))
- (apply (car f) `((,response)) args)
- )
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement