2020-10-17 15:47:17 +00:00
|
|
|
use chronicle_dicebot::commands;
|
2021-01-30 14:17:34 +00:00
|
|
|
use chronicle_dicebot::commands::ResponseExtractor;
|
2021-01-29 22:35:07 +00:00
|
|
|
use chronicle_dicebot::context::{Context, RoomContext};
|
2020-10-15 16:52:08 +00:00
|
|
|
use chronicle_dicebot::db::Database;
|
|
|
|
use chronicle_dicebot::error::BotError;
|
2021-01-29 22:35:07 +00:00
|
|
|
use matrix_sdk::identifiers::room_id;
|
2020-04-21 03:15:13 +00:00
|
|
|
|
2020-10-17 15:47:17 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), BotError> {
|
2020-10-15 16:52:08 +00:00
|
|
|
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) {
|
2020-10-15 16:52:08 +00:00
|
|
|
Ok(command) => command,
|
|
|
|
Err(e) => return Err(e),
|
2020-04-21 03:15:13 +00:00
|
|
|
};
|
2020-10-15 16:52:08 +00:00
|
|
|
|
2020-11-22 20:52:44 +00:00
|
|
|
let context = Context {
|
2020-11-29 21:03:45 +00:00
|
|
|
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"),
|
2021-01-29 22:35:07 +00:00
|
|
|
room: RoomContext {
|
|
|
|
id: &room_id!("!fakeroomid:example.com"),
|
|
|
|
display_name: "fake room",
|
|
|
|
},
|
2020-11-22 20:52:44 +00:00
|
|
|
username: "@localuser:example.com",
|
|
|
|
message_body: &input,
|
|
|
|
};
|
|
|
|
|
2021-01-31 14:06:25 +00:00
|
|
|
let message = command.execute(&context).await.message_html("fakeuser");
|
|
|
|
let message = html2text::from_read(message.as_bytes(), 80);
|
|
|
|
println!("{}", message.trim());
|
2020-04-21 03:15:13 +00:00
|
|
|
Ok(())
|
|
|
|
}
|