Added feature for users to mute/unmute the bot. Externized the parameters
This commit is contained in:
parent
ccb689744b
commit
5b901e51a9
@ -3,8 +3,6 @@
|
|||||||
:dependencies [[org.clojure/clojure "1.2.0"]
|
:dependencies [[org.clojure/clojure "1.2.0"]
|
||||||
[org.clojure/clojure-contrib "1.2.0"]
|
[org.clojure/clojure-contrib "1.2.0"]
|
||||||
[pircbot/pircbot "1.5.0"]]
|
[pircbot/pircbot "1.5.0"]]
|
||||||
;:aot [marvin.core]
|
:dev-dependencies [[lein-javac "1.2.1-SNAPSHOT"]]
|
||||||
:dev-dependencies [[lein-javac "1.2.1-SNAPSHOT"]
|
|
||||||
[swank-clojure "1.2.1"]]
|
|
||||||
:java-source-path [["src"]]
|
:java-source-path [["src"]]
|
||||||
:main marvin.core)
|
:main marvin.core)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
(ns marvin.core
|
(ns marvin.core
|
||||||
(:import [java.text BreakIterator]
|
(:import [java.text BreakIterator]
|
||||||
|
[java.util.regex Pattern]
|
||||||
[java.io File]
|
[java.io File]
|
||||||
[marvin Bot])
|
[marvin Bot])
|
||||||
(:use [clojure.string :only (lower-case, join, trim)]
|
(:use [clojure.string :only (lower-case, join, trim)]
|
||||||
@ -8,7 +9,7 @@
|
|||||||
[clojure.contrib.io :only (pwd, write-lines)])
|
[clojure.contrib.io :only (pwd, write-lines)])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(defn log [o] (do (println o) o))
|
(defn parse-int [s] (Integer/parseInt s))
|
||||||
|
|
||||||
(defn tokenize-line [line]
|
(defn tokenize-line [line]
|
||||||
(let [non-char-pattern (re-pattern "[\\p{Z}\\p{C}\\p{P}]+")
|
(let [non-char-pattern (re-pattern "[\\p{Z}\\p{C}\\p{P}]+")
|
||||||
@ -146,6 +147,12 @@
|
|||||||
(defn send-message [bot channel message]
|
(defn send-message [bot channel message]
|
||||||
(.sendMessage bot channel message))
|
(.sendMessage bot channel message))
|
||||||
|
|
||||||
|
(defn send-action [bot channel action]
|
||||||
|
(.sendAction bot channel action))
|
||||||
|
|
||||||
|
(defn change-nick [bot nick]
|
||||||
|
(.changeNick bot nick))
|
||||||
|
|
||||||
(defn make-bot
|
(defn make-bot
|
||||||
[bot-name
|
[bot-name
|
||||||
on-message-callback
|
on-message-callback
|
||||||
@ -177,9 +184,10 @@
|
|||||||
speak-interval
|
speak-interval
|
||||||
min-sentence-length
|
min-sentence-length
|
||||||
max-sentence-length]
|
max-sentence-length]
|
||||||
(let [msg-count (atom 0)]
|
(let [msg-count (atom 0)
|
||||||
|
bot-talking? (atom true)]
|
||||||
(fn [bot channel sender login hostname message]
|
(fn [bot channel sender login hostname message]
|
||||||
(let [speak-about-pattern (re-pattern (str "speak about (.*) " (.getName bot)))
|
(let [speak-about-pattern (re-pattern (str "speak about (.*) " (Pattern/quote (.getNick bot))))
|
||||||
message (trim message)
|
message (trim message)
|
||||||
create-statement-and-send
|
create-statement-and-send
|
||||||
(fn
|
(fn
|
||||||
@ -207,7 +215,17 @@
|
|||||||
(try
|
(try
|
||||||
(swap! msg-count inc)
|
(swap! msg-count inc)
|
||||||
(cond
|
(cond
|
||||||
(= message (str "speak " (.getName bot)))
|
(= message (str "shutup " (.getNick bot)))
|
||||||
|
(do (println "Shutting up")
|
||||||
|
(reset! bot-talking? false)
|
||||||
|
(send-action bot channel "shuts up")
|
||||||
|
(change-nick bot (str (.getName bot) "|muted")))
|
||||||
|
(= message (str "talk " (.getNick bot)))
|
||||||
|
(do (println "Talking")
|
||||||
|
(reset! bot-talking? true)
|
||||||
|
(send-action bot channel "can talk now")
|
||||||
|
(change-nick bot (.getName bot)))
|
||||||
|
(= message (str "speak " (.getNick bot)))
|
||||||
(do (println "Replying to speak command:" message)
|
(do (println "Replying to speak command:" message)
|
||||||
(create-statement-and-send))
|
(create-statement-and-send))
|
||||||
(not (nil? (re-matches speak-about-pattern message)))
|
(not (nil? (re-matches speak-about-pattern message)))
|
||||||
@ -234,7 +252,9 @@
|
|||||||
line-list-atom
|
line-list-atom
|
||||||
key-size
|
key-size
|
||||||
history-size)
|
history-size)
|
||||||
(when (<= (rand) (/ 1 speak-interval))
|
(when (and
|
||||||
|
@bot-talking?
|
||||||
|
(<= (rand) (/ 1 speak-interval)))
|
||||||
(create-statement-and-send)))))
|
(create-statement-and-send)))))
|
||||||
(when (zero? (mod @msg-count save-interval))
|
(when (zero? (mod @msg-count save-interval))
|
||||||
(println "Saving memory")
|
(println "Saving memory")
|
||||||
@ -293,10 +313,27 @@
|
|||||||
(.connect server)
|
(.connect server)
|
||||||
(.joinChannel channel))))
|
(.joinChannel channel))))
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main
|
||||||
(run-bot "A4E.Immortal-Anime.net" "#animestan" "marvin" 1 500 50 10 6 15))
|
[& [server
|
||||||
|
channel
|
||||||
|
bot-name
|
||||||
|
key-size
|
||||||
|
history-size
|
||||||
|
save-interval
|
||||||
|
speak-interval
|
||||||
|
min-sentence-length
|
||||||
|
max-sentence-length]]
|
||||||
|
(run-bot
|
||||||
|
server
|
||||||
|
channel
|
||||||
|
bot-name
|
||||||
|
(parse-int key-size)
|
||||||
|
(parse-int history-size)
|
||||||
|
(parse-int save-interval)
|
||||||
|
(parse-int speak-interval)
|
||||||
|
(parse-int min-sentence-length)
|
||||||
|
(parse-int max-sentence-length)))
|
||||||
|
|
||||||
;;filter out links
|
;;filter out links
|
||||||
;;switch to pircbotx
|
;;switch to pircbotx
|
||||||
;;pronoun substitution
|
;;pronoun substitution
|
||||||
;;externalize parameters
|
|
||||||
|
Loading…
Reference in New Issue
Block a user