aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 15:57:24 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2025-03-26 15:57:24 +0000
commit521a8915f273dc2cda59080a2393e40e4f25db50 (patch)
tree5fd01f240084566bb8d32261819f7ab14022346e
parent4d1be876f8bccf8018728d5ee474f91c256da5c9 (diff)
downloadluz-521a8915f273dc2cda59080a2393e40e4f25db50.tar.gz
luz-521a8915f273dc2cda59080a2393e40e4f25db50.tar.bz2
luz-521a8915f273dc2cda59080a2393e40e4f25db50.zip
feat(filamento): create example
-rw-r--r--filamento/.gitignore1
-rw-r--r--filamento/Cargo.toml6
-rw-r--r--filamento/examples/example.rs35
-rw-r--r--filamento/filamento.dbbin90112 -> 94208 bytes
-rw-r--r--filamento/src/db.rs2
-rw-r--r--lampada/.gitignore2
-rw-r--r--lampada/Cargo.toml3
-rw-r--r--lampada/src/main.rs42
8 files changed, 43 insertions, 48 deletions
diff --git a/filamento/.gitignore b/filamento/.gitignore
index 8bb4037..ec8a40b 100644
--- a/filamento/.gitignore
+++ b/filamento/.gitignore
@@ -1 +1,2 @@
filamento.db
+.sqlx/
diff --git a/filamento/Cargo.toml b/filamento/Cargo.toml
index 821a6a0..aed261d 100644
--- a/filamento/Cargo.toml
+++ b/filamento/Cargo.toml
@@ -15,3 +15,9 @@ jid = { version = "0.1.0", path = "../jid", features = ["sqlx"] }
uuid = { version = "1.13.1", features = ["v4"] }
tracing = "0.1.41"
chrono = "0.4.40"
+
+[dev-dependencies]
+tracing-subscriber = "0.3.19"
+
+[[example]]
+name = "example"
diff --git a/filamento/examples/example.rs b/filamento/examples/example.rs
new file mode 100644
index 0000000..f2b787b
--- /dev/null
+++ b/filamento/examples/example.rs
@@ -0,0 +1,35 @@
+use std::{path::Path, str::FromStr, time::Duration};
+
+use filamento::{Client, db::Db};
+use jid::JID;
+use tracing::info;
+
+#[tokio::main]
+async fn main() {
+ tracing_subscriber::fmt::init();
+ let db = Db::create_connect_and_migrate(Path::new("./filamentoa.db"))
+ .await
+ .unwrap();
+ let (client, mut recv) =
+ Client::new("test@blos.sm".try_into().unwrap(), "slayed".to_string(), db);
+
+ tokio::spawn(async move {
+ while let Some(msg) = recv.recv().await {
+ info!("{:#?}", msg)
+ }
+ });
+
+ client.connect().await.unwrap();
+ tokio::time::sleep(Duration::from_secs(5)).await;
+ info!("sending message");
+ client
+ .send_message(
+ JID::from_str("cel@blos.sm").unwrap(),
+ filamento::chat::Body {
+ body: "hallo!!!".to_string(),
+ },
+ )
+ .await
+ .unwrap();
+ println!("sent message");
+}
diff --git a/filamento/filamento.db b/filamento/filamento.db
index 5c3c720..c32c939 100644
--- a/filamento/filamento.db
+++ b/filamento/filamento.db
Binary files differ
diff --git a/filamento/src/db.rs b/filamento/src/db.rs
index aea40ac..f34fea6 100644
--- a/filamento/src/db.rs
+++ b/filamento/src/db.rs
@@ -1,7 +1,7 @@
use std::{collections::HashSet, path::Path};
use jid::JID;
-use sqlx::{migrate, Error, SqlitePool};
+use sqlx::{Error, SqlitePool, migrate};
use uuid::Uuid;
use crate::{
diff --git a/lampada/.gitignore b/lampada/.gitignore
deleted file mode 100644
index 60868fd..0000000
--- a/lampada/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-luz.db
-.sqlx/
diff --git a/lampada/Cargo.toml b/lampada/Cargo.toml
index 856fd7d..9b42aad 100644
--- a/lampada/Cargo.toml
+++ b/lampada/Cargo.toml
@@ -10,8 +10,5 @@ peanuts = { version = "0.1.0", path = "../../peanuts" }
jid = { version = "0.1.0", path = "../jid", features = ["sqlx"] }
stanza = { version = "0.1.0", path = "../stanza", features = ["xep_0203"] }
tokio = "1.42.0"
-tokio-stream = "0.1.17"
-tokio-util = "0.7.13"
tracing = "0.1.41"
-tracing-subscriber = "0.3.19"
thiserror = "2.0.11"
diff --git a/lampada/src/main.rs b/lampada/src/main.rs
deleted file mode 100644
index 7b7469d..0000000
--- a/lampada/src/main.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-use std::{path::Path, str::FromStr, time::Duration};
-
-use jid::JID;
-use lampada::{db::Db, CoreClientCommand, LuzHandle};
-use sqlx::SqlitePool;
-use tokio::{
- io::{AsyncReadExt, AsyncWriteExt},
- sync::oneshot,
-};
-use tracing::info;
-
-#[tokio::main]
-async fn main() {
- tracing_subscriber::fmt::init();
- let db = Db::create_connect_and_migrate(Path::new("./luz.db"))
- .await
- .unwrap();
- let (luz, mut recv) =
- LuzHandle::new("test@blos.sm".try_into().unwrap(), "slayed".to_string(), db);
-
- tokio::spawn(async move {
- while let Some(msg) = recv.recv().await {
- info!("{:#?}", msg)
- }
- });
-
- luz.send(CoreClientCommand::Connect).await.unwrap();
- let (send, recv) = oneshot::channel();
- tokio::time::sleep(Duration::from_secs(5)).await;
- info!("sending message");
- luz.send(CoreClientCommand::SendMessage(
- JID::from_str("cel@blos.sm").unwrap(),
- luz::chat::Body {
- body: "hallo!!!".to_string(),
- },
- send,
- ))
- .await
- .unwrap();
- recv.await.unwrap().unwrap();
- println!("sent message");
-}