From c1ab7ed3630062b0939ee3358491bae5d2cd9003 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Tue, 29 Mar 2022 10:34:48 +0530 Subject: [PATCH] ci: init Signed-off-by: Amneesh Singh --- Cargo.lock | 10 ++++ Cargo.toml | 1 + ci/pipeline.yml | 114 ++++++++++++++++++++++++++++++++++++++++++++ singh4.nomad | 39 +++++++++++++++ src/lib/messages.rs | 53 ++++++++++++++++++++ src/main.rs | 4 +- 6 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 ci/pipeline.yml create mode 100644 singh4.nomad create mode 100644 src/lib/messages.rs diff --git a/Cargo.lock b/Cargo.lock index eea5946..1a2de38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -527,6 +527,15 @@ version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +[[package]] +name = "linkify" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccbcd666d915aa3ae3c3774999a9e20b2776a018309b8159d07df062b91f45e8" +dependencies = [ + "memchr", +] + [[package]] name = "log" version = "0.4.14" @@ -1049,6 +1058,7 @@ dependencies = [ name = "singh4" version = "0.1.0" dependencies = [ + "linkify", "reqwest", "serenity", "tokio", diff --git a/Cargo.toml b/Cargo.toml index ad311f1..abd163a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] tracing = "*" reqwest = "*" +linkify = "*" [dependencies.serenity] version = "0.10.10" diff --git a/ci/pipeline.yml b/ci/pipeline.yml new file mode 100644 index 0000000..89095b0 --- /dev/null +++ b/ci/pipeline.yml @@ -0,0 +1,114 @@ +resource_types: +- name: nomad + type: registry-image + source: + repository: natto17/concourse-nomad-resource + tag: latest + +resources: +- name: image + type: registry-image + icon: docker + source: + repository: ((docker.user))/singh4 + tag: latest + username: ((docker.user)) + password: ((docker.pass)) + +- 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 + icon: discord + source: + uri: https://git.weirdnatto.in/natto1784/singh4.git + branch: master + +- name: rust-image + type: registry-image + icon: docker + source: + repository: arm64v8/rust + tag: latest + +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: rust-image + trigger: false + - task: build + image: rust-image + config: + params: + CARGO_HOME: cargo-home + CARGO_TARGET_DIR: builddir + inputs: + - name: repo + caches: + - path: builddir + - path: cargo-home + platform: linux + run: + path: sh + args: + - -c + - | + apt-get update + apt-get -y install libssl-dev pkg-config + cargo build --release --manifest-path repo/Cargo.toml + mkdir release + mv $CARGO_TARGET_DIR/release/singh4 bin + outputs: + - name: bin + - task: push-image + privileged: true + config: + platform: linux + image_resource: + type: registry-image + source: + repository: rdclda/concourse-oci-build-task + caches: + - path: cache + inputs: + - name: bin + outputs: + - name: image + run: + path: sh + args: + - -c + - | + cat < Dockerfile + FROM arm64v8/ubuntu + COPY bin/singh4 /usr/bin/singh4 + RUN apt-get update + RUN apt-get -y install ffmpeg libssl-dev + CMD ["singh4"] + EOF + build + - put: image + params: + image: image/image.tar + - put: nomad-job + params: + job_path: repo/singh4.nomad + templating: false + restart: true diff --git a/singh4.nomad b/singh4.nomad new file mode 100644 index 0000000..0b94195 --- /dev/null +++ b/singh4.nomad @@ -0,0 +1,39 @@ +job "singh4" { + region = "global" + datacenters = ["nazrin"] + type = "service" + + group "svc" { + count = 1 + + network { + mode = "bridge" + } + + vault { + policies = ["singh4-policy"] + } + + task "bot" { + driver = "docker" + + config { + image = "natto17/singh4:latest" + force_pull = true + volumes = [ "/tmp:/tmp" ] + } + + template { + data = <, + n_attachments: u8, + n_links: u16, + rn_attachments: Option, + rn_links: Option, +} + +pub trait ExtractInfo { + fn extract_urls(&self) -> URLExtractInfo; +} + +// Priority: Text > Attachments > Reference +impl ExtractInfo for Message { + fn extract_urls(&self) -> URLExtractInfo { + let mut ret = URLExtractInfo::default(); + let finder = LinkFinder::new(); + let find_links = |x| finder.links(x).map(|x| x.as_str().to_string()).collect(); + + ret.urls = find_links(&self.content); + + ret.n_links = ret.urls.len() as u16; + + ret.urls.extend( + self.attachments + .iter() + .map(|x| x.url.clone()) + .collect::>(), + ); + + ret.n_attachments = self.attachments.len() as u8; + + if let Some(msg) = &self.referenced_message { + let msg_links: Vec = find_links(&msg.content); + + ret.rn_attachments = Some(msg.attachments.len() as u8); + ret.rn_links = Some(msg_links.len() as u16); + ret.urls.extend(msg_links); + ret.urls.extend( + msg.attachments + .iter() + .map(|x| x.url.clone()) + .collect::>(), + ); + } + + ret + } +} diff --git a/src/main.rs b/src/main.rs index 36bd709..578a2e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ impl TypeMapKey for ShardManagerContainer { } #[group] -#[commands(remux,speed)] +#[commands(remux, speed)] struct Transcode; #[group] @@ -68,7 +68,7 @@ async fn main() { }; let framework = StandardFramework::new() - .configure(|c| c.owners(owners).prefix("xx")) + .configure(|c| c.owners(owners).prefix("xx").delimiters(vec![" ", "\n"])) .help(&MY_HELP) .group(&GENERAL_GROUP) .group(&TRANSCODE_GROUP);