From 2e882774011f2c8669b4b3ee1473ef6c11e20dc1 Mon Sep 17 00:00:00 2001 From: niten Date: Sat, 23 Mar 2024 11:21:50 -0700 Subject: [PATCH] Updates --- flake.nix | 2 +- src/bebot/client.clj | 78 ++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/flake.nix b/flake.nix index abc57c7..a75972c 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ default = updateDeps; updateDeps = pkgs.mkShell { buildInputs = with helpers.packages."${system}"; - [ updateClojureDeps ]; + [ (updateClojureDeps { }) ]; }; }; }); diff --git a/src/bebot/client.clj b/src/bebot/client.clj index 444a743..f25eb02 100644 --- a/src/bebot/client.clj +++ b/src/bebot/client.clj @@ -2,7 +2,7 @@ (:require [bebot.model :refer [id user-id new-post to-model mentions-user? channel-last-view from-model created-at]] [bebot.api.client :as client] [bebot.api.channel :as chan] - [fudo-clojure.result :refer [let-result exception-failure success failure map-success dispatch-result]] + [fudo-clojure.result :as res :refer [let-result exception-failure success failure map-success dispatch-result unwrap]] [clojure.core.async :as async :refer [go-loop chan timeout >! ! out-chan (success o)))) - ([e] (>! out-chan (exception-failure e)))) + (go-loop [os (coll-gen)] + (doseq [o (sort-by-create-date os)] + (>! out-chan o)) (> (client/get-posts-since! client (id channel) instant) + (remove-posts-by me))) (get-new-mentions! [self] - (map-success (chan/get-new-posts! self) - (partial filter (mentions-user? me)))) + (->> self + (chan/get-new-posts!) + (filter (mentions-user? me)))) (peek-new-mentions! [self] - (map-success (chan/peek-new-posts! self) - (partial filter (mentions-user? me)))) + (->> self + (chan/peek-new-posts!) + (filter (mentions-user? me)))) (get-mentions-since! [self instant] - (map-success (chan/get-posts-since! self instant) - (partial filter (mentions-user? me)))) + (->> self + (chan/get-posts-since! instant) + (filter (mentions-user? me)))) (post-channel! [self] (yield-to-channel (fn [] (chan/get-new-posts! self)) :poll-delay 5)) @@ -105,21 +103,21 @@ (to-result (.getUserByUsername client username nil))) (open-channel! [self chan-id] - (let-result [chan (client/get-channel! self chan-id) - read-instant (client/mark-read! self chan-id)] - (success (->BebotChannel self chan (atom read-instant) me)))) + (let [chan (client/get-channel! self chan-id) + read-instant (client/mark-read! self chan-id)] + (->BebotChannel self chan (atom read-instant) me))) (open-direct-channel! [self user-id] - (let-result [chan (to-result (.createDirectChannel client (id me) user-id))] - (success (client/open-channel! self (id chan))))) + (let [chan (to-result (.createDirectChannel client (id me) user-id))] + (client/open-channel! self (id chan)))) (mark-read! [_ chan-id] - (let [chan-view (ChannelView. chan-id)] - (let-result [views (to-result (.viewChannel client (id me) chan-view))] - (if-let [view-time (channel-last-view views chan-id)] - (success view-time) - (failure (str "unable to mark read, not found: " chan-id) - {:channel-views views}))))) + (let [chan-view (ChannelView. chan-id) + views (to-result (.viewChannel client (id me) chan-view))] + (if-let [view-time (channel-last-view views chan-id)] + view-time + (throw (ex-info (str "unable to mark read, not found: " chan-id) + {:channel-views views}))))) (get-post! [_ post-id] (to-result (.getPost client post-id nil))) @@ -135,11 +133,13 @@ (get-me! [_] (to-result (.getMe client nil))) (initialize! [self] - (map-success (client/get-me! self) (fn [me] (->BebotClient client me))))) + (->> self + (client/get-me!) + (->BebotClient client)))) (defn create-connection [url access-token] (->BebotClientStub (doto (MattermostClient. url) (.setAccessToken access-token)))) (defn connect [url access-token] - (client/initialize! (create-connection url access-token))) + (client/initialize! (create-connection url access-token)))