Rename workspace packages and update Rust imports and usage examples
This commit is contained in:
Generated
+26
-26
@@ -29,12 +29,30 @@ version = "0.2.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57b212daf2e827b1ccdd778b7eb48ba433e58cb0e4f27b43cd6b7a608425a014"
|
||||
|
||||
[[package]]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bot",
|
||||
"core",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"ureq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.23.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5"
|
||||
|
||||
[[package]]
|
||||
name = "bot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.12.2"
|
||||
@@ -97,6 +115,14 @@ dependencies = [
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"jieba-rs",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.6"
|
||||
@@ -811,32 +837,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "telefind-app"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"telefind-bot",
|
||||
"telefind-core",
|
||||
"ureq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "telefind-bot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"telefind-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "telefind-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"jieba-rs",
|
||||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.55"
|
||||
|
||||
@@ -7,7 +7,7 @@ Rust keyword search for public Telegram channels, groups, bots and posts. The ex
|
||||
From the workspace root:
|
||||
|
||||
```sh
|
||||
cargo run -p telefind-app -- query - '/search type:video 上海相机' <<'JSONL'
|
||||
cargo run -p app -- query - '/search type:video 上海相机' <<'JSONL'
|
||||
{"op":"upsert","kind":"post","id":-100501,"message_id":42,"username":"example_feed","title":"相机入门.mp4","body":"上海 摄影","media":"video"}
|
||||
JSONL
|
||||
```
|
||||
@@ -19,7 +19,7 @@ This prints the reply as JSON, including a button with the URL `https://t.me/exa
|
||||
Supply the bot token through the environment variable `TELEGRAM_BOT_TOKEN` and run:
|
||||
|
||||
```sh
|
||||
cargo run -p telefind-app -- bot events.jsonl
|
||||
cargo run -p app -- bot events.jsonl
|
||||
```
|
||||
|
||||
The input file is optional. The process identifies its username via `getMe`, then long-polls for incoming messages and sends search results with URL buttons. Type keywords in private chat or use `/search@YourBot keywords` in a group. In a public channel where the bot receives posts, incoming posts and edits update the in-memory index. For channels without a public username, protected posts and unsupported content, the bot skips indexing the message. Telegram does not send ordinary post-deletion notifications via this update stream. An upstream source can supply deletion events. If a reply reached Telegram but its HTTP acknowledgement was lost, retrying an update can send the reply twice.
|
||||
@@ -34,7 +34,7 @@ Pass an ordered UTF-8 JSONL stream in a file, or pass `-` to read standard input
|
||||
{"op":"delete","kind":"post","id":-100501,"message_id":42}
|
||||
```
|
||||
|
||||
The process keeps no database or history archive. Restarting loads whichever input the caller supplies. For a persistent or concurrent host, implement `telefind_core::index::IndexStore` and its snapshot reader, then use `Engine::new(store)`. Pass the resulting engine to `telefind_app::telegram::run` with a `telefind_app::telegram::Client` to reuse the same polling and reply logic. The JSONL reader `telefind_app::input::load` also accepts any implementation of `SearchIndex`.
|
||||
The process keeps no database or history archive. Restarting loads whichever input the caller supplies. For a persistent or concurrent host, implement `search_core::index::IndexStore` and its snapshot reader, then use `Engine::new(store)`. Pass the resulting engine to `app::telegram::run` with a `app::telegram::Client` to reuse the same polling and reply logic. The JSONL reader `app::input::load` also accepts any implementation of `SearchIndex`.
|
||||
|
||||
## Verification
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "telefind-app"
|
||||
name = "app"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
default-run = "telefind"
|
||||
@@ -9,8 +9,8 @@ name = "telefind"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
telefind-core = { path = "../core" }
|
||||
telefind-bot = { path = "../bot" }
|
||||
core = { path = "../core" }
|
||||
bot = { path = "../bot" }
|
||||
ureq = { version = "3", features = ["json"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Line-delimited public document changes supplied by the caller.
|
||||
use search_core::{Document, DocumentId, Media, PublicName, SearchIndex};
|
||||
use serde::Deserialize;
|
||||
use std::{error::Error, io::BufRead};
|
||||
use telefind_core::{Document, DocumentId, Media, PublicName, SearchIndex};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use app::{input, telegram};
|
||||
use search_core::MemoryIndex;
|
||||
use std::{
|
||||
env,
|
||||
error::Error,
|
||||
@@ -5,8 +7,6 @@ use std::{
|
||||
io::{self, BufReader},
|
||||
process::ExitCode,
|
||||
};
|
||||
use telefind_app::{input, telegram};
|
||||
use telefind_core::MemoryIndex;
|
||||
|
||||
const USAGE: &str = concat!(
|
||||
"telefind bot [events.jsonl|-]\n",
|
||||
@@ -36,7 +36,7 @@ fn run() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
Some("query") if args.len() >= 3 => {
|
||||
load(&args[1], &mut index)?;
|
||||
let reply = telefind_bot::handle(&index, "telefind", &args[2..].join(" "))?;
|
||||
let reply = bot::handle(&index, "telefind", &args[2..].join(" "))?;
|
||||
println!("{}", serde_json::to_string(&telegram::render(reply))?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ use self::{
|
||||
update::{dispatch, Update},
|
||||
};
|
||||
pub use client::Client;
|
||||
use search_core::SearchIndex;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use std::{error::Error, thread, time::Duration};
|
||||
use telefind_core::SearchIndex;
|
||||
pub use update::render;
|
||||
|
||||
fn with_retry<T>(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Broker-neutral gateway and leased workers. Each adapter is scoped to one bot.
|
||||
use super::{client::Failure, process, receive, run_loop, Client, Update};
|
||||
use search_core::SearchIndex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{error::Error, time::Duration};
|
||||
use telefind_core::SearchIndex;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Lane {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::*;
|
||||
use search_core::MemoryIndex;
|
||||
use std::{
|
||||
io::{BufRead, BufReader, Read, Write},
|
||||
net::TcpListener,
|
||||
};
|
||||
use telefind_core::MemoryIndex;
|
||||
|
||||
fn respond(server: &TcpListener, reply: impl FnOnce(&str, Value) -> (u16, String)) {
|
||||
let (mut socket, _) = server.accept().unwrap();
|
||||
@@ -105,7 +105,7 @@ fn nonpublic_and_protected_updates_do_not_add_searchable_posts() {
|
||||
}
|
||||
assert_eq!(
|
||||
index
|
||||
.search(&telefind_core::Query::new("private"))
|
||||
.search(&search_core::Query::new("private"))
|
||||
.unwrap()
|
||||
.total,
|
||||
0
|
||||
|
||||
@@ -108,7 +108,7 @@ fn publish_failure_keeps_offset_then_workers_replay_and_defer_flooded_reply() {
|
||||
assert_eq!(step(&mut queries), Outcome::Completed);
|
||||
assert_eq!(
|
||||
index
|
||||
.search(&telefind_core::Query::new("tutorial"))
|
||||
.search(&search_core::Query::new("tutorial"))
|
||||
.unwrap()
|
||||
.total,
|
||||
0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use bot::{handle, Reply};
|
||||
use search_core::{Document, DocumentId, Media, PublicName, SearchIndex};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use telefind_bot::{handle, Reply};
|
||||
use telefind_core::{Document, DocumentId, Media, PublicName, SearchIndex};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Update {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "telefind-bot"
|
||||
name = "bot"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
telefind-core = { path = "../core" }
|
||||
core = { path = "../core" }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use telefind_core::{Kind, Media, Query};
|
||||
use search_core::{Kind, Media, Query};
|
||||
pub(crate) enum Input<'a> {
|
||||
Ignore,
|
||||
Help,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Transport-independent Telegram search interaction. The host supplies
|
||||
//! incoming text and sends the returned plain-text labels and URL buttons.
|
||||
mod command;
|
||||
use telefind_core::{Document, Kind, SearchIndex};
|
||||
use search_core::{Document, Kind, SearchIndex};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ResultLink {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use telefind_bot::{handle, Reply};
|
||||
use telefind_core::{Document, DocumentId, MemoryIndex, PublicName, SearchIndex};
|
||||
use bot::{handle, Reply};
|
||||
use search_core::{Document, DocumentId, MemoryIndex, PublicName, SearchIndex};
|
||||
|
||||
#[test]
|
||||
fn plain_and_addressed_search_return_public_post_link() {
|
||||
@@ -72,7 +72,7 @@ fn paging_is_stateless_and_rejects_invalid_numbers() {
|
||||
#[test]
|
||||
fn type_filter_is_available_in_search_and_page_commands() {
|
||||
let mut index = MemoryIndex::default();
|
||||
for (id, media) in [(1, None), (2, Some(telefind_core::Media::Video))] {
|
||||
for (id, media) in [(1, None), (2, Some(search_core::Media::Video))] {
|
||||
index
|
||||
.upsert(Document {
|
||||
id: DocumentId::Post {
|
||||
@@ -117,7 +117,7 @@ fn scoped_media_search_keeps_quoted_phrase_and_original_link() {
|
||||
username: PublicName::new("my_feed").unwrap(),
|
||||
title: String::new(),
|
||||
body: body.into(),
|
||||
media: Some(telefind_core::Media::Video),
|
||||
media: Some(search_core::Media::Video),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
[package]
|
||||
name = "telefind-core"
|
||||
name = "core"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "search_core"
|
||||
|
||||
[dependencies]
|
||||
jieba-rs = "0.8"
|
||||
unicode-normalization = "0.1"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use telefind_core::{
|
||||
Document, DocumentId, Kind, Media, MemoryIndex, PublicName, Query, SearchIndex,
|
||||
};
|
||||
use search_core::{Document, DocumentId, Kind, Media, MemoryIndex, PublicName, Query, SearchIndex};
|
||||
|
||||
fn post(chat: i64, message: u32, title: &str, body: &str) -> Document {
|
||||
Document {
|
||||
|
||||
Reference in New Issue
Block a user