mirror of
https://github.com/house-of-vanity/desubot.git
synced 2025-07-07 04:34:07 +00:00
add_user, add_group features.
This commit is contained in:
29
src/main.rs
29
src/main.rs
@ -6,17 +6,16 @@ use telegram_bot::*;
|
||||
|
||||
mod commands;
|
||||
mod db;
|
||||
mod errors;
|
||||
mod utils;
|
||||
|
||||
async fn handler(api: Api, message: Message) -> Result<(), Error> {
|
||||
match message.kind {
|
||||
MessageKind::Text { ref data, .. } => {
|
||||
let title = match &message.chat {
|
||||
MessageChat::Supergroup(chat) => &chat.title,
|
||||
_ => "test",
|
||||
};
|
||||
let title = utils::get_title(&message);
|
||||
|
||||
println!(
|
||||
"<{}>[{}::{}({})]: {}",
|
||||
"<{}({})>[{}({})]: {}",
|
||||
&message.chat.id(),
|
||||
title,
|
||||
&message.from.id,
|
||||
@ -25,7 +24,6 @@ async fn handler(api: Api, message: Message) -> Result<(), Error> {
|
||||
);
|
||||
match data.as_str() {
|
||||
"/here" => commands::here(api, message).await?,
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@ -36,13 +34,7 @@ async fn handler(api: Api, message: Message) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Error> {
|
||||
/*
|
||||
println!("get_user: {:?}", db::get_user(1228494339));
|
||||
println!("get_confs: {:?}", db::get_confs());
|
||||
println!("get_members: {:?}", db::get_members(-1001233797421));
|
||||
|
||||
*/
|
||||
async fn main() -> Result<(), errors::Error> {
|
||||
let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
|
||||
let api = Api::new(token);
|
||||
|
||||
@ -52,16 +44,11 @@ async fn main() -> Result<(), Error> {
|
||||
// If the received update contains a new message...
|
||||
let update = update?;
|
||||
if let UpdateKind::Message(message) = update.kind {
|
||||
db::add_user(api.clone(), message.clone()).await?;
|
||||
db::add_conf(api.clone(), message.clone()).await?;
|
||||
|
||||
handler(api.clone(), message).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
/*
|
||||
{ id: MessageId(94793), from:
|
||||
User { id: UserId(124317807), first_name: "Холм", last_name: Some("Вечный"), username: Some("ultradesu"), is_bot: false, language_code: Some("en") },
|
||||
date: 1606564847,
|
||||
chat: Supergroup(Supergroup { id: SupergroupId(-1001233797421), title: "Квантовый Аллах", username: None, invite_link: None }),
|
||||
forward: None, reply_to_message: None, edit_date: None, kind: Text { data: "пук", entities: [] }
|
||||
|
||||
*/
|
||||
|
Reference in New Issue
Block a user