-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rkt
61 lines (52 loc) · 1.87 KB
/
main.rkt
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
59
60
61
#lang racket
(require racket/cmdline
"config.rkt"
"chat/event/message-event.rkt"
"chat/bot.rkt"
"chat/message/main.rkt"
"eval-service/main.rkt"
"func-lib/message-handler.rkt"
"func-lib/login-handler.rkt"
"nlp/dict.rkt")
(define verbose-mode (make-parameter #f))
(define debug-mode (make-parameter #f))
(command-line #:once-each
[("-v" "--verbose")
"日志"
(verbose-mode #t)]
[("-d" "--debug")
"调试日志"
(debug-mode #t)])
(displayln "Started")
(define bot (new bot%
[id bot-id]
[nickname bot-nickname]
[server-config mirai-ws-server-config]
[verbose (verbose-mode)]
[client-debug (debug-mode)]))
(send bot subscribe-message-event
(λ (event)
(define subject (send event get-subject))
(define mcb (new message-chain-builder%))
(define sent? #f)
(define add-message (create-add-message
mcb
(λ (_) (cond
[sent? (error) #f]
[else #t]))))
(define message (send event get-message))
(when (non-empty-string? (send message content-to-string))
(define handled (handle-eval-service-message event add-message))
(when (not handled)
(set! handled (handle-message bot event add-message)))
(when handled
(define mc (send mcb build))
(when (not (send mc empty?))
(send subject send-message (send mc trim))))
(set! sent? #t))))
(displayln "连接中...")
(send bot login
(λ ()
(displayln "已连接到服务器:)")
(handle-login bot)
(dict-add-word bot-nickname)))