tenebrous-dicebot/src/bin/dicebot-cmd.rs

37 lines
1008 B
Rust
Raw Normal View History

2020-10-17 15:47:17 +00:00
use chronicle_dicebot::commands;
use chronicle_dicebot::context::Context;
use chronicle_dicebot::db::Database;
use chronicle_dicebot::error::BotError;
use matrix_sdk::{
identifiers::{room_id, user_id},
Room,
};
fn dummy_room() -> Room {
Room::new(
&room_id!("!fakeroomid:example.com"),
&user_id!("@fakeuserid:example.com"),
)
}
2020-10-17 15:47:17 +00:00
#[tokio::main]
async fn main() -> Result<(), BotError> {
let input = std::env::args().skip(1).collect::<Vec<String>>().join(" ");
2020-11-12 21:05:14 +00:00
let command = match commands::parser::parse_command(&input) {
Ok(command) => command,
Err(e) => return Err(e),
};
2020-11-22 20:52:44 +00:00
let context = Context {
db: Database::new_temp()?,
2020-11-22 20:52:44 +00:00
matrix_client: &matrix_sdk::Client::new("http://example.com")
.expect("Could not create matrix client"),
room: &dummy_room(),
2020-11-22 20:52:44 +00:00
username: "@localuser:example.com",
message_body: &input,
};
2020-10-17 15:47:17 +00:00
println!("{}", command.execute(&context).await.plain());
Ok(())
}