This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhygdrop.hy
58 lines (51 loc) · 1.91 KB
/
hygdrop.hy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(import os
irc.bot
[hy.importer [import_file_to_module]]
[docopt [docopt]])
(def *plugins* [])
(def *usage* "Hygdrop - Hy IRC bot
Usage:
hygdrop.hy
hygdrop.hy [--server=<server>] [--channel=<channel>] [--port=<portnum>] [--nick=<nick>]
hygdrop.hy [-h | --help]
hygdrop.hy [-v | --version]
hygdrop.hy [--dry-run]
Options:
-h --help Show this help screen
-v --version Show version
--server=<server:port> Servers to connect
--channel=<channel>,<channel> Channel to join
--port=<portnumber> Port number to connect to IRC server
--nick=<nickname> Nick the bot should use")
(def *arguments* (apply docopt [*usage*] {"version" "Hygdrop 0.1"}))
(defun welcome-handler [connection event]
(for [(, dir subdir files) (os.walk (-> (os.path.dirname
(os.path.realpath __file__))
(os.path.join "plugins")))]
(for [file files]
(if (.endswith file ".hy")
(.append *plugins* (import_file_to_module (get (.split file ".") 0)
(os.path.join dir file))))))
(if (get *arguments* "--channel")
(for [channel (.split (get *arguments* "--channel") ",")]
(.join connection channel))
(.join connection "#hy")))
(defun pubmsg-handler [connection event]
(let [[arg (get event.arguments 0)]]
(for [plugin *plugins*]
(.process plugin connection event arg))))
(defun start[]
(let [[server (fn[] (if (get *arguments* "--server")
(get *arguments* "--server") "irc.freenode.net"))]
[port (fn[] (if (get *arguments* "--port")
(get *arguments* "--port") 6667))]
[nick (fn[] (if (get *arguments* "--nick")
(get *arguments* "--nick") "hygdrop"))]
[bot
(irc.bot.SingleServerIRCBot [(, (server) (port))]
(nick) "Hy five!")]]
(.add_global_handler bot.connection "welcome" welcome-handler)
(.add_global_handler bot.connection "pubmsg" pubmsg-handler)
(.start bot)))
(if (= __name__ "__main__")
(start))