initial commit
This commit is contained in:
70
alterego/src/main.rs
Normal file
70
alterego/src/main.rs
Normal file
@ -0,0 +1,70 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user