Skip to content

Commit

Permalink
correctly recognize friendliness based on destination
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigory Romodanovskiy committed Apr 30, 2018
1 parent 336832c commit b719c81
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.red/ares "0.3.0-SNAPSHOT"
(defproject org.red/ares "0.3.1-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "MIT"
Expand All @@ -11,6 +11,6 @@
[org.clojure/core.async "0.4.474"]
[mount "0.1.12"]
[org.clojure/tools.cli "0.3.6"]]
:main ^:skip-aot killbot.core
:main ^:skip-aot org.red.ares.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
10 changes: 5 additions & 5 deletions src/org/red/ares/discord.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(defn- generate-image-by-id [id] (str (:img-eve-baseurl discord-vars) "/type/" id "_64.png"))


(defn generate-embed [km-package]
(defn generate-embed [km-package friendly]
(let [names (:names km-package)
victim (get-in km-package [:killmail :victim])
solar-system-id (get-in km-package [:killmail :solar_system_id])
Expand All @@ -77,7 +77,7 @@
:url url
:thumbnail {:url thumbnail-url}
:timestamp timestamp
:color (if (:friendly km-package) (get-in discord-vars [:colors :red]) (get-in discord-vars [:colors :green]))
:color (if friendly (get-in discord-vars [:colors :red]) (get-in discord-vars [:colors :green]))
:fields (filter #(not (nil? %))
[(if (contains? victim :character_id)
{
Expand Down Expand Up @@ -133,15 +133,15 @@
(defn- process*! [dest km-package]
(try
(log/debug (str "Processing km package " (:killID km-package)))
(post-embed! dest (generate-embed km-package))
(let
[cur-friendly (get (:friendlies km-package) (get-in dest [:discord-wh :url]))]
(post-embed! dest (generate-embed km-package cur-friendly)))
(log/debug (str "Processed km package " (:killID km-package)))
(catch Exception e (payload-http-exception-handler e km-package (partial process*! dest) 1000))))


(defn- chan-process! [dest mailbox] (while true (process*! dest (<!! mailbox))))



(defn- pull-and-route! [mailbox channel-map]
(while true
(let
Expand Down
16 changes: 14 additions & 2 deletions src/org/red/ares/router.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@
(flatten (conj attackers-alliance-ids victim-alliance-id)))))))))


(defn friendly? [km-package destination]
(let [char-id (get-in km-package [:killmail :victim :character_id])
corp-id (get-in km-package [:killmail :victim :corporation_id])
alliance-id (get-in km-package [:killmail :victim :alliance_id])]
(not (nil?
(or (some #(= char-id %) (get-in destination [:relevant-entities :character-ids]))
(some #(= corp-id %) (get-in destination [:relevant-entities :corporation-ids]))
(some #(= alliance-id %) (get-in destination [:relevant-entities :alliance-ids])))))))


(defn- km-package-router [km-package]
(let
[destinations (filter #(relevant? km-package %) (:destinations config))]
[destinations (filter #(relevant? km-package %) (:destinations config))
friendly (into {}
(map #(hash-map (get-in % [:discord-wh :url]) (friendly? km-package %)) destinations))]
(when (not (empty? destinations))
(log/debug "Determined that package with id "
(:killID km-package)
" goes to destinations with names"
(map #(str " " (get-in % [:discord-wh :bot-name])) destinations))
(merge km-package {:destinations destinations}))))
(merge km-package {:destinations destinations} {:friendlies friendly}))))


(defn- km-package-router-transducer [xf]
Expand Down
13 changes: 1 addition & 12 deletions src/org/red/ares/zkb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
:base-url "https://zkillboard.com/kill"})


(defn- friendly? [km-package]
(let [char-id (get-in km-package [:killmail :victim :character_id])
corp-id (get-in km-package [:killmail :victim :corporation_id])
alliance-id (get-in km-package [:killmail :victim :alliance_id])]
(not (nil?
(or (some #(= char-id %) (get-in config [:relevant-entities :character-ids]))
(some #(= corp-id %) (get-in config [:relevant-entities :corporation-ids]))
(some #(= alliance-id %) (get-in config [:relevant-entities :alliance-ids])))))))

(defn- enrich-friendly [km-package] (when (not (nil? km-package)) (merge km-package {:friendly (friendly? km-package)})))

(defn- poll* [] (:package (parse-string (:body (client/get (:redisq-url zkb-vars) {:accept :json})) true)))

(defn poll [_]
Expand All @@ -34,7 +23,7 @@

(defn- poll-and-push! [mailbox]
(while true
(let [km-package (enrich-friendly (poll nil))]
(let [km-package (poll nil)]
(when (not (nil? km-package))
(log/debug (str "Pushing payload to mailbox with killID " (:killID km-package)))
(>!! mailbox km-package)))))
Expand Down

0 comments on commit b719c81

Please sign in to comment.