hi from the commit
This commit is contained in:
commit
e09e97b93c
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
creds
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "hixmpp"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tokio = "1"
|
||||
tokio-xmpp = "3.2.0"
|
||||
xmpp-parsers = "0.19.2"
|
|
@ -0,0 +1,17 @@
|
|||
# Hi from the main
|
||||
|
||||
## This is a silly thing stealing code from sendxmpp
|
||||
|
||||
To use this you must place a "creds" file with the folowing structure:
|
||||
|
||||
```plaintext
|
||||
jid
|
||||
password
|
||||
```
|
||||
|
||||
The message is hardcoded in main.rs, could be changed to be pulled from the creds file but meh
|
||||
|
||||
The recipients are hardcoded strings into the main.rs in a vec! macro.
|
||||
|
||||
# License: Have fun
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
use std::fs;
|
||||
use tokio_xmpp::SimpleClient;
|
||||
use xmpp_parsers::message::{Body, Message, MessageType};
|
||||
use xmpp_parsers::{Element, Jid};
|
||||
|
||||
const CREDS: &str = "creds";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let creds = fs::read_to_string(CREDS)
|
||||
.expect("Should have been able to read the file");
|
||||
let mut creds = creds.lines();
|
||||
let (jid, password) = (creds.next().expect("No JID"), creds.next().expect("No Pass"));
|
||||
let recipients = vec!["suguivy@fai.st", "bizcochito@fai.st", "bizcochito@cronut.cafe"];
|
||||
|
||||
xmp(jid, password, "Hi from the main", recipients).await;
|
||||
}
|
||||
|
||||
async fn xmp(jid: &str, password: &str, data: &str, recipients: Vec<&str>) {
|
||||
let data = data.trim();
|
||||
if data.is_empty() {/* don't send empty stanzas*/ return;}
|
||||
|
||||
let mut client = SimpleClient::new(jid, password).await.expect("could not connect to xmpp server");
|
||||
for recipient in recipients{
|
||||
let recipient = recipient.parse::<Jid>().unwrap();
|
||||
let reply = make_reply(recipient.clone(), &data, false);
|
||||
client.send_stanza(reply).await.expect("sending message failed");
|
||||
}
|
||||
// Close SimpleClient connection
|
||||
client.end().await.ok(); // ignore errors here, I guess
|
||||
}
|
||||
|
||||
fn make_reply(to: Jid, body: &str, groupchat: bool) -> Element {
|
||||
let mut message = Message::new(Some(to));
|
||||
if groupchat {
|
||||
message.type_ = MessageType::Groupchat;
|
||||
}
|
||||
message.bodies.insert(String::new(), Body(body.to_owned()));
|
||||
message.into()
|
||||
}
|
Loading…
Reference in New Issue