rustfmt
This commit is contained in:
parent
f5deffc3b3
commit
c977500ee4
24
src/db.rs
24
src/db.rs
@ -75,7 +75,11 @@ impl DB {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_message(&mut self, chatid: i64, messageid: i32) -> Result<Option<Message>, Box<dyn std::error::Error>> {
|
||||
pub async fn get_message(
|
||||
&mut self,
|
||||
chatid: i64,
|
||||
messageid: i32,
|
||||
) -> Result<Option<Message>, Box<dyn std::error::Error>> {
|
||||
use self::schema::messages::dsl::*;
|
||||
let conn = &mut self.pool.get().await.unwrap();
|
||||
|
||||
@ -89,12 +93,21 @@ impl DB {
|
||||
Ok(msg)
|
||||
}
|
||||
|
||||
pub async fn get_message_literal(&mut self, chatid: i64, messageid: i32) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
||||
pub async fn get_message_literal(
|
||||
&mut self,
|
||||
chatid: i64,
|
||||
messageid: i32,
|
||||
) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
||||
let msg = self.get_message(chatid, messageid).await?;
|
||||
Ok(msg.map(|m| m.token))
|
||||
}
|
||||
|
||||
pub async fn set_message_literal(&mut self, chatid: i64, messageid: i32, literal: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub async fn set_message_literal(
|
||||
&mut self,
|
||||
chatid: i64,
|
||||
messageid: i32,
|
||||
literal: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
use self::schema::messages::dsl::*;
|
||||
let conn = &mut self.pool.get().await?;
|
||||
|
||||
@ -107,20 +120,19 @@ impl DB {
|
||||
.set(token.eq(literal))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
},
|
||||
}
|
||||
None => {
|
||||
diesel::insert_into(messages)
|
||||
.values((
|
||||
chat_id.eq(chatid),
|
||||
message_id.eq(messageid as i64),
|
||||
token.eq(literal)
|
||||
token.eq(literal),
|
||||
))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
#![allow(unused)]
|
||||
#![allow(clippy::all)]
|
||||
|
||||
|
||||
use diesel::prelude::*;
|
||||
#[derive(Queryable, Debug)]
|
||||
#[diesel(table_name = literals)]
|
||||
@ -28,4 +27,3 @@ pub struct User {
|
||||
pub id: i64,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
|
||||
|
||||
@ -26,8 +26,4 @@ diesel::table! {
|
||||
}
|
||||
}
|
||||
|
||||
diesel::allow_tables_to_appear_in_same_query!(
|
||||
literals,
|
||||
messages,
|
||||
users,
|
||||
);
|
||||
diesel::allow_tables_to_appear_in_same_query!(literals, messages, users,);
|
||||
|
||||
19
src/main.rs
19
src/main.rs
@ -56,13 +56,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
eprintln!("{u:#?}"); // Print the update to the console with inspect
|
||||
})
|
||||
.branch(command_handler(config))
|
||||
.branch(Update::filter_message()
|
||||
.branch(
|
||||
Update::filter_message()
|
||||
.filter_async(async |msg: Message, mut db: DB| {
|
||||
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
||||
user.is_admin
|
||||
})
|
||||
.filter(|msg: Message| msg == "edit")
|
||||
.endpoint(edit_msg_handler)
|
||||
.endpoint(edit_msg_handler),
|
||||
)
|
||||
.branch(Update::filter_message().endpoint(echo));
|
||||
|
||||
@ -81,15 +82,23 @@ async fn edit_msg_handler(bot: Bot, msg: Message) -> Result<(), teloxide::Reques
|
||||
Some(replied) => {
|
||||
let msgid = replied.id;
|
||||
// look for message in db and set text
|
||||
},
|
||||
}
|
||||
None => {
|
||||
bot.send_message(msg.chat.id, "You have to reply to message to edit it").await?;
|
||||
bot.send_message(msg.chat.id, "You have to reply to message to edit it")
|
||||
.await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn command_handler(config: Config) -> Handler<'static, DependencyMap, Result<(), teloxide::RequestError>, teloxide::dispatching::DpHandlerDescription> {
|
||||
fn command_handler(
|
||||
config: Config,
|
||||
) -> Handler<
|
||||
'static,
|
||||
DependencyMap,
|
||||
Result<(), teloxide::RequestError>,
|
||||
teloxide::dispatching::DpHandlerDescription,
|
||||
> {
|
||||
Update::filter_message()
|
||||
.branch(
|
||||
dptree::entry()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user