2022-02-19 23:32:43 +01:00
|
|
|
;; SPDX-License-Identifier: Apache-2.0
|
|
|
|
;; SPDX-FileCopyrightText: 2022 Sebastian Crane <seabass-labrax@gmx.com>
|
|
|
|
|
|
|
|
(ns irc
|
2022-02-27 22:52:07 +01:00
|
|
|
(:require [clojure.string :as str]
|
|
|
|
[bot :refer :all]
|
2022-02-19 23:32:43 +01:00
|
|
|
[irclj.core]))
|
|
|
|
|
|
|
|
(defn irc-callback [state config connection type & m]
|
|
|
|
(let [{:keys [channel]} (:irc config)
|
|
|
|
{:keys [nick text target]} type]
|
2022-02-28 22:09:05 +01:00
|
|
|
(some->> (dispatch-command state nick text)
|
|
|
|
(str/split-lines)
|
|
|
|
(run! (partial irclj.core/message connection channel)))))
|
2022-02-19 23:32:43 +01:00
|
|
|
|
|
|
|
(defn new-irc-connection [state config]
|
|
|
|
(let [{:keys [server port name nick channel]} (:irc config)]
|
|
|
|
(try
|
|
|
|
(irclj.core/connect server
|
|
|
|
port
|
|
|
|
nick
|
2022-02-28 17:29:35 +01:00
|
|
|
:real-name (or name nick)
|
2022-02-19 23:32:43 +01:00
|
|
|
:callbacks {:privmsg (partial irc-callback state config)})
|
|
|
|
(catch Exception e nil))))
|