Wokring on pagination of options to get around discord limit, #43

This commit is contained in:
Kiran Shila
2022-01-09 18:21:12 -08:00
parent f38204b45d
commit b4b15a4ce5
4 changed files with 21 additions and 6 deletions

View File

@@ -4,7 +4,8 @@
org.clojure/core.cache {:mvn/version "1.0.225"}
yogthos/config {:mvn/version "1.1.9"}
com.rpl/specter {:mvn/version "1.1.3"}
org.suskalo/discljord {:mvn/version "1.3.0"}
org.suskalo/discljord {:git/url "https://github.com/kiranshila/discljord"
:git/sha "b6e29d4b8f3e77462016a6b60af01357e1415345"}
org.clojure/core.async {:mvn/version "1.5.648"}
cheshire/cheshire {:mvn/version "5.10.1"}
fmnoise/flow {:mvn/version "4.1.0"}

View File

@@ -1,6 +1,6 @@
(ns doplarr.core
(:require
[taoensso.timbre :refer [info fatal debug]]
[taoensso.timbre :refer [info fatal debug] :as timbre]
[taoensso.timbre.tools.logging :as tlog]
[discljord.connections :as c]
[discljord.messaging :as m]
@@ -16,6 +16,9 @@
; Pipe tools.logging to timbre
(tlog/use-timbre)
#_(timbre/merge-config! {:min-level [[#{"discljord.messaging.*"} :trace]
[#{"*"} :debug]]})
; Multimethod for handling incoming Discord events
(defmulti handle-event!
(fn [event-type _]
@@ -71,4 +74,5 @@
(defn -main
[& _]
(config/validate-config)
(start-bot!)
(shutdown-agents))

View File

@@ -35,6 +35,8 @@
2 :button
3 :select-menu})
(def MAX-OPTIONS 25)
(def request-thumbnail
{:series "https://thetvdb.com/images/logo.png"
:movie "https://i.imgur.com/44ueTES.png"})
@@ -82,9 +84,17 @@
(map-indexed select-menu-option results))))
(defn option-dropdown [option options uuid]
(dropdown (str "Which " (utils/canonical-option-name option) "?")
(str "option-select:" uuid ":" (name option))
(map #(hash-map :label (:name %) :value (:id %)) options)))
(let [ddown (dropdown (str "Which " (utils/canonical-option-name option) "?")
(str "option-select:" uuid ":" (name option))
(take MAX-OPTIONS (map #(hash-map :label (:name %) :value (:id %)) options)))]
(if (> (count options) MAX-OPTIONS)
(update-in ddown [:components] conj {:type 1
:components [{:type 2
:style 1
:custom_id (str "option-page:" uuid ":")
:disabled false
:label "More Options"}]})
ddown)))
(defn dropdown-result [interaction]
(Integer/parseInt (s/select-one [:payload :values 0] interaction)))

View File

@@ -62,7 +62,7 @@
(let [{:keys [results media-type]} (get @state/cache uuid)
result (nth results (discord/dropdown-result interaction))
add-opts (log-on-error
(a/<! ((utils/media-fn media-type "additional-options") result))
(a/<! ((utils/media-fn media-type "additional-options") result media-type))
"Exception thrown from additional-options")
pending-opts (->> add-opts
(filter #(seq? (second %)))