From 905540e858e6381216303ae2c927d5a91be8fb3c Mon Sep 17 00:00:00 2001 From: Listum Date: Thu, 2 Nov 2023 07:33:42 +0300 Subject: [PATCH] Now bot compile downloaded sources --- src/telegram.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/telegram.rs b/src/telegram.rs index ae10bcf..2f61ea7 100644 --- a/src/telegram.rs +++ b/src/telegram.rs @@ -1,34 +1,46 @@ use teloxide::{prelude::*, utils::command::BotCommands}; use aur_rpc; use git2::Repository; +use std::process::Command; +use std::env; pub async fn main(bot: Bot){ - Command::repl(bot, answer).await; + Commands::repl(bot, answer).await; } #[derive(BotCommands, Clone)] #[command(rename_rule = "lowercase", description = "Commands:")] -enum Command{ +enum Commands{ Upload(String), Clean, Search(String) } -async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> { +async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> { match cmd { - Command::Upload(pkg) => { + Commands::Upload(pkg) => { 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?, }; - + env::set_current_dir(dir).expect("Failed to go to pkg dir"); + let output = Command::new("makepkg") + .arg("-s") + .arg("--noconfirm") + .output() + .expect("Failed to run makepkg"); + if output.status.success() { + bot.send_message(msg.chat.id, format!("Build succseed")).await?; + } else { + bot.send_message(msg.chat.id, format!("Build failed")).await?; + } } - Command::Clean => { + Commands::Clean => { bot.send_message(msg.chat.id, format!("Done")).await?; } - Command::Search(name) => { + Commands::Search(name) => { let mut packages = aur_rpc::search(format!("{}", name)).await.unwrap(); packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes)); let mut result = Vec::new();