dev #25
34
src/main.rs
34
src/main.rs
@ -11,16 +11,13 @@ pub mod utils;
|
|||||||
|
|
||||||
use bot_manager::BotManager;
|
use bot_manager::BotManager;
|
||||||
use botscript::application::attach_user_application;
|
use botscript::application::attach_user_application;
|
||||||
use botscript::{BotMessage, Runner, RunnerConfig, ScriptError, ScriptResult};
|
use botscript::{Runner, RunnerConfig, ScriptError, ScriptResult};
|
||||||
use db::application::Application;
|
use db::application::Application;
|
||||||
use db::bots::BotInstance;
|
use db::bots::BotInstance;
|
||||||
use db::callback_info::CallbackInfo;
|
use db::callback_info::CallbackInfo;
|
||||||
use db::message_forward::MessageForward;
|
|
||||||
use handlers::admin::admin_handler;
|
use handlers::admin::admin_handler;
|
||||||
use log::{error, info, warn};
|
use log::{error, info};
|
||||||
use message_answerer::MessageAnswerer;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
|
||||||
use utils::create_callback_button;
|
|
||||||
|
|
||||||
use crate::db::{CallDB, DB};
|
use crate::db::{CallDB, DB};
|
||||||
use crate::mongodb_storage::MongodbStorage;
|
use crate::mongodb_storage::MongodbStorage;
|
||||||
@ -29,13 +26,8 @@ use db::DbError;
|
|||||||
use envconfig::Envconfig;
|
use envconfig::Envconfig;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use teloxide::dispatching::dialogue::serializer::Json;
|
use teloxide::dispatching::dialogue::serializer::Json;
|
||||||
use teloxide::dispatching::dialogue::{GetChatId, Serializer};
|
use teloxide::dispatching::dialogue::Serializer;
|
||||||
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};
|
use teloxide::prelude::*;
|
||||||
use teloxide::{
|
|
||||||
payloads::SendMessageSetters,
|
|
||||||
prelude::*,
|
|
||||||
utils::{command::BotCommands, render::RenderMessageTextHelper},
|
|
||||||
};
|
|
||||||
|
|
||||||
type BotDialogue = Dialogue<State, MongodbStorage<Json>>;
|
type BotDialogue = Dialogue<State, MongodbStorage<Json>>;
|
||||||
|
|
||||||
@ -172,6 +164,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mut db = DB::init(&config.db_url, config.bot_name.to_owned()).await?;
|
let mut db = DB::init(&config.db_url, config.bot_name.to_owned()).await?;
|
||||||
|
|
||||||
BotInstance::restart_all(&mut db, false).await?;
|
BotInstance::restart_all(&mut db, false).await?;
|
||||||
|
// if we can't get info for main bot, we should stop anyway
|
||||||
|
#[allow(clippy::unwrap_used)]
|
||||||
let bm = BotManager::with(
|
let bm = BotManager::with(
|
||||||
async || {
|
async || {
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
@ -188,7 +182,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
BotInstance::restart_all(&mut db, false).await.unwrap();
|
BotInstance::restart_all(&mut db, false).await.unwrap();
|
||||||
std::iter::once(bi).chain(instances)
|
std::iter::once(bi).chain(instances)
|
||||||
},
|
},
|
||||||
async |bi| vec![admin_handler()].into_iter(),
|
async |_| vec![admin_handler()].into_iter(),
|
||||||
);
|
);
|
||||||
|
|
||||||
bm.dispatch(&mut db).await;
|
bm.dispatch(&mut db).await;
|
||||||
@ -218,9 +212,9 @@ async fn send_application_to_chat(
|
|||||||
app.from
|
app.from
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
return Err(BotError::AdminMisconfiguration(format!(
|
return Err(BotError::AdminMisconfiguration(
|
||||||
"admin forget to set support_chat_id"
|
"admin forget to set support_chat_id".to_string(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let msg = match db.get_literal_value("application_format").await? {
|
let msg = match db.get_literal_value("application_format").await? {
|
||||||
@ -236,9 +230,9 @@ async fn send_application_to_chat(
|
|||||||
),
|
),
|
||||||
None => {
|
None => {
|
||||||
notify_admin("format for support_chat_id is not set").await;
|
notify_admin("format for support_chat_id is not set").await;
|
||||||
return Err(BotError::AdminMisconfiguration(format!(
|
return Err(BotError::AdminMisconfiguration(
|
||||||
"admin forget to set application_format"
|
"admin forget to set application_format".to_string(),
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user