|
@@ -16,7 +16,6 @@ use std::sync::{
|
|
|
use teloxide::types::*;
|
|
use teloxide::types::*;
|
|
|
use teloxide::{
|
|
use teloxide::{
|
|
|
dispatching::dialogue::{InMemStorage, Storage},
|
|
dispatching::dialogue::{InMemStorage, Storage},
|
|
|
- macros::DialogueState,
|
|
|
|
|
net::Download,
|
|
net::Download,
|
|
|
prelude::*,
|
|
prelude::*,
|
|
|
types::File as TgFile,
|
|
types::File as TgFile,
|
|
@@ -69,7 +68,10 @@ enum FileConvertError {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[derive(BotCommands, Debug)]
|
|
#[derive(BotCommands, Debug)]
|
|
|
-#[command(rename = "lowercase", description = "These commands are supported:")]
|
|
|
|
|
|
|
+#[command(
|
|
|
|
|
+ rename_rule = "lowercase",
|
|
|
|
|
+ description = "These commands are supported:"
|
|
|
|
|
+)]
|
|
|
enum Command {
|
|
enum Command {
|
|
|
#[command(description = "display this text.")]
|
|
#[command(description = "display this text.")]
|
|
|
Help,
|
|
Help,
|
|
@@ -92,14 +94,12 @@ async fn download_file(
|
|
|
downloader: &AutoSend<Bot>,
|
|
downloader: &AutoSend<Bot>,
|
|
|
file_id: &str,
|
|
file_id: &str,
|
|
|
) -> Result<String, FileReceiveError> {
|
|
) -> Result<String, FileReceiveError> {
|
|
|
- let TgFile {
|
|
|
|
|
- file_id, file_path, ..
|
|
|
|
|
- } = downloader.get_file(file_id).send().await?;
|
|
|
|
|
|
|
+ let TgFile { path, .. } = downloader.get_file(file_id).send().await?;
|
|
|
log::info!("Attempt to download file");
|
|
log::info!("Attempt to download file");
|
|
|
let filepath = format!("/tmp/{}", file_id);
|
|
let filepath = format!("/tmp/{}", file_id);
|
|
|
log::info!("Path: {}", filepath);
|
|
log::info!("Path: {}", filepath);
|
|
|
let mut file = File::create(&filepath).await?;
|
|
let mut file = File::create(&filepath).await?;
|
|
|
- downloader.download_file(&file_path, &mut file).await?;
|
|
|
|
|
|
|
+ downloader.download_file(&path, &mut file).await?;
|
|
|
Ok(filepath)
|
|
Ok(filepath)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -253,7 +253,7 @@ async fn handle_json(
|
|
|
log::info!("It's message");
|
|
log::info!("It's message");
|
|
|
if let MediaKind::Document(doc) = &msg.media_kind {
|
|
if let MediaKind::Document(doc) = &msg.media_kind {
|
|
|
is_file = true;
|
|
is_file = true;
|
|
|
- file_id = String::from_str(&doc.document.file_id).unwrap_or("".to_string());
|
|
|
|
|
|
|
+ file_id = String::from_str(&doc.document.file.id).unwrap_or("".to_string());
|
|
|
log::info!("It's file with id {:}", file_id);
|
|
log::info!("It's file with id {:}", file_id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -279,8 +279,11 @@ async fn handle_json(
|
|
|
let mut i = non_cat_items(&newfile, &user);
|
|
let mut i = non_cat_items(&newfile, &user);
|
|
|
if let Some(item) = i.pop() {
|
|
if let Some(item) = i.pop() {
|
|
|
log::info!("No category for {}", &item);
|
|
log::info!("No category for {}", &item);
|
|
|
- bot.send_message(msg.chat.id, format!("Select category for {}", item))
|
|
|
|
|
- .await?;
|
|
|
|
|
|
|
+ bot.send_message(
|
|
|
|
|
+ msg.chat.id,
|
|
|
|
|
+ format!("Input category to search for {}", item),
|
|
|
|
|
+ )
|
|
|
|
|
+ .await?;
|
|
|
dialogue
|
|
dialogue
|
|
|
.update(State::CategorySelect { filename, item })
|
|
.update(State::CategorySelect { filename, item })
|
|
|
.await?;
|
|
.await?;
|
|
@@ -301,6 +304,11 @@ async fn handle_category(
|
|
|
"Expenses:Alco".to_string(),
|
|
"Expenses:Alco".to_string(),
|
|
|
"Expenses:Groceries".to_string(),
|
|
"Expenses:Groceries".to_string(),
|
|
|
];
|
|
];
|
|
|
|
|
+ let userid = if let Some(user) = msg.from() {
|
|
|
|
|
+ user.id.0
|
|
|
|
|
+ } else {
|
|
|
|
|
+ 0
|
|
|
|
|
+ };
|
|
|
let keyboard = InlineKeyboardMarkup::default().append_row(
|
|
let keyboard = InlineKeyboardMarkup::default().append_row(
|
|
|
accounts
|
|
accounts
|
|
|
.iter()
|
|
.iter()
|
|
@@ -568,7 +576,7 @@ async fn callback_handler(
|
|
|
|
|
|
|
|
#[cfg(feature = "telegram")]
|
|
#[cfg(feature = "telegram")]
|
|
|
async fn run() {
|
|
async fn run() {
|
|
|
- teloxide::enable_logging!();
|
|
|
|
|
|
|
+ // teloxide::enable_logging!();
|
|
|
log::info!("Starting telegram bot");
|
|
log::info!("Starting telegram bot");
|
|
|
IS_RUNNING.store(true, Ordering::SeqCst);
|
|
IS_RUNNING.store(true, Ordering::SeqCst);
|
|
|
let (tx, mut rx) = mpsc::channel(32);
|
|
let (tx, mut rx) = mpsc::channel(32);
|
|
@@ -584,7 +592,10 @@ async fn run() {
|
|
|
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
|
.enter_dialogue::<Message, InMemStorage<State>, State>()
|
|
|
.branch(teloxide::handler![State::Idle].endpoint(handle_idle))
|
|
.branch(teloxide::handler![State::Idle].endpoint(handle_idle))
|
|
|
// No idea about `{filename, }`, but otherwise thread "'tokio-runtime-worker' panicked at '(alloc::string::String,) was requested, but not provided."
|
|
// No idea about `{filename, }`, but otherwise thread "'tokio-runtime-worker' panicked at '(alloc::string::String,) was requested, but not provided."
|
|
|
- .branch(teloxide::handler![State::NewJson { filename }].endpoint(handle_json))
|
|
|
|
|
|
|
+ .branch(
|
|
|
|
|
+ #[rustfmt::skip]
|
|
|
|
|
+ teloxide::handler![State::NewJson { filename, }].endpoint(handle_json),
|
|
|
|
|
+ )
|
|
|
.branch(
|
|
.branch(
|
|
|
teloxide::handler![State::CategorySelect { filename, item }]
|
|
teloxide::handler![State::CategorySelect { filename, item }]
|
|
|
.endpoint(handle_category),
|
|
.endpoint(handle_category),
|
|
@@ -612,43 +623,13 @@ async fn run() {
|
|
|
.enter_dialogue::<CallbackQuery, InMemStorage<State>, State>()
|
|
.enter_dialogue::<CallbackQuery, InMemStorage<State>, State>()
|
|
|
.endpoint(callback_handler),
|
|
.endpoint(callback_handler),
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
Dispatcher::builder(bot, handler)
|
|
Dispatcher::builder(bot, handler)
|
|
|
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
|
.dependencies(dptree::deps![InMemStorage::<State>::new()])
|
|
|
.build()
|
|
.build()
|
|
|
.setup_ctrlc_handler()
|
|
.setup_ctrlc_handler()
|
|
|
.dispatch()
|
|
.dispatch()
|
|
|
.await;
|
|
.await;
|
|
|
- /*
|
|
|
|
|
- // TODO: Add Dispatcher to process UpdateKinds
|
|
|
|
|
- Dispatcher::new(bot)
|
|
|
|
|
- .messages_handler(DialogueDispatcher::with_storage(
|
|
|
|
|
- move |DialogueWithCx { cx, dialogue }: In| {
|
|
|
|
|
- let _tx = tx.clone();
|
|
|
|
|
- async move {
|
|
|
|
|
- let dialogue = dialogue.expect("std::convert::Infallible");
|
|
|
|
|
- handle_message(cx, dialogue, _tx)
|
|
|
|
|
- .await
|
|
|
|
|
- .expect("Something wrong with the bot!")
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- storage.clone(),
|
|
|
|
|
- ))
|
|
|
|
|
- .callback_queries_handler({
|
|
|
|
|
- move |rx: DispatcherHandlerRx<AutoSend<Bot>, CallbackQuery>| {
|
|
|
|
|
- UnboundedReceiverStream::new(rx).for_each_concurrent(None, {
|
|
|
|
|
- move |cx| {
|
|
|
|
|
- let storage = storage.clone();
|
|
|
|
|
- async move {
|
|
|
|
|
- callback_handler(cx, storage).await.log_on_error().await;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .dispatch()
|
|
|
|
|
- .await;
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
drop(manager);
|
|
drop(manager);
|
|
|
IS_RUNNING.store(false, Ordering::SeqCst);
|
|
IS_RUNNING.store(false, Ordering::SeqCst);
|
|
|
}
|
|
}
|