Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 0a8fc7b3 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Initial commit: The bot can sign in as a user with a passowrd

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
/target
conf.ini
Ce diff est replié.
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "mgb"
version = "0.1.0"
authors = ["Maël 'Kubat' Martin <mael.martin31@gmail.com>"]
edition = "2018"
[profile.release]
panic = 'abort'
[dependencies]
matrix-sdk = "0.4.1"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync", "macros"] }
rust-ini = "0.17"
url = "2.2.2"
# MGB: Matrix Gatcha Bot
## Build instructions
Just use the `cargo build` command. You will need the nighly version of the rust
toolchain, so a `rustup default nightly` might be needed.
#![allow(unused_imports)]
extern crate ini;
use ini::Ini;
use matrix_sdk::{
ruma::{
events::{room::message::MessageEventContent, SyncMessageEvent},
UserId,
},
Client, Result, SyncSettings,
};
use std::convert::TryFrom;
use std::{env, process::exit};
use url::Url;
/* a def conf creation (TODO):
let mut conf = Ini::new();
conf.with_section(None::<String>)
.set("encoding", "utf-8");
conf.with_section(Some("User"))
.set("given_name", "Tommy")
.set("family_name", "Green")
.set("unicode", "Raspberry树莓");
conf.with_section(Some("Book"))
.set("name", "Rust cool");
conf.write_to_file("conf.ini").unwrap();
*/
#[tokio::main]
async fn main() -> Result<()> {
let config_file = "conf.ini"; // TODO
let conf = Ini::load_from_file(config_file).unwrap();
let user_conf = conf.section(Some("user")).unwrap();
let user_id = user_conf.get("id").unwrap();
let user_token = user_conf.get("password").unwrap();
let homeserver = user_conf.get("homeserver").unwrap();
let alice = UserId::try_from(user_id)?;
println!("User id created: {}", alice);
return match Url::parse(homeserver) {
Err(e) => panic!("Invalid homeserver url: {}", e),
Ok(homeserver_url) => {
println!("Try to login to: {}", homeserver_url);
let client = Client::new(homeserver_url)?;
client
.login(alice.localpart(), user_token, None, Some("Test BOT"))
.await?;
println!("Logged in! Try to register event handler");
client
.register_event_handler(|ev: SyncMessageEvent<MessageEventContent>| async move {
println!("Received a message {:?}", ev);
})
.await;
client.sync(SyncSettings::default()).await; // Should never return
Ok(())
}
};
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter