revert back to old ci

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-04-04 18:17:02 +05:30
parent a3919853b0
commit 25735e3581
7 changed files with 2439 additions and 83 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ result
.\#*
.*~*~
*~
result-bin

10
Cargo.lock generated
View File

@@ -532,15 +532,6 @@ 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 = "lock_api"
version = "0.4.4"
@@ -1129,7 +1120,6 @@ dependencies = [
name = "singh3"
version = "0.1.0"
dependencies = [
"linkify",
"rand 0.8.4",
"regex",
"serenity",

2321
Cargo.nix Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,5 @@
cargo-features = ["edition2021"]
[package]
name = "singh3"
version = "0.1.0"
@@ -9,7 +11,6 @@ tracing = "*"
regex = "1"
tokio-postgres = "*"
rand = "*"
linkify = "*"
[dependencies.serenity]
version = "0.10.10"

108
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": {
@@ -16,6 +51,22 @@
}
},
"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": {
"lastModified": 1622966049,
"narHash": "sha256-6g+28v94ISkVk9TBSsITVOnB2slK8plieWPIF2jo/l0=",
@@ -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": 1648953213,
"narHash": "sha256-kXWcXFwqcvooHjcDoEK4mtvKU/8LuetwhrofU+9KMS0=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "caa1a7ea867138d4f4e05bd2f41d707df0a61cde",
"type": "github"
},
"original": {

View File

@@ -5,18 +5,32 @@
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;
};
in
rec {
devShells = with pkgs; {
default = mkShell
{
@@ -47,16 +61,14 @@
];
};
};
devShell = devShells.default;
defaultPackage = pkgs.rustPlatform.buildRustPackage rec {
pname = "singh3";
version = "0.1.0";
src = ./.;
nativeBuildInputs = with pkgs; [
rust-bin.nightly.latest.default
];
cargoSha256 = "sha256-04yTexSkFpa3KQKVvfi7NM1j4V7m08kHDqw98bxXT5M=";
packages = {
default = (rustPkgs.workspace.singh3 { }).bin;
};
defaultPackage = packages.default;
}
);
}

View File

@@ -1,57 +1,10 @@
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;
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String>;
}
// 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
}
fn extract_text(&self, skip: usize, with_ref: bool) -> Option<String> {
let mut ret: String = String::from("");