/command now downloads git repo

This commit is contained in:
Listum 2023-11-02 05:37:45 +03:00
parent 4e02fecd97
commit a10f526426
3 changed files with 84 additions and 10 deletions

66
Cargo.lock generated
View File

@ -47,6 +47,7 @@ name = "aur_builder"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"aur-rpc", "aur-rpc",
"git2",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
@ -111,6 +112,7 @@ version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [ dependencies = [
"jobserver",
"libc", "libc",
] ]
@ -385,6 +387,21 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "git2"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd"
dependencies = [
"bitflags 2.4.1",
"libc",
"libgit2-sys",
"log",
"openssl-probe",
"openssl-sys",
"url",
]
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.21" version = "0.3.21"
@ -540,6 +557,15 @@ version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "jobserver"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.64" version = "0.3.64"
@ -561,6 +587,46 @@ version = "0.2.149"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "libgit2-sys"
version = "0.16.1+1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a2bb3680b094add03bb3732ec520ece34da31a8cd2d633d1389d0f0fb60d0c"
dependencies = [
"cc",
"libc",
"libssh2-sys",
"libz-sys",
"openssl-sys",
"pkg-config",
]
[[package]]
name = "libssh2-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee"
dependencies = [
"cc",
"libc",
"libz-sys",
"openssl-sys",
"pkg-config",
"vcpkg",
]
[[package]]
name = "libz-sys"
version = "1.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.10" version = "0.4.10"

View File

@ -12,3 +12,4 @@ reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
aur-rpc = "0.2.2" aur-rpc = "0.2.2"
git2 = "0.18.1"

View File

@ -1,5 +1,7 @@
use teloxide::{prelude::*, utils::command::BotCommands}; use teloxide::{prelude::*, utils::command::BotCommands};
use aur_rpc; use aur_rpc;
use git2::Repository;
pub async fn main(bot: Bot){ pub async fn main(bot: Bot){
Command::repl(bot, answer).await; Command::repl(bot, answer).await;
@ -14,21 +16,26 @@ enum Command{
} }
async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> { async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
match cmd { match cmd {
Command::Upload(url) => { Command::Upload(pkg) => {
bot.send_message(msg.chat.id, format!("Test {}", url)).await?; let repo = format!("https://aur.archlinux.org/{}.git", pkg);
let dir = format!("pkgs/{}", pkg);
match Repository::clone(repo.as_str(), dir.as_str()) {
Ok(_) => bot.send_message(msg.chat.id, format!("Succsess {}", pkg)).await?,
Err(e) => bot.send_message(msg.chat.id, format!("Error: {}", e)).await?,
};
} }
Command::Clean => { Command::Clean => {
bot.send_message(msg.chat.id, format!("Done")).await?; bot.send_message(msg.chat.id, format!("Done")).await?;
} }
Command::Search(name) => { Command::Search(name) => {
let packages = aur_rpc::search(format!("{}", name)).await.unwrap(); let mut packages = aur_rpc::search(format!("{}", name)).await.unwrap();
let mut sorted_packages = packages; packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes));
sorted_packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes)); let mut result = Vec::new();
let mut result:Vec<String> = Vec::new(); for (index, package) in packages.iter().enumerate().take(10) {
for (index, package) in sorted_packages.iter().enumerate().take(10) { result.push(format!("{}. {}", index+1, package.name));
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?; bot.send_message(msg.chat.id, format!("{}", result.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("\n"))).await?;
} }
} }
Ok(()) Ok(())