feat(app): answer registered chat channels in chat
- chatChannels[].answer: wakeWord (default) or everything. Chat uses call.chatWakeWords (else the voice wake words) with the shared designated-people switches. - The brain's answer (reply via chat, not spoken) is posted as a Discord reply to the message, pinging nobody; failed or empty answers post nothing. Bots, channels with sending off and stops are not answered. - Chat runs beside the voice conversation and never takes its turn. - Core: send_chat_reply, chat_answer and the ReplyText event; the worker client's reply takes via. - Specs (conversation, discord core) and the roadmap updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,8 @@ pub enum CoreEvent {
|
||||
/// `SpeakEnd`s of what it stopped.
|
||||
Stopped,
|
||||
Chat(ChatMessage),
|
||||
/// The brain's answer text for a `reply` (`answer()` or `chat_answer()`).
|
||||
ReplyText { id: String, text: String, failed: bool },
|
||||
/// The brain's answer to `addressed()`.
|
||||
Addressed { id: String, addressed: bool },
|
||||
/// The brain's answer to `rank()`: candidate ids, most important first (empty: failed).
|
||||
@@ -405,10 +407,15 @@ impl DiscordCore {
|
||||
pub fn answer(&self, user: u64, text: &str) -> Option<String> {
|
||||
self.voice_channel_id()?;
|
||||
let id = with_playback(&self.inner, |p| p.adopt());
|
||||
self.inner.worker.reply(&id, user, text, true);
|
||||
self.inner.worker.reply(&id, user, text, "voice", true);
|
||||
Some(id)
|
||||
}
|
||||
|
||||
/// Have the brain answer a chat message under `id`; the text comes as `CoreEvent::ReplyText`.
|
||||
pub fn chat_answer(&self, id: &str, user: u64, text: &str) -> bool {
|
||||
self.inner.worker.reply(id, user, text, "chat", false)
|
||||
}
|
||||
|
||||
/// Stop one request (an answer or a `say`); the rest of the queue goes on.
|
||||
pub fn cancel(&self, id: &str) {
|
||||
with_playback(&self.inner, |p| p.cancel(id));
|
||||
@@ -474,6 +481,27 @@ impl DiscordCore {
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
/// Send `text` to a registered channel as a reply to `message` (the first part carries the reply;
|
||||
/// nobody is pinged, not even the person answered). The message ids.
|
||||
pub async fn send_chat_reply(&self, channel_id: u64, message: u64, text: &str) -> Result<Vec<u64>, CoreError> {
|
||||
self.inner.chat.check_send(channel_id)?;
|
||||
if text.trim().is_empty() {
|
||||
return Err(CoreError("nothing to send".into()));
|
||||
}
|
||||
let http = self.http()?;
|
||||
let mut ids = vec![];
|
||||
for (i, part) in split_message(text, MESSAGE_LIMIT).into_iter().enumerate() {
|
||||
let mut m = CreateMessage::new().content(part).allowed_mentions(CreateAllowedMentions::new().replied_user(false));
|
||||
if i == 0 {
|
||||
m = m.reference_message((ChannelId::new(channel_id), MessageId::new(message)));
|
||||
}
|
||||
let sent = ChannelId::new(channel_id).send_message(http.as_ref(), m).await.map_err(cerr("could not send"))?;
|
||||
ids.push(sent.id.get());
|
||||
}
|
||||
debug_log!("chat", "chat answer sent to {channel_id} parts={} chars={}", ids.len(), text.chars().count());
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
/// Do what the brain's chat channel tool asked (chat_channels.spec.md). The message ids made or
|
||||
/// touched. Every action needs its channel switch; edits only the bot's own messages.
|
||||
pub async fn chat_action(&self, a: &ChatAction) -> Result<Vec<u64>, CoreError> {
|
||||
@@ -660,6 +688,7 @@ async fn worker_task(core: std::sync::Weak<Inner>, mut rx: mpsc::UnboundedReceiv
|
||||
WorkerEvent::TtsDone(d) => with_playback(&inner, |p| p.done(&d)),
|
||||
WorkerEvent::ReplyText { id, text, failed } => {
|
||||
debug_log!("voice", "reply {id} chars={} failed={failed}", text.chars().count());
|
||||
let _ = inner.events.send(CoreEvent::ReplyText { id, text, failed });
|
||||
}
|
||||
WorkerEvent::Addressed { id, addressed } => {
|
||||
let _ = inner.events.send(CoreEvent::Addressed { id, addressed });
|
||||
|
||||
Reference in New Issue
Block a user