Renamed commands/Command to plugin/Plugin.

This commit is contained in:
Micheal Smith
2025-11-14 07:19:28 -06:00
parent 70de039610
commit 30e2d9a448
4 changed files with 24 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ use irc::client::prelude::{Client, Command, Config as IRCConfig, Message};
use tokio::sync::mpsc;
use tracing::{Level, event, instrument};
use crate::{Event, EventManager, LLMHandle, commands};
use crate::{Event, EventManager, LLMHandle, plugin};
#[derive(Debug)]
pub struct Chat {
@@ -50,7 +50,7 @@ pub async fn new(
}
impl Chat {
pub async fn run(&mut self, mut command_in: mpsc::Receiver<commands::Command>) -> Result<()> {
pub async fn run(&mut self, mut command_in: mpsc::Receiver<plugin::Plugin>) -> Result<()> {
self.client.identify()?;
let mut stream = self.client.stream()?;
@@ -69,7 +69,7 @@ impl Chat {
command = command_in.recv() => {
event!(Level::INFO, "Received command {:#?}", command);
match command {
Some(commands::Command::SendMessage {channel, message} ) => {
Some(plugin::Plugin::SendMessage {channel, message} ) => {
// Now to pass on the message.
event!(Level::INFO, "Trying to send to channel.");
self.client.send_privmsg(&channel, &message).wrap_err("Couldn't send to channel")?;

View File

@@ -9,7 +9,7 @@ use tokio::{
};
use tracing::{error, info};
use crate::{commands::Command, event::Event};
use crate::{event::Event, plugin::Plugin};
// Hard coding for now. Maybe make this a parameter to new.
const EVENT_BUF_MAX: usize = 1000;
@@ -49,7 +49,7 @@ impl EventManager {
}
// NB: This assumes it has exclusive control of the FIFO.
pub async fn start_fifo<P>(path: &P, command_tx: mpsc::Sender<Command>) -> Result<()>
pub async fn start_fifo<P>(path: &P, command_tx: mpsc::Sender<Plugin>) -> Result<()>
where
P: AsRef<Path> + NixPath + ?Sized,
{
@@ -65,7 +65,7 @@ impl EventManager {
while reader.read_line(&mut line).await? > 0 {
// Now handle the command.
let cmd: Command = serde_json::from_str(&line)?;
let cmd: Plugin = serde_json::from_str(&line)?;
info!("Command received: {:?}.", cmd);
command_tx.send(cmd).await?;
line.clear();
@@ -316,7 +316,7 @@ mod tests {
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
// Write a command to the FIFO
let cmd = Command::SendMessage {
let cmd = Plugin::SendMessage {
channel: "#test".to_string(),
message: "hello".to_string(),
};
@@ -338,7 +338,7 @@ mod tests {
.expect("channel closed");
match received {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#test");
assert_eq!(message, "hello");
}
@@ -362,15 +362,15 @@ mod tests {
// Write multiple commands
let commands = vec![
Command::SendMessage {
Plugin::SendMessage {
channel: "#chan1".to_string(),
message: "first".to_string(),
},
Command::SendMessage {
Plugin::SendMessage {
channel: "#chan2".to_string(),
message: "second".to_string(),
},
Command::SendMessage {
Plugin::SendMessage {
channel: "#chan3".to_string(),
message: "third".to_string(),
},
@@ -395,7 +395,7 @@ mod tests {
.expect("channel closed");
match first {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#chan1");
assert_eq!(message, "first");
}
@@ -407,7 +407,7 @@ mod tests {
.expect("channel closed");
match second {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#chan2");
assert_eq!(message, "second");
}
@@ -419,7 +419,7 @@ mod tests {
.expect("channel closed");
match third {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#chan3");
assert_eq!(message, "third");
}
@@ -449,7 +449,7 @@ mod tests {
let tx = pipe::OpenOptions::new().open_sender(&path).unwrap();
let mut tx = tokio::io::BufWriter::new(tx);
let cmd = Command::SendMessage {
let cmd = Plugin::SendMessage {
channel: "#first".to_string(),
message: "batch1".to_string(),
};
@@ -465,7 +465,7 @@ mod tests {
.expect("channel closed");
match first {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#first");
assert_eq!(message, "batch1");
}
@@ -482,7 +482,7 @@ mod tests {
let tx = pipe::OpenOptions::new().open_sender(&fifo_path).unwrap();
let mut tx = tokio::io::BufWriter::new(tx);
let cmd = Command::SendMessage {
let cmd = Plugin::SendMessage {
channel: "#second".to_string(),
message: "batch2".to_string(),
};
@@ -497,7 +497,7 @@ mod tests {
.expect("channel closed");
match second {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#second");
assert_eq!(message, "batch2");
}
@@ -524,7 +524,7 @@ mod tests {
let tx = pipe::OpenOptions::new().open_sender(&fifo_path).unwrap();
let mut tx = tokio::io::BufWriter::new(tx);
let cmd1 = Command::SendMessage {
let cmd1 = Plugin::SendMessage {
channel: "#test".to_string(),
message: "first".to_string(),
};
@@ -537,7 +537,7 @@ mod tests {
// Write whitespace line
tx.write_all(b" \n").await.unwrap();
let cmd2 = Command::SendMessage {
let cmd2 = Plugin::SendMessage {
channel: "#test".to_string(),
message: "second".to_string(),
};
@@ -553,7 +553,7 @@ mod tests {
.expect("channel closed");
match first {
Command::SendMessage { channel, message } => {
Plugin::SendMessage { channel, message } => {
assert_eq!(channel, "#test");
assert_eq!(message, "first");
}

View File

@@ -9,10 +9,10 @@ use tracing::{Level, info};
use tracing_subscriber::FmtSubscriber;
pub mod chat;
pub mod commands;
pub mod event;
pub mod event_manager;
pub mod ipc;
pub mod plugin;
pub mod qna;
pub mod setup;

View File

@@ -3,11 +3,11 @@ use std::fmt::Display;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub enum Command {
pub enum Plugin {
SendMessage { channel: String, message: String },
}
impl Display for Command {
impl Display for Plugin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::SendMessage { channel, message } => {