├── .gitignore ├── README.md ├── info.rkt ├── LICENSE.txt ├── reminderbot.rkt └── .travis.yml /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | .\#* 4 | .DS_Store 5 | compiled 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | reminderbot 2 | =========== 3 | 4 | A bot to send reminders. 5 | 6 | You'll need to install [Racket](https://racket-lang.org) to run it. 7 | 8 | Install with `raco package install` 9 | 10 | To run: `racket -t reminderbot.rkt` 11 | -------------------------------------------------------------------------------- /info.rkt: -------------------------------------------------------------------------------- 1 | #lang info 2 | (define collection "reminderbot") 3 | (define deps '("base" 4 | "https://github.com/braidchat/braidbot.git#v1.1" 5 | "tasks")) 6 | (define build-deps '("web-server-lib")) 7 | (define pkg-desc "Description Here") 8 | (define version "0.0") 9 | (define pkg-authors '(james)) 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | reminderbot 2 | Copyright (c) 2017 james 3 | 4 | This package is distributed under the GNU Lesser General Public 5 | License (LGPL). This means that you can link reminderbot into proprietary 6 | applications, provided you follow the rules stated in the LGPL. You 7 | can also modify this package; if you distribute a modified version, 8 | you must distribute it under the terms of the LGPL, which in 9 | particular means that you must release the source code for the 10 | modified software. See http://www.gnu.org/copyleft/lesser.html 11 | for more information. 12 | -------------------------------------------------------------------------------- /reminderbot.rkt: -------------------------------------------------------------------------------- 1 | #lang braidbot/insta 2 | 3 | (require racket/match 4 | racket/string 5 | tasks 6 | 7 | braidbot/util 8 | braidbot/uuid) 9 | 10 | (define bot-id (or (getenv "BOT_ID") "5a47c63e-8d23-4bba-92ef-53c3c0f7e398")) 11 | (define bot-token (or (getenv "BOT_TOKEN") "4S3EzYM-exfyBibpYxEggiX7ahcWrRh3AIKoKbms")) 12 | (define braid-url (or (getenv "BRAID_URL") "http://localhost:5557")) 13 | 14 | (listen-port 8899) 15 | 16 | (define reminder-re #rx"^/reminderbot (.*) in ([0-9]+) minutes?$") 17 | 18 | (on-init (λ () (println "Launching reminderbot"))) 19 | 20 | (define (parse-reminder str) 21 | (if-let [matches (regexp-match reminder-re str)] 22 | (let ([secs (-> matches caddr string->number (* 60))] 23 | [txt (cadr matches)]) 24 | (list secs txt)) 25 | #f)) 26 | 27 | (define (act-on-message msg) 28 | (->> (if-let [rem (parse-reminder (hash-ref msg '#:content))] 29 | (let ([secs (car rem)] 30 | [txt (cadr rem)]) 31 | (thread 32 | (λ () 33 | (with-task-server 34 | (delayed-task 35 | secs 36 | (-> (make-immutable-hash) 37 | (hash-set '#:id (make-uuid)) 38 | (hash-set '#:thread-id (make-uuid)) 39 | (hash-set '#:group-id (hash-ref msg '#:group-id)) 40 | (hash-set '#:content txt) 41 | (hash-set '#:mentioned-user-ids 42 | (list (hash-ref msg '#:user-id))) 43 | (hash-set '#:mentioned-tag-ids '()) 44 | (send-message #:bot-id bot-id #:bot-token bot-token 45 | #:braid-url braid-url))) 46 | (run-tasks)))) 47 | (-> (list "Okay, I'll remind you in" (number->string secs) "seconds") 48 | string-join)) 49 | (-> (list "Sorry, I don't know what that means." 50 | "Try something like " 51 | "`/reminderbot check laundry in 5 minutes`.") 52 | (string-join "\n"))) 53 | (reply-to msg 54 | #:bot-id bot-id #:bot-token bot-token 55 | #:braid-url braid-url))) 56 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | # Based from: https://github.com/greghendershott/travis-racket 4 | 5 | # Optional: To use Travis CI's newer container infrastucture, 6 | # un-comment the following line. (Also be sure RACKET_DIR is set to 7 | # somewhere like ~/racket that doesn't require sudo.) 8 | # 9 | # sudo: false 10 | 11 | env: 12 | global: 13 | # Supply a global RACKET_DIR environment variable. This is where 14 | # Racket will be installed. A good idea is to use ~/racket because 15 | # that doesn't require sudo to install and is therefore compatible 16 | # with Travis CI's newer container infrastructure. 17 | - RACKET_DIR=~/racket 18 | matrix: 19 | # Supply at least one RACKET_VERSION environment variable. This is 20 | # used by the install-racket.sh script (run at before_install, 21 | # below) to select the version of Racket to download and install. 22 | # 23 | # Supply more than one RACKET_VERSION (as in the example below) to 24 | # create a Travis-CI build matrix to test against multiple Racket 25 | # versions. 26 | # - RACKET_VERSION=5.3.4 27 | # - RACKET_VERSION=5.3.5 28 | # - RACKET_VERSION=5.92 29 | - RACKET_VERSION=6.0 30 | - RACKET_VERSION=6.1 31 | - RACKET_VERSION=6.1.1 32 | - RACKET_VERSION=HEAD 33 | 34 | before_install: 35 | - git clone https://github.com/greghendershott/travis-racket.git 36 | - cat travis-racket/install-racket.sh | bash # pipe to bash not sh! 37 | - export PATH="${RACKET_DIR}/bin:${PATH}" #install-racket.sh can't set for us 38 | 39 | install: 40 | 41 | before_script: 42 | 43 | # Here supply steps such as raco make, raco test, etc. Note that you 44 | # need to supply /usr/racket/bin/ -- it's not in PATH. You can run 45 | # `raco pkg install --deps search-auto <>` to install any required 46 | # packages without it getting stuck on a confirmation prompt. 47 | script: 48 | - /usr/racket/bin/raco make main.rkt 49 | - /usr/racket/bin/raco test -x . 50 | 51 | # NOTE: If your repo is a Racket package with an info.rkt that 52 | # includes some `deps`, the following is more elegant: 53 | # 54 | # script: 55 | # - cd .. # Travis did a cd into the dir. Back up, for the next: 56 | # - /usr/racket/bin/raco pkg install --deps search-auto --link <> 57 | # - /usr/racket/bin/raco test -x -p <> 58 | 59 | after_script: 60 | --------------------------------------------------------------------------------