Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-05-09 03:54:25 +05:30
parent d170ae0e1a
commit 0113466c87
12 changed files with 2845 additions and 329 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
Cargo.nix linguist-generated

5
.gitignore vendored
View File

@@ -1,2 +1,7 @@
target/
result
\#*\#
.\#*
.*~*~
*~
result-bin

588
Cargo.lock generated

File diff suppressed because it is too large Load Diff

2239
Cargo.nix generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,3 @@
cargo-features = ["edition2021"]
[package]
name = "singh4"

73
ci/pipeline.yml Normal file
View File

@@ -0,0 +1,73 @@
resource_types:
- name: nomad
type: registry-image
source:
repository: natto17/concourse-nomad-resource
tag: latest
resources:
- name: nomad-job
type: nomad
source:
url: https://nomad.weirdnatto.in
name: singh4
token: ((nomad.token))
consul_token: ((nomad.consul))
vault_token: ((nomad.vault))
- name: repo
type: git
source:
uri: https://git.weirdnatto.in/natto1784/singh4.git
branch: master
- name: nix
type: registry-image
source:
repository: nixos/nix
tag: latest-arm64
jobs:
- name: configure-self
public: true
plan:
- get: repo
trigger: true
- set_pipeline: self
file: repo/ci/pipeline.yml
- name: singh4
plan:
- get: repo
trigger: true
passed: [configure-self]
- get: nix
trigger: false
- task: build
image: nix
config:
params:
CACHIX_NAME: ((cachix.name))
CACHIX_AUTH_TOKEN: ((cachix.token))
inputs:
- name: repo
outputs:
- name: storepath
platform: linux
run:
path: sh
args:
- -c
- |
nix-env -iA nixpkgs.cachix
cachix use $CACHIX_NAME
cachix watch-exec $CACHIX_NAME nix -- --extra-experimental-features "nix-command flakes" build ./repo
readlink -n result-bin > storepath/value
- put: nomad-job
params:
job_path: repo/singh4.nomad
templating: true
restart: true
vars:
binary: singh4
var_files:
storepath: storepath/value

120
flake.lock generated
View File

