|
1 | 1 | (ns lazybot.irc
|
2 |
| - (:require [lazybot.core :as core] |
| 2 | + (:require [lazybot.core :as lazybot] |
3 | 3 | [lazybot.info :as info]
|
4 | 4 | [useful.fn :refer [decorate]]
|
5 | 5 | [useful.map :refer [keyed]]
|
6 | 6 | [irclj.core :as ircb]))
|
7 | 7 |
|
| 8 | +(defn make-hook |
| 9 | + [actions] |
| 10 | + (fn [& args] |
| 11 | + (when-not (empty? @actions) |
| 12 | + (doseq [action @actions] |
| 13 | + (apply action args))))) |
| 14 | + |
8 | 15 | (defn base-maps
|
9 | 16 | "Create the base callback and bot maps."
|
10 | 17 | [config]
|
11 |
| - (let [refzors (ref {:modules {:internal {:hooks core/initial-hooks}} |
| 18 | + (let [refzors (ref {:modules {:internal {:hooks lazybot/initial-hooks}} |
12 | 19 | :config config
|
13 | 20 | :pending-ops 0})]
|
14 | 21 | [(into {}
|
15 | 22 | (map
|
16 | 23 | (decorate
|
17 |
| - #(fn [irc-map] |
18 |
| - (core/call-all (-> irc-map |
19 |
| - (assoc :bot refzors :com (:irc irc-map)) |
20 |
| - (dissoc :irc)) |
21 |
| - %))) |
22 |
| - [:on-any :on-message :on-quit :on-join])) |
| 24 | + #(fn dispatch-hooks [irc-map event] |
| 25 | + (dosync (alter irc-map assoc :server (:network @irc-map))) |
| 26 | + (lazybot/call-all (-> @irc-map |
| 27 | + (assoc :bot refzors :com irc-map) |
| 28 | + (dissoc :irc) |
| 29 | + (assoc :event event) |
| 30 | + (assoc :bot-nick (:nick @irc-map)) |
| 31 | + (assoc :nick (:nick event)) |
| 32 | + (assoc :message (:text event)) |
| 33 | + (assoc :channel ((:params event) 0))) |
| 34 | + %))) |
| 35 | + [:001 :privmsg :quit :join])) |
23 | 36 | refzors]))
|
24 | 37 |
|
25 |
| -(defn make-bot-run |
26 |
| - "Create an irclj param map to pass to connect." |
27 |
| - [name password server fnmap] |
28 |
| - (ircb/create-irc (keyed [name password server fnmap]))) |
29 |
| - |
30 | 38 | (defn make-bot
|
31 | 39 | "Creates a new bot and connects it."
|
32 | 40 | [server]
|
33 | 41 | (let [bot-config (info/read-config)
|
| 42 | + port 6667 |
34 | 43 | [name pass channels] ((juxt :bot-name :bot-password :channels)
|
35 |
| - (bot-config server)) |
| 44 | + (bot-config server)) |
36 | 45 | [fnmap refzors] (base-maps bot-config)
|
37 |
| - irc (ircb/connect (make-bot-run name pass server fnmap) |
38 |
| - :channels channels, :identify-after-secs 3)] |
| 46 | + irc (ircb/connect server port name |
| 47 | + :callbacks fnmap |
| 48 | + :identify-after-secs 3)] |
39 | 49 | [irc refzors]))
|
40 | 50 |
|
41 | 51 | (defn init-bot
|
42 | 52 | "Initialize a new bot."
|
43 | 53 | [server]
|
44 | 54 | (let [[irc refzors] (make-bot server)]
|
45 |
| - (swap! core/bots assoc server {:com irc :bot refzors}) |
46 |
| - (dosync (core/reload-config refzors)) |
47 |
| - (core/load-plugins irc refzors))) |
| 55 | + (swap! lazybot/bots assoc server {:com irc :bot refzors}) |
| 56 | + (dosync (lazybot/reload-config refzors)) |
| 57 | + (lazybot/load-plugins irc refzors))) |
48 | 58 |
|
49 | 59 | (defn start-bots
|
50 | 60 | "Starts bots for servers."
|
51 | 61 | [servers]
|
52 | 62 | (doseq [serv servers]
|
53 | 63 | (init-bot serv))
|
54 |
| - (core/route (core/extract-routes (vals @core/bots)))) |
| 64 | + (lazybot/route (lazybot/extract-routes (vals @lazybot/bots)))) |
0 commit comments