Skip to content

Commit

Permalink
Gracefully handle not getting a avatar from discord (Because there is…
Browse files Browse the repository at this point in the history
…nt one set)
  • Loading branch information
plexus committed Aug 26, 2024
1 parent 8ed3185 commit e628416
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/co/gaiwan/compass/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
name-or-email
)))

(defn unassign-ticket [user]
@(db/transact [[:db/retract (:db/id (u/assigned-ticket user)) :tito.ticket/assigned-to (:db/id user)]]))

(comment
(into {}
(:tito.ticket/release
Expand Down
34 changes: 19 additions & 15 deletions src/co/gaiwan/compass/routes/oauth.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,25 @@
{:keys [access_token refresh_token expires_in] :as body}
{:keys [id email global_name] :as user-info}]
#_(def user-info user-info)
(let [discord-avatar-url (str "https://cdn.discordapp.com/avatars/" id "/" (:avatar user-info) ".png")
avatar-url (try
(user/download-avatar discord-avatar-url)
(catch Exception e
(log/warn :discord/avatar-download-failed {:url discord-avatar-url}
:exception e)
discord-avatar-url))]
[{:user/uuid user-uuid
:public-profile/name global_name
:public-profile/avatar-url avatar-url
:discord/id id
:discord/email email
:discord/access-token access_token
:discord/refresh-token refresh_token
:discord/expires-at (util/expires-in->instant expires_in)}]))
(let [avatar-id (:avatar user-info)
discord-avatar-url (when-not (str/blank? avatar-id)
(str "https://cdn.discordapp.com/avatars/" id "/" avatar-id ".png"))
avatar-url (when discord-avatar-url
(try
(user/download-avatar discord-avatar-url)
(catch Exception e
(log/warn :discord/avatar-download-failed {:url discord-avatar-url}
:exception e)
discord-avatar-url)))]
[(cond-> {:user/uuid user-uuid
:public-profile/name global_name
:discord/id id
:discord/email email
:discord/access-token access_token
:discord/refresh-token refresh_token
:discord/expires-at (util/expires-in->instant expires_in)}
avatar-url
(assoc :public-profile/avatar-url avatar-url))]))

(defn GET-discord-callback [{:keys [query-params session]}]
(let [{:strs [code state]} query-params
Expand Down

0 comments on commit e628416

Please sign in to comment.