Files
rustspace/alterego/src/main.rs
2023-02-26 17:59:35 +03:00

71 lines
1.6 KiB
Rust

use alterego::telegram;
use tokio::runtime;
const BOT_TOKEN: &str = "170515067:AAElDJ8Sq_oIqo9WaL4DKvUr13nSEIdHCYs";
fn main() -> anyhow::Result<()> {
println!("Hello, world!");
let rt = runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.expect("making runtime");
rt.block_on(app())?;
Ok(())
}
use futures::StreamExt;
async fn app() -> anyhow::Result<()> {
let bot = telegram::bot::Client::new(BOT_TOKEN.to_owned());
let mut stream = bot.updates_stream();
while let Some(update) = stream.next().await {
let update = update?;
println!("{:?}", update);
handle_update(update);
}
Ok(())
}
use log::{debug, trace, warn};
use telegram::types::UpdateKind;
fn handle_update(update: telegram::types::Update) {
match update.kind {
UpdateKind::Message(msg) => {
let text = msg.text.unwrap_or_default();
if !text.starts_with('/') {
trace!("it's not a command, skipping");
return;
}
match text.as_str() {
"/help" => {
println!("help command called");
}
"/temp" => {
println!("temp command called");
}
"/versionrequest" => {}
other => {
println!("unknown command {}", other);
}
}
}
UpdateKind::EditedMessage(msg) => {
debug!("edited message: {:?}", msg);
}
UpdateKind::Undefined => {
warn!("message udentified");
}
}
}