-
-
Save brehaut/b929b62cec7d1b093935 to your computer and use it in GitHub Desktop.
A skeleton PircBot wrapper in Clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This code is influenced by https://github.com/hiredman/clojurebot/blob/master/src/hiredman/clojurebot/core.clj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns zbot.core | |
(:require [clojure.core.async :as async | |
:refer [chan <!! >!! <! >! go go-loop thread]]) | |
(import [org.jibble.pircbot PircBot])) | |
(defn ircbot | |
"Instantiates a new bot object and an events channel." | |
[settings] | |
(let [events (chan 20) | |
botobj | |
(proxy [PircBot] [] | |
(onConnect [] | |
(>!! events [:connect nil])) | |
(onJoin [channel sender login hostname] | |
(>!! events [:join channel])) | |
(onPart [channel sender login hostname] | |
(>!! events [:part channel])) | |
(onQuit [channel sender login hostname] | |
(>!! events [:quit channel])) | |
(onMessage [channel sender login hostname message] | |
(>!! events [:message channel sender message])) | |
(onPrivateMessage [sender login hostname message] | |
(>!! events [:message nil sender message])))] | |
(merge settings {:this botobj :events events}))) | |
(defn send-message | |
"sends a message via a bot" | |
[bot target message] | |
(.sendMessage (:this bot) target message)) | |
(defn send-notice | |
"sends a notice via a bot" | |
[bot target message] | |
(.sendNotice (:this bot) target message)) | |
(defn start-bot | |
[settings] | |
(let [bot (ircbot settings) | |
this (:this bot)] | |
(doto this | |
(.connect (:server bot)) | |
(.changeNick (:nick bot))) | |
(doseq [channel (:channels bot)] | |
(.joinChannel this channel)) | |
bot)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment