10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -527,6 +527,15 @@ version = "0.2.97"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linkify"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ccbcd666d915aa3ae3c3774999a9e20b2776a018309b8159d07df062b91f45e8"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
@@ -1049,6 +1058,7 @@ dependencies = [
|
|||||||
name = "singh4"
|
name = "singh4"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"linkify",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serenity",
|
"serenity",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
tracing = "*"
|
tracing = "*"
|
||||||
reqwest = "*"
|
reqwest = "*"
|
||||||
|
linkify = "*"
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.10.10"
|
version = "0.10.10"
|
||||||
|
114
ci/pipeline.yml
Normal file
114
ci/pipeline.yml
Normal file
@@ -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 <<EOF > 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
|
39
singh4.nomad
Normal file
39
singh4.nomad
Normal file
@@ -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 = <<EOF
|
||||||
|
{{with secret "kv/data/singh4/discord"}}
|
||||||
|
DISCORD_TOKEN="{{.Data.data.token}}"
|
||||||
|
{{end}}
|
||||||
|
RUST_BACKTRACE=1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
destination = "${NOMAD_SECRETS_DIR}/data.env"
|
||||||
|
env = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
src/lib/messages.rs
Normal file
53
src/lib/messages.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use linkify::LinkFinder;
|
||||||
|
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 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::<Vec<String>>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
ret.n_attachments = self.attachments.len() as u8;
|
||||||
|
|
||||||
|
if let Some(msg) = &self.referenced_message {
|
||||||
|
let msg_links: Vec<String> = 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::<Vec<String>>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
@@ -27,7 +27,7 @@ impl TypeMapKey for ShardManagerContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(remux,speed)]
|
#[commands(remux, speed)]
|
||||||
struct Transcode;
|
struct Transcode;
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
@@ -68,7 +68,7 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let framework = StandardFramework::new()
|
let framework = StandardFramework::new()
|
||||||
.configure(|c| c.owners(owners).prefix("xx"))
|
.configure(|c| c.owners(owners).prefix("xx").delimiters(vec![" ", "\n"]))
|
||||||
.help(&MY_HELP)
|
.help(&MY_HELP)
|
||||||
.group(&GENERAL_GROUP)
|
.group(&GENERAL_GROUP)
|
||||||
.group(&TRANSCODE_GROUP);
|
.group(&TRANSCODE_GROUP);
|
||||||
|
Reference in New Issue
Block a user