parse the feed command, add users
This commit is contained in:
parent
046d3157c2
commit
86a257410c
7 changed files with 57 additions and 18 deletions
1
migrations/0001_users.down.sql
Normal file
1
migrations/0001_users.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
-- Add down migration script here
|
||||||
1
migrations/0001_users.up.sql
Normal file
1
migrations/0001_users.up.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
CREATE TABLE IF NOT EXISTS feeds (
|
CREATE TABLE IF NOT EXISTS feeds (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
url TEXT UNIQUE NOT NULL,
|
url TEXT UNIQUE NOT NULL,
|
||||||
added_by TEXT NOT NULL,
|
added_by INT NOT NULL,
|
||||||
last_modified_by TEXT NOT NULL,
|
last_modified_by TEXT NOT NULL,
|
||||||
active BOOLEAN NOT NULL DEFAULT FALSE,
|
active BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
created_at DATETIME NOT NULL DEFAULT current_timestamp,
|
created_at DATETIME NOT NULL DEFAULT current_timestamp,
|
||||||
|
|
@ -11,7 +11,13 @@ use serde::Deserialize;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
use sqlx::SqlitePool;
|
use sqlx::SqlitePool;
|
||||||
use tokio_util::sync::CancellationToken;
|
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>;
|
type Payload = Map<String, Value>;
|
||||||
|
|
||||||
|
|
@ -68,9 +74,18 @@ async fn handle_manage_feed(
|
||||||
if state.email == bot_email && state.token == token {
|
if state.email == bot_email && state.token == token {
|
||||||
tracing::debug!("gonna do a thing with {message:?}");
|
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()
|
Json(HashMap::from([("content", "nee-ope")])).into_response()
|
||||||
} else {
|
} else {
|
||||||
tracing::debug!("bad emal/token");
|
|
||||||
StatusCode::IM_A_TEAPOT.into_response()
|
StatusCode::IM_A_TEAPOT.into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,18 +135,40 @@ struct ZulipMessage {
|
||||||
_rest: Payload,
|
_rest: Payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_command(input: &mut &str) -> String {
|
enum Action {
|
||||||
// let Ok(s) = ("***@", winnow::token::take_until(1.., "**"))
|
Add,
|
||||||
// .map(|(_, s, _)| s)
|
Remove,
|
||||||
// .parse_next(input)
|
Help,
|
||||||
// else {
|
}
|
||||||
// return "could not find Blogdor's name".to_string();
|
|
||||||
// };
|
struct FeedCommand<'req> {
|
||||||
// if s != "Blogdor Outgoing Bot" {
|
feed: &'req str,
|
||||||
// return "could not confirm Blogdor's name".to_string();
|
action: Action,
|
||||||
// }
|
}
|
||||||
|
|
||||||
// s.into()
|
fn parse_command<'i>(input: &mut &'i str) -> winnow::Result<FeedCommand<'i>> {
|
||||||
|
let _ = "**@blogdor's manager**".parse_next(input)?;
|
||||||
todo!()
|
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 })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue