Now bot compile downloaded sources

This commit is contained in:
Listum 2023-11-02 07:33:42 +03:00
parent a10f526426
commit 905540e858
1 changed files with 19 additions and 7 deletions

View File

@ -1,34 +1,46 @@
use teloxide::{prelude::*, utils::command::BotCommands}; use teloxide::{prelude::*, utils::command::BotCommands};
use aur_rpc; use aur_rpc;
use git2::Repository; use git2::Repository;
use std::process::Command;
use std::env;
pub async fn main(bot: Bot){ pub async fn main(bot: Bot){
Command::repl(bot, answer).await; Commands::repl(bot, answer).await;
} }
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "Commands:")] #[command(rename_rule = "lowercase", description = "Commands:")]
enum Command{ enum Commands{
Upload(String), Upload(String),
Clean, Clean,
Search(String) Search(String)
} }
async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> { async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> {
match cmd { match cmd {
Command::Upload(pkg) => { Commands::Upload(pkg) => {
let repo = format!("https://aur.archlinux.org/{}.git", pkg); let repo = format!("https://aur.archlinux.org/{}.git", pkg);
let dir = format!("pkgs/{}", pkg); let dir = format!("pkgs/{}", pkg);
match Repository::clone(repo.as_str(), dir.as_str()) { match Repository::clone(repo.as_str(), dir.as_str()) {
Ok(_) => bot.send_message(msg.chat.id, format!("Succsess {}", pkg)).await?, Ok(_) => bot.send_message(msg.chat.id, format!("Succsess {}", pkg)).await?,
Err(e) => bot.send_message(msg.chat.id, format!("Error: {}", e)).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?; 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(); let mut packages = aur_rpc::search(format!("{}", name)).await.unwrap();
packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes)); packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes));
let mut result = Vec::new(); let mut result = Vec::new();