Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
Extract non-core fragments using self-repair criterion:
- core-context -> symbolic-awareness (224 lines, fboundp guards in think())
- heartbeat generation -> symbolic-events (renamed events-start-heartbeat)
Rename 23 files for clarity and new naming scheme:
- 6 core: core-package, core-transport, core-pipeline,
core-perceive, core-reason, core-act
- 13 system: symbolic-*, neuro-*, embedding-*, channel-shell
- 4 gateway: channel-cli, channel-tui-*, channel-tui-state
Utility relocations:
- markdown-strip -> programming-markdown
- plist-keywords-normalize -> programming-lisp
- cognitive-tool-prompt -> programming-tools
- VAULT-MEMORY -> security-vault
- Merge *backend-registry* into *probabilistic-backends*
Split gateway-messaging into channel-telegram/channel-signal/
channel-discord/channel-slack (4 independent skills)
Delete dead system-model.lisp (16-line wrapper)
Document self-repair criterion in DESIGN_DECISIONS
Version bump: 0.4.3 -> 0.5.0
67 lines
3.0 KiB
Org Mode
67 lines
3.0 KiB
Org Mode
#+TITLE: Channel Discord (channel-discord.org)
|
|
#+AUTHOR: Agent
|
|
#+FILETAGS: :channel:discord:
|
|
#+PROPERTY: header-args:lisp :tangle ../lisp/channel-discord.lisp
|
|
|
|
* Channel Discord
|
|
|
|
Extracted from gateway-messaging in v0.5.0. Isolated platform — Discord-specific poll and send logic.
|
|
|
|
* Implementation
|
|
|
|
#+begin_src lisp
|
|
(in-package :passepartout)
|
|
(defun discord-get-token ()
|
|
(vault-get-secret :discord))
|
|
|
|
(defun discord-send (action context)
|
|
"Sends a message via Discord REST API."
|
|
(declare (ignore context))
|
|
(let* ((payload (getf action :payload))
|
|
(meta (getf action :meta))
|
|
(channel-id (or (getf meta :channel-id) (getf payload :chat-id)))
|
|
(text (or (getf payload :text) (getf action :text)))
|
|
(token (discord-get-token)))
|
|
(when (and token channel-id text)
|
|
(handler-case
|
|
(dex:post (format nil "https://discord.com/api/v10/channels/~a/messages" channel-id)
|
|
:headers '(("Authorization" . ,(format nil "Bot ~a" token))
|
|
("Content-Type" . "application/json"))
|
|
:content (cl-json:encode-json-to-string
|
|
`((content . ,text))))
|
|
(error (c) (log-message "DISCORD ERROR: ~a" c))))))
|
|
|
|
(defun discord-poll ()
|
|
"Polls Discord via HTTP GET /channels/{id}/messages. In production,
|
|
a WebSocket connection to the Gateway is preferred for real-time events."
|
|
(let* ((token (discord-get-token)))
|
|
(when token
|
|
(handler-case
|
|
(dolist (channel '("channel-id-here")) ;; configured channel IDs
|
|
(let* ((last-id (getf (gethash "discord" *gateway-configs*) :last-update-id 0))
|
|
(url (format nil "https://discord.com/api/v10/channels/~a/messages?after=~a"
|
|
channel last-id))
|
|
(response (dex:get url :headers
|
|
`(("Authorization" . ,(format nil "Bot ~a" token))))))
|
|
(let ((messages (ignore-errors
|
|
(cdr (assoc :message
|
|
(cl-json:decode-json-from-string response))))))
|
|
(dolist (msg (and (listp messages) messages))
|
|
(let* ((id (cdr (assoc :id msg)))
|
|
(content (cdr (assoc :content msg)))
|
|
(author (cdr (assoc :author msg)))
|
|
(author-id (cdr (assoc :id author)))
|
|
(is-bot (cdr (assoc :bot author))))
|
|
(when (and id content (not is-bot))
|
|
(setf (getf (gethash "discord" *gateway-configs*) :last-update-id) id)
|
|
(unless (ignore-errors (hitl-handle-message content :discord))
|
|
(stimulus-inject
|
|
(list :type :EVENT
|
|
:meta (list :source :discord :chat-id channel)
|
|
:payload (list :sensor :user-input :text content))))))))))
|
|
(error (c) (log-message "DISCORD POLL ERROR: ~a" c))))))
|
|
#+end_src
|
|
|
|
|
|
#+end_src
|