@@ -1,12 +1,47 @@
{
"nodes": {
"cargo2nix": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1648397583,
"narHash": "sha256-g1Ej9APkfHjGd9ExBDvpmyAvsKcfMOsNH6p95xc8E/Y=",
"owner": "cargo2nix",
"repo": "cargo2nix",
"rev": "4362ae00fe824d120e94dd5d6f6e63969dc3d264",
"type": "github"
},
"original": {
"owner": "cargo2nix",
"repo": "cargo2nix",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"lastModified": 1638122382,
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"rev": "74f7e4319258e287b0f9cb95426c9853b282730b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
@@ -17,11 +52,27 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1622966049,
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
"lastModified": 1638109994,
"narHash": "sha256-OpA37PTiPMIqoRJbufbl5rOLII7HeeGcA0yl7FoyCIE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "fbfb79400a08bf754e32b4d4fc3f7d8f8055cf94",
"rev": "a284564b7f75ac4db73607db02076e8da9d42c9d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-21.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1651726670,
"narHash": "sha256-dSGdzB49SEvdOJvrQWfQYkAefewXraHIV08Vz6iDXWQ=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c777cdf5c564015d5f63b09cc93bef4178b19b01",
"type": "github"
},
"original": {
@@ -31,39 +82,66 @@
"type": "github"
}
},
"nixpkgs_2": {
"nixpkgs_3": {
"locked": {
"lastModified": 1617325113,
"narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=",
"owner": "nixos",
"lastModified": 1637453606,
"narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb",
"rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"cargo2nix": "cargo2nix",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay_2",
"utils": "utils"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
"flake-utils": [
"cargo2nix",
"flake-utils"
],
"nixpkgs": [
"cargo2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1623034161,
"narHash": "sha256-cbw9X+nVFcpIuBga0hkbtzXbW2fyDWBon6oUN/uQmu0=",
"lastModified": 1638152159,
"narHash": "sha256-Q0UHsm36cCxk16I/bF1rHJHxjIflESKk2ej76P39j90=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "0b952cdfa37f8b0fc70fc75fbd4605227cd0b272",
"rev": "d9a664513558376595e838b21348cdac0ba3115e",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"rust-overlay_2": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1651977622,
"narHash": "sha256-M3vm6mz+ypilmw3hkA6/GyDHH7ID85jWqeE9rtPWe8k=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "c66fab76467a5df683ef50724a7bde54c315f967",
"type": "github"
},
"original": {
@@ -74,11 +152,11 @@
},
"utils": {
"locked": {
"lastModified": 1622445595,
"narHash": "sha256-m+JRe6Wc5OZ/mKw2bB3+Tl0ZbtyxxxfnAWln8Q5qs+Y=",
"lastModified": 1649676176,
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "7d706970d94bc5559077eb1a6600afddcd25a7c8",
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
"type": "github"
},
"original": {

View File

@@ -5,54 +5,55 @@
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
utils.url = github:numtide/flake-utils;
rust-overlay.url = github:oxalica/rust-overlay;
cargo2nix.url = github:cargo2nix/cargo2nix;
};
outputs = { self, nixpkgs, utils, rust-overlay }:
outputs = { self, nixpkgs, utils, rust-overlay, cargo2nix }:
utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
overlays =
[
(import "${cargo2nix}/overlay")
rust-overlay.overlay
];
pkgs = import nixpkgs {
inherit system overlays;
};
rustPkgs = pkgs.rustBuilder.makePackageSet' {
rustChannel = "latest";
packageFun = import ./Cargo.nix;
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all ++ [
(pkgs.rustBuilder.rustLib.makeOverride {
name = "singh4";
overrideAttrs = drv: {
propagatedNativeBuildInputs = drv.propagatedNativeBuildInputs or [ ] ++ [
pkgs.openssl
pkgs.archiver
pkgs.pkg-config
];
};
})
];
};
in
rec {
devShells = with pkgs; {
default = mkShell
{
buildInputs = with gst_all_1; [
rust-bin.nightly.latest.default
rust-analyzer
ffmpeg
];
};
bare = mkShell
{
buildInputs = [
rust-bin.nightly.latest.default
];
};
withLSP = mkShell
{
devShell = with pkgs; mkShell {
buildInputs = [
rust-bin.nightly.latest.default
rust-analyzer
postgresql
];
};
packages = {
default = (rustPkgs.workspace.singh4 { }).bin;
};
devShell = devShells.default;
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
pname = "singh4";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
rust-bin.nightly.latest.default
];
buildInputs = with pkgs; [
ffmpeg
];
cargoSha256 = "sha256-0rzz+xOQnZYwygReKobNvUAOMeRrFZj7FUVSkAObm7I=";
};
defaultPackage = packages.default;
}
);
}

44
singh4.nomad Normal file
View File

@@ -0,0 +1,44 @@
job "singh4" {
region = "global"
datacenters = ["nazrin"]
type = "service"
group "svc" {
count = 1
network {
mode = "bridge"
}
vault {
policies = ["singh4-policy"]
}
task "bot" {
driver = "raw_exec"
config {
command = "/bin/sh"
args = [ "-c", <<EOF
nix-store --realise {{+.storepath+}}
nix shell nixpkgs#ffmpeg
{{+.storepath+}}/bin/{{+.binary+}}
EOF
]
}
template {
data = <<EOF
{{with secret "kv/data/singh4/discord"}}
DISCORD_TOKEN="{{.Data.data.token}}"
{{end}}
RUST_BACKTRACE=full
PATH=/run/current-system/sw/bin/
EOF
destination = "${NOMAD_SECRETS_DIR}/data.env"
env = true
}
}
}
}

View File

@@ -1,4 +1,4 @@
use crate::lib::ffmpeg::FfmpegTranscode;
use crate::lib::{ffmpeg::FfmpegTranscode, messages::ExtractInfo};
use serenity::{
framework::standard::{macros::command, Args, CommandResult},
http::AttachmentType,
@@ -13,11 +13,11 @@ pub const IMAGE_EXTS: [&'static str; 6] = ["png", "gif", "bmp", "webp", "jpg", "
#[command]
#[aliases("mux")]
pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let q: Vec<&str> = args.raw().collect::<Vec<&str>>();
if q.len() < 2 || q.len() > 4 {
let q = msg.extract_urls().urls;
if q.len() < 2 {
msg.reply(
ctx,
"Please use the proper syntax: `xxremux <audio> <video> [audio_codec] [video_codec]`",
"Please use the proper syntax: `xxremux <audio> <video> [audio_codec] [video_codec]`"
)
.await?;
return Ok(());
@@ -25,13 +25,13 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut trans = FfmpegTranscode::default();
trans.add_input(q[0]);
trans.add_input(&q[0]);
trans.set_acodec("copy");
let mut ext = Path::new(&q[1]).extension().unwrap().to_str().unwrap();
if IMAGE_EXTS.contains(&ext) {
let resp = reqwest::get(q[1]).await?;
let resp = reqwest::get(&q[1]).await?;
let p = format!("/tmp/{}{}-image.{}", "singh4-", msg.id, ext);
let mut f = File::create(&p).await?;
tokio::io::copy(&mut resp.bytes().await?.as_ref(), &mut f).await?;
@@ -44,19 +44,20 @@ pub async fn remux(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
.add_input(&p)
.set_vcodec("h264")
.add_arg("vf", "pad=ceil(iw/2)*2:ceil(ih/2)*2") //to correct the dimensions
.add_arg("tune", "stillimage");
.add_arg("tune", "stillimage")
.add_arg("pix_fmt", "yuv420p");
ext = "mp4";
} else {
trans.add_input(q[1]).set_vcodec("copy");
trans.add_input(&q[1]).set_vcodec("copy");
}
if q.len() > 2 {
/* if q.len() > 2 {
trans.set_acodec(q[2]);
}
if q.len() > 3 {
trans.set_vcodec(q[3]);
}
}*/
let output = format!("/tmp/{}{}.{}", "singh4-", msg.id, ext);

View File

@@ -3,11 +3,11 @@ use serenity::model::channel::Message;
#[derive(Default)]
pub struct URLExtractInfo {
urls: Vec<String>,
n_attachments: u8,
n_links: u16,
rn_attachments: Option<u8>,
rn_links: Option<u16>,
pub urls: Vec<String>,
pub n_attachments: u8,
pub n_links: u16,
pub rn_attachments: Option<u8>,
pub rn_links: Option<u16>,
}
pub trait ExtractInfo {

View File

@@ -1 +1,2 @@
pub mod ffmpeg;
pub mod messages;