dev #25
@ -178,12 +178,9 @@ pub async fn admin_command_handler(
|
||||
}
|
||||
};
|
||||
|
||||
let bi =
|
||||
BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string())
|
||||
.store(&mut db)
|
||||
.await?;
|
||||
|
||||
bi
|
||||
BotInstance::new(name.clone(), token.to_string(), DEFAULT_SCRIPT.to_string())
|
||||
.store(&mut db)
|
||||
.await?
|
||||
};
|
||||
|
||||
bot.send_message(
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
use futures::future::join_all;
|
||||
use log::{error, info};
|
||||
use quickjs_rusty::serde::{from_js, to_js};
|
||||
use quickjs_rusty::serde::to_js;
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
str::FromStr,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use teloxide::{
|
||||
dispatching::{dialogue::GetChatId, UpdateFilterExt},
|
||||
dptree::{self, Handler},
|
||||
prelude::{DependencyMap, Requester},
|
||||
types::{CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, Update},
|
||||
types::{CallbackQuery, InlineKeyboardMarkup, Message, Update},
|
||||
Bot,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
botscript::{self, message_info::MessageInfoBuilder, BotMessage, RunnerConfig},
|
||||
botscript::{self, message_info::MessageInfoBuilder, BotMessage},
|
||||
commands::BotCommand,
|
||||
db::{callback_info::CallbackInfo, CallDB, DB},
|
||||
message_answerer::MessageAnswerer,
|
||||
@ -108,7 +108,7 @@ async fn handle_botmessage(bot: Bot, mut db: DB, bm: BotMessage, msg: Message) -
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
if bm.meta() == true {
|
||||
if bm.meta() {
|
||||
if let Some(ref meta) = variant {
|
||||
user.insert_meta(&mut db, meta).await?;
|
||||
};
|
||||
@ -193,8 +193,7 @@ async fn handle_botmessage(bot: Bot, mut db: DB, bm: BotMessage, msg: Message) -
|
||||
let literal = bm.literal().map_or("", |s| s.as_str());
|
||||
|
||||
let ma = MessageAnswerer::new(&bot, &mut db, msg.chat.id.0);
|
||||
ma.answer(literal, variant.as_ref().map(|v| v.as_str()), buttons)
|
||||
.await?;
|
||||
ma.answer(literal, variant.as_deref(), buttons).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1,28 +1,20 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
future::Future,
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
sync::{Arc, Mutex},
|
||||
thread::JoinHandle,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, info};
|
||||
use teloxide::{
|
||||
dispatching::dialogue::serializer::Json,
|
||||
dptree,
|
||||
prelude::{Dispatcher, Requester},
|
||||
types::{ChatId, UserId},
|
||||
Bot,
|
||||
};
|
||||
use tokio::runtime::Handle;
|
||||
use teloxide::{dispatching::dialogue::serializer::Json, dptree, prelude::Dispatcher, Bot};
|
||||
|
||||
use crate::{
|
||||
bot_handler::{script_handler, BotHandler},
|
||||
db::{bots::BotInstance, DbError, DB},
|
||||
message_answerer::MessageAnswerer,
|
||||
mongodb_storage::MongodbStorage,
|
||||
BotController, BotError, BotResult, BotRuntime,
|
||||
BotController, BotResult, BotRuntime,
|
||||
};
|
||||
|
||||
pub struct BotRunner {
|
||||
@ -235,7 +227,7 @@ pub async fn spawn_notificator_thread(
|
||||
Some(n) => {
|
||||
// waiting time to send notification
|
||||
tokio::time::sleep(n.wait_for()).await;
|
||||
'n: for n in n.notifications().into_iter() {
|
||||
'n: for n in n.notifications().iter() {
|
||||
for user in n.get_users(&c.db).await?.into_iter() {
|
||||
let text = match n.resolve_message(&c.db, &user).await? {
|
||||
Some(text) => text,
|
||||
|
||||
@ -2,7 +2,7 @@ pub mod application;
|
||||
pub mod db;
|
||||
pub mod message_info;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex, PoisonError};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::db::raw_calls::RawCallError;
|
||||
@ -12,7 +12,6 @@ use crate::utils::parcelable::{ParcelType, Parcelable, ParcelableError, Parcelab
|
||||
use chrono::{DateTime, Days, NaiveTime, ParseError, TimeDelta, Timelike, Utc};
|
||||
use db::attach_db_obj;
|
||||
use futures::future::join_all;
|
||||
use futures::lock::MutexGuard;
|
||||
use itertools::Itertools;
|
||||
use quickjs_rusty::serde::{from_js, to_js};
|
||||
use quickjs_rusty::utils::create_empty_object;
|
||||
@ -543,7 +542,8 @@ impl BotMessage {
|
||||
pub fn update_defaults(self) -> Self {
|
||||
let bm = self;
|
||||
// if message is `start`, defaulting meta to true, if not set
|
||||
let bm = match bm.meta {
|
||||
|
||||
match bm.meta {
|
||||
Some(_) => bm,
|
||||
None => match &bm.literal {
|
||||
Some(l) if l == "start" => Self {
|
||||
@ -552,9 +552,7 @@ impl BotMessage {
|
||||
},
|
||||
_ => bm,
|
||||
},
|
||||
};
|
||||
|
||||
bm
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_replace(&self) -> bool {
|
||||
@ -1062,7 +1060,7 @@ impl Runner {
|
||||
#[allow(clippy::unwrap_used)]
|
||||
#[allow(clippy::print_stdout)]
|
||||
mod tests {
|
||||
use quickjs_rusty::{serde::from_js, OwnedJsObject};
|
||||
use quickjs_rusty::OwnedJsObject;
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -6,9 +6,9 @@ use teloxide::Bot;
|
||||
use tokio::runtime::Handle;
|
||||
|
||||
use crate::{
|
||||
db::{application::Application, message_forward::MessageForward, CallDB, DB},
|
||||
db::{application::Application, message_forward::MessageForward, DB},
|
||||
message_answerer::MessageAnswerer,
|
||||
send_application_to_chat, BotError,
|
||||
send_application_to_chat,
|
||||
};
|
||||
|
||||
use super::ScriptError;
|
||||
|
||||
@ -9,6 +9,12 @@ pub struct MessageInfoBuilder {
|
||||
inner: MessageInfo,
|
||||
}
|
||||
|
||||
impl Default for MessageInfoBuilder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageInfoBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
use bson::doc;
|
||||
use bson::oid::ObjectId;
|
||||
use chrono::{DateTime, FixedOffset, Local};
|
||||
use futures::StreamExt;
|
||||
use futures::TryStreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ pub mod raw_calls;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, FixedOffset, Local, Utc};
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use enum_stringify::EnumStringify;
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
|
||||
@ -177,7 +177,7 @@ async fn test_drop_media_except() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_random_users() {
|
||||
let mut db = setup_db().await;
|
||||
let db = setup_db().await;
|
||||
|
||||
let users = db.get_random_users(1).await.unwrap();
|
||||
assert_eq!(users.len(), 1);
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use itertools::Itertools;
|
||||
use log::{info, warn};
|
||||
use std::time::Duration;
|
||||
@ -108,15 +106,15 @@ async fn newscript_handler(bot: Bot, mut db: DB, msg: Message, name: String) ->
|
||||
let mut bytes = bytes.unwrap().to_vec();
|
||||
buf.append(&mut bytes);
|
||||
}
|
||||
let script = match String::from_utf8(buf) {
|
||||
|
||||
match String::from_utf8(buf) {
|
||||
Ok(s) => s,
|
||||
Err(err) => {
|
||||
warn!("Failed to parse buf to string, err: {err}");
|
||||
bot.send_message(msg.chat.id, format!("Failed to Convert file to script: file is not UTF-8, err: {err}")).await?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
script
|
||||
}
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
@ -129,7 +127,7 @@ async fn newscript_handler(bot: Bot, mut db: DB, msg: Message, name: String) ->
|
||||
None => {
|
||||
bot.send_message(
|
||||
msg.chat.id,
|
||||
format!("Failed to set script, possibly bots name is incorrent"),
|
||||
"Failed to set script, possibly bots name is incorrent".to_string(),
|
||||
)
|
||||
.await?;
|
||||
return Ok(());
|
||||
|
||||
@ -85,7 +85,7 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use teloxide::types::InlineKeyboardButton;
|
||||
use teloxide::types::InlineKeyboardMarkup;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user