revert back to old ci
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ result
|
|||||||
.\#*
|
.\#*
|
||||||
.*~*~
|
.*~*~
|
||||||
*~
|
*~
|
||||||
|
result-bin
|
||||||
|
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -532,15 +532,6 @@ 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 = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.4"
|
version = "0.4.4"
|
||||||
@@ -1129,7 +1120,6 @@ dependencies = [
|
|||||||
name = "singh3"
|
name = "singh3"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"linkify",
|
|
||||||
"rand 0.8.4",
|
"rand 0.8.4",
|
||||||
"regex",
|
"regex",
|
||||||
"serenity",
|
"serenity",
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
cargo-features = ["edition2021"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "singh3"
|
name = "singh3"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -9,7 +11,6 @@ tracing = "*"
|
|||||||
regex = "1"
|
regex = "1"
|
||||||
tokio-postgres = "*"
|
tokio-postgres = "*"
|
||||||
rand = "*"
|
rand = "*"
|
||||||
linkify = "*"
|
|
||||||
|
|
||||||
[dependencies.serenity]
|
[dependencies.serenity]
|
||||||
version = "0.10.10"
|
version = "0.10.10"
|
||||||
|
108
flake.lock
generated
108
flake.lock
generated
@@ -1,12 +1,47 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"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": {
|
"flake-utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1614513358,
|
"lastModified": 1638122382,
|
||||||
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
|
"narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"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"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -16,6 +51,22 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1638109994,
|
||||||
|
"narHash": "sha256-OpA37PTiPMIqoRJbufbl5rOLII7HeeGcA0yl7FoyCIE=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "a284564b7f75ac4db73607db02076e8da9d42c9d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "release-21.05",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1622966049,
|
"lastModified": 1622966049,
|
||||||
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
|
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
|
||||||
@@ -31,39 +82,66 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_3": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1617325113,
|
"lastModified": 1637453606,
|
||||||
"narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=",
|
"narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
|
||||||
"owner": "nixos",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb",
|
"rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs",
|
"cargo2nix": "cargo2nix",
|
||||||
"rust-overlay": "rust-overlay",
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"rust-overlay": "rust-overlay_2",
|
||||||
"utils": "utils"
|
"utils": "utils"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": [
|
||||||
"nixpkgs": "nixpkgs_2"
|
"cargo2nix",
|
||||||
|
"flake-utils"
|
||||||
|
],
|
||||||
|
"nixpkgs": [
|
||||||
|
"cargo2nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1623034161,
|
"lastModified": 1638152159,
|
||||||
"narHash": "sha256-cbw9X+nVFcpIuBga0hkbtzXbW2fyDWBon6oUN/uQmu0=",
|
"narHash": "sha256-Q0UHsm36cCxk16I/bF1rHJHxjIflESKk2ej76P39j90=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"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": 1648953213,
|
||||||
|
"narHash": "sha256-kXWcXFwqcvooHjcDoEK4mtvKU/8LuetwhrofU+9KMS0=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "caa1a7ea867138d4f4e05bd2f41d707df0a61cde",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
32
flake.nix
32
flake.nix
@@ -5,18 +5,32 @@
|
|||||||
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
|
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
|
||||||
utils.url = github:numtide/flake-utils;
|
utils.url = github:numtide/flake-utils;
|
||||||
rust-overlay.url = github:oxalica/rust-overlay;
|
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
|
utils.lib.eachDefaultSystem
|
||||||
(system:
|
(system:
|
||||||
let
|
let
|
||||||
overlays = [ (import rust-overlay) ];
|
|
||||||
|
overlays =
|
||||||
|
[
|
||||||
|
(import "${cargo2nix}/overlay")
|
||||||
|
rust-overlay.overlay
|
||||||
|
];
|
||||||
|
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system overlays;
|
inherit system overlays;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rustPkgs = pkgs.rustBuilder.makePackageSet' {
|
||||||
|
rustChannel = "latest";
|
||||||
|
packageFun = import ./Cargo.nix;
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
devShells = with pkgs; {
|
devShells = with pkgs; {
|
||||||
default = mkShell
|
default = mkShell
|
||||||
{
|
{
|
||||||
@@ -47,16 +61,14 @@
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devShell = devShells.default;
|
devShell = devShells.default;
|
||||||
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
|
|
||||||
pname = "singh3";
|
packages = {
|
||||||
version = "0.1.0";
|
default = (rustPkgs.workspace.singh3 { }).bin;
|
||||||
src = ./.;
|
|
||||||
nativeBuildInputs = with pkgs; [
|
|
||||||
rust-bin.nightly.latest.default
|
|
||||||
];
|
|
||||||
cargoSha256 = "sha256-04yTexSkFpa3KQKVvfi7NM1j4V7m08kHDqw98bxXT5M=";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
defaultPackage = packages.default;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,57 +1,10 @@
|
|||||||
use linkify::LinkFinder;
|
|
||||||
use serenity::model::channel::Message;
|
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 {
|
pub trait ExtractInfo {
|
||||||
fn extract_urls(&self) -> URLExtractInfo;
|
|
||||||
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String>;
|
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority: Text > Attachments > Reference
|
|
||||||
impl ExtractInfo for Message {
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String> {
|
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String> {
|
||||||
let mut ret: String = String::from("");
|
let mut ret: String = String::from("");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user