parse the feed command, add users

This commit is contained in:
Joe 2025-12-20 18:08:46 -08:00
parent 046d3157c2
commit 86a257410c
7 changed files with 57 additions and 18 deletions

View file

@ -0,0 +1 @@
-- Add down migration script here

View file

@ -0,0 +1 @@

View file

@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS feeds (
id INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY,
url TEXT UNIQUE NOT NULL,
added_by TEXT NOT NULL,
added_by INT NOT NULL,
last_modified_by TEXT NOT NULL,
active BOOLEAN NOT NULL DEFAULT FALSE,
created_at DATETIME NOT NULL DEFAULT current_timestamp,

View file

@ -11,7 +11,13 @@ use serde::Deserialize;
use serde_json::{Map, Value};
use sqlx::SqlitePool;
use tokio_util::sync::CancellationToken;
use winnow::Parser;
use winnow::{
Parser,
ascii::space0,
combinator::{alt, fail},
error::StrContext,
token::take_while,
};
type Payload = Map<String, Value>;
@ -68,9 +74,18 @@ async fn handle_manage_feed(
if state.email == bot_email && state.token == token {
tracing::debug!("gonna do a thing with {message:?}");
let ZulipMessage {
mut content,
ref sender_email,
sender_id,
sender_full_name,
..
} = message;
let command = parse_command(&mut content.as_str());
Json(HashMap::from([("content", "nee-ope")])).into_response()
} else {
tracing::debug!("bad emal/token");
StatusCode::IM_A_TEAPOT.into_response()
}
}
@ -120,18 +135,40 @@ struct ZulipMessage {
_rest: Payload,
}
fn parse_command(input: &mut &str) -> String {
// let Ok(s) = ("***@", winnow::token::take_until(1.., "**"))
// .map(|(_, s, _)| s)
// .parse_next(input)
// else {
// return "could not find Blogdor's name".to_string();
// };
// if s != "Blogdor Outgoing Bot" {
// return "could not confirm Blogdor's name".to_string();
// }
// s.into()
todo!()
enum Action {
Add,
Remove,
Help,
}
struct FeedCommand<'req> {
feed: &'req str,
action: Action,
}
fn parse_command<'i>(input: &mut &'i str) -> winnow::Result<FeedCommand<'i>> {
let _ = "**@blogdor's manager**".parse_next(input)?;
let action = (
space0,
alt((
"add",
"remove",
"help",
fail.context(StrContext::Expected(
"supported commands are `add`, `remove`, or `help`".into(),
)),
)),
)
.map(|(_, a)| match a {
"add" => Action::Add,
"remove" => Action::Remove,
"help" => Action::Help,
_ => unreachable!(),
})
.parse_next(input)?;
let feed = (space0, take_while(0.., |c: char| !c.is_whitespace()))
.map(|(_, f)| f)
.parse_next(input)?;
Ok(FeedCommand { feed, action })
}