This commit is contained in:
Listum 2023-10-31 04:07:23 +03:00
parent bb6814acfe
commit 4e02fecd97
4 changed files with 1682 additions and 0 deletions

1624
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

14
Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
name = "aur_builder"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
teloxide = { version = "0.12.2", features = ["macros"] }
tokio = { version = "1", features = ["full"] }
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
aur-rpc = "0.2.2"

9
src/main.rs Normal file
View File

@ -0,0 +1,9 @@
mod telegram;
use teloxide;
#[tokio::main]
async fn main() {
telegram::main(teloxide::Bot::from_env()).await;
}

35
src/telegram.rs Normal file
View File

@ -0,0 +1,35 @@
use teloxide::{prelude::*, utils::command::BotCommands};
use aur_rpc;
pub async fn main(bot: Bot){
Command::repl(bot, answer).await;
}
#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Commands:")]
enum Command{
Upload(String),
Clean,
Search(String)
}
async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
match cmd {
Command::Upload(url) => {
bot.send_message(msg.chat.id, format!("Test {}", url)).await?;
}
Command::Clean => {
bot.send_message(msg.chat.id, format!("Done")).await?;
}
Command::Search(name) => {
let packages = aur_rpc::search(format!("{}", name)).await.unwrap();
let mut sorted_packages = packages;
sorted_packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes));
let mut result:Vec<String> = Vec::new();
for (index, package) in sorted_packages.iter().enumerate().take(10) {
result.push(format!("{}. {}\n", index+1, package.name));
}
bot.send_message(msg.chat.id, format!("{}", result.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(""))).await?;
}
}
Ok(())
}