b22daeb17e3bb126da14d71929c8eefda0de73b5 — Vincent Lee 1 year, 5 months ago 0c3f470
Allow delete_time to be configurable, and document it
2 files changed, 14 insertions(+), 8 deletions(-)

M frontends/discord.rkt
M scribblings/r16.scrbl
M frontends/discord.rkt => frontends/discord.rkt +11 -7
@@ 9,7 9,7 @@
 (only-in racket/function const curry identity negate thunk)
 (only-in racket/math exact-ceiling)
 (only-in racket/math exact-ceiling nonnegative-integer?)
 (only-in racket/port port->bytes with-input-from-string with-output-to-string)

@@ 86,6 86,7 @@
    (init-field client)
    (init-field bot-prefix)
    (init-field trick-prefix)
    (init-field delete-time-sec)

    (define with-typing-indicator ;; (_ proc)
      (let ()

@@ 192,16 193,17 @@
    (define recent-messages-cache
       (* 5 60 1000))) ;; 5 min as ms
       (* delete-time-sec 1000)))

     (sleep 30)
     (let ([purged (length (expiring-cache-purge emote-image-cache))])
       (when (> purged 0)
         (log-r16-debug "Purged ~a emote image bytestrings" purged)))
     (let ([purged (length (expiring-cache-purge recent-messages-cache))])
       (when (> purged 0)
         (log-r16-debug "Purged ~a recent messages" purged))))
     (when (> delete-time-sec 0)
       (let ([purged (length (expiring-cache-purge recent-messages-cache))])
         (when (> purged 0)
           (log-r16-debug "Purged ~a recent messages" purged)))))

    (define/public (get-enrich-context)
      (define deleted-box (current-deleted-box))

@@ 414,7 416,7 @@
               (and not-deleted message)
            (when (and not-deleted response)
            (when (and response not-deleted (> delete-time-sec 0))
              (define response-id (hash-ref response 'id))
              (expiring-cache-put recent-messages-cache
                                  (hash-ref message 'id)

@@ 672,6 674,7 @@
  (define token (hash-ref config 'bot_token))
  (define bot-prefix (hash-ref config 'bot_prefix "!rkt "))
  (define trick-prefix (hash-ref config 'trick_prefix "!!"))
  (define delete-time-sec (hash-ref config 'delete_time 300))
  (define client

@@ 680,4 683,5 @@
  (new discord-frontend%
       [client client]
       [bot-prefix bot-prefix]
       [trick-prefix trick-prefix]))
       [trick-prefix trick-prefix]
       [delete-time-sec delete-time-sec]))

M scribblings/r16.scrbl => scribblings/r16.scrbl +3 -1
@@ 2,7 2,7 @@

@(require (for-label racket/base (only-in racket/math natural?) racket/contract))

@title{R16 -- Community-Driven Interactive Code Evaluation}
@title{R16 — Community-Driven Interactive Code Evaluation}

R16 is a "trick bot". It saves snippets of code, which can then be recalled and executed on user-provided input.

@@ 93,6 93,8 @@ The @tt{frontend} object in the configuration file can have the following keys a
@item{@tt{bot_token} must be a string containing your Discord bot token.}
@item{@tt{bot_prefix} is a string specifying the bot's trigger prefix. If not present, defaults to @code{"!rkt "}.}
@item{@tt{trick_prefix} is a string specifying the bot's shorthand prefix. If not present, defaults to @code{"!!"}.}
@item{@tt{delete_time} is a nonnegative integer specifying a time in seconds. If any invocation of R16 is deleted within this time, then R16 will also delete its response.
This helps with spam due to incorrect trick invocations. If not present, defaults to 5 minutes (300 seconds). Set to 0 to disable this feature.}

@subsection{Discord Trick Environment Extensions}