mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-21 01:38:55 +00:00
Compare commits
3 commits
a146883620
...
e07949378c
Author | SHA1 | Date | |
---|---|---|---|
|
e07949378c | ||
|
c148dca438 | ||
|
7399008414 |
6 changed files with 39 additions and 40 deletions
10
.github/workflows/build_test.yml
vendored
10
.github/workflows/build_test.yml
vendored
|
@ -64,6 +64,16 @@ jobs:
|
||||||
run: cargo test
|
run: cargo test
|
||||||
env:
|
env:
|
||||||
SQLX_OFFLINE: "true"
|
SQLX_OFFLINE: "true"
|
||||||
|
checkDeps:
|
||||||
|
name: Check dependency hash
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: cachix/install-nix-action@v27
|
||||||
|
with:
|
||||||
|
github_access_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Build dependencies
|
||||||
|
run: nix build .#youmubot.cargoDeps --option substituters "https://cache.nixos.org" --option extra-substituters ""
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
16
flake.lock
generated
16
flake.lock
generated
|
@ -1,20 +1,5 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1734744351,
|
|
||||||
"narHash": "sha256-fN9npuZHHHzDVr1wuKoh/TheHkerDaLB9l4vj/48Exg=",
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"rev": "a83a48a62640517588c3d137c948ed034706363c",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "ipetkov",
|
|
||||||
"repo": "crane",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
|
@ -51,7 +36,6 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"crane": "crane",
|
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
|
|
12
flake.nix
12
flake.nix
|
@ -2,7 +2,6 @@
|
||||||
description = "A discord bot for Dự Tuyển Tổng Hợp server";
|
description = "A discord bot for Dự Tuyển Tổng Hợp server";
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
crane.url = "github:ipetkov/crane";
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
rust-overlay = {
|
rust-overlay = {
|
||||||
url = "github:oxalica/rust-overlay";
|
url = "github:oxalica/rust-overlay";
|
||||||
|
@ -14,9 +13,6 @@
|
||||||
extra-trusted-public-keys = [ "natsukagami.cachix.org-1:3U6GV8i8gWEaXRUuXd2S4ASfYgdl2QFPWg4BKPbmYiQ=" ];
|
extra-trusted-public-keys = [ "natsukagami.cachix.org-1:3U6GV8i8gWEaXRUuXd2S4ASfYgdl2QFPWg4BKPbmYiQ=" ];
|
||||||
};
|
};
|
||||||
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
|
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
|
||||||
let
|
|
||||||
rustVersion = "1.83.0";
|
|
||||||
in
|
|
||||||
flake-utils.lib.eachDefaultSystem
|
flake-utils.lib.eachDefaultSystem
|
||||||
(system:
|
(system:
|
||||||
let
|
let
|
||||||
|
@ -24,11 +20,9 @@
|
||||||
{
|
{
|
||||||
inherit system; overlays = [ (import inputs.rust-overlay) ];
|
inherit system; overlays = [ (import inputs.rust-overlay) ];
|
||||||
};
|
};
|
||||||
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.stable.${rustVersion}.default);
|
|
||||||
# craneLib = inputs.crane.mkLib pkgs;
|
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
packages.youmubot = pkgs.callPackage ./package.nix { inherit craneLib; };
|
packages.youmubot = pkgs.callPackage ./package.nix { };
|
||||||
|
|
||||||
defaultPackage = packages.youmubot;
|
defaultPackage = packages.youmubot;
|
||||||
|
|
||||||
|
@ -54,9 +48,7 @@
|
||||||
};
|
};
|
||||||
}) // {
|
}) // {
|
||||||
overlays.default = final: prev: {
|
overlays.default = final: prev: {
|
||||||
youmubot = final.callPackage ./package.nix {
|
youmubot = final.callPackage ./package.nix { };
|
||||||
craneLib = (inputs.crane.mkLib final).overrideToolchain (p: p.rust-bin.stable.${rustVersion}.default);
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
# module
|
# module
|
||||||
nixosModules.default = import ./module.nix;
|
nixosModules.default = import ./module.nix;
|
||||||
|
|
33
package.nix
33
package.nix
|
@ -1,27 +1,41 @@
|
||||||
{ craneLib
|
{ rustPlatform
|
||||||
, lib
|
, lib
|
||||||
, stdenv
|
, stdenv
|
||||||
, pkg-config
|
, pkg-config
|
||||||
, openssl
|
, openssl
|
||||||
|
|
||||||
, enableCodeforces ? true
|
, enableCodeforces ? false
|
||||||
, enableOsu ? true
|
, enableOsu ? true
|
||||||
, ...
|
, ...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
customizeFeatures = !(enableCodeforces && enableOsu);
|
customizeFeatures = !(enableCodeforces && enableOsu);
|
||||||
featureFlags = lib.optionals customizeFeatures (
|
|
||||||
[ "--no-default-features" "--features=core" ]
|
|
||||||
++ lib.optional enableCodeforces "--features=codeforces"
|
|
||||||
++ lib.optional enableOsu "--features=osu"
|
|
||||||
);
|
|
||||||
in
|
in
|
||||||
craneLib.buildPackage {
|
rustPlatform.buildRustPackage {
|
||||||
pname = "youmubot";
|
pname = "youmubot";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
cargoExtraArgs = builtins.concatStringsSep " " ([ "--locked" "--package youmubot" ] ++ featureFlags);
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
outputHashes = {
|
||||||
|
"poise-0.6.1" = "sha256-44pPe02JJ97GEpzAXdQmDq/9bb4KS9G7ZFVlBRC6EYs=";
|
||||||
|
"rosu-v2-0.9.0" = "sha256-dx0EwqqgkLaHwCPHyn5vMkhZ2NZcahH5SACFcsJKP1E=";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
buildNoDefaultFeatures = customizeFeatures;
|
||||||
|
buildFeatures = lib.optionals customizeFeatures (
|
||||||
|
[ "core" ]
|
||||||
|
++ lib.optional enableCodeforces "codeforces"
|
||||||
|
++ lib.optional enableOsu "osu"
|
||||||
|
);
|
||||||
|
|
||||||
|
cargoBuildFlags = [
|
||||||
|
"--locked"
|
||||||
|
"--package"
|
||||||
|
"youmubot"
|
||||||
|
];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
openssl
|
openssl
|
||||||
|
@ -33,4 +47,3 @@ craneLib.buildPackage {
|
||||||
|
|
||||||
SQLX_OFFLINE = "true";
|
SQLX_OFFLINE = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ pub struct ToPrint<'a> {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
// Beatmap(set) hooks
|
// Beatmap(set) hooks
|
||||||
static ref OLD_LINK_REGEX: Regex = Regex::new(
|
static ref OLD_LINK_REGEX: Regex = Regex::new(
|
||||||
r"(?:https?://)?osu\.ppy\.sh/(?P<link_type>s|b|beatmaps)/(?P<id>\d+)(?:[\&\?]m=(?P<mode>[0123]))?(?:(?P<mods>v2|[[:^alpha:]]\S+\b))?"
|
r"(?:https?://)?osu\.ppy\.sh/(?P<link_type>s|b|beatmaps)/(?P<id>\d+)(?:[\&\?]m=(?P<mode>[0123]))?(?:(?P<mods>v2|[[:^alpha:]][\w@.]+\b))?"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
static ref NEW_LINK_REGEX: Regex = Regex::new(
|
static ref NEW_LINK_REGEX: Regex = Regex::new(
|
||||||
r"(?:https?://)?osu\.ppy\.sh/beatmapsets/(?P<set_id>\d+)/?(?:\#(?P<mode>osu|taiko|fruits|mania)(?:/(?P<beatmap_id>\d+)|/?))?(?:(?P<mods>v2|[[:^alpha:]]\S+\b))?"
|
r"(?:https?://)?osu\.ppy\.sh/beatmapsets/(?P<set_id>\d+)/?(?:\#(?P<mode>osu|taiko|fruits|mania)(?:/(?P<beatmap_id>\d+)|/?))?(?:(?P<mods>v2|[[:^alpha:]][\w@.]+\b))?"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
static ref SHORT_LINK_REGEX: Regex = Regex::new(
|
static ref SHORT_LINK_REGEX: Regex = Regex::new(
|
||||||
r"(?:^|\s|\W)(?P<main>/(?P<link_type>b|s)/(?P<id>\d+)(?:/(?P<mode>osu|taiko|fruits|mania))?(?:(?P<mods>v2|[[:^alpha:]]\S+\b))?)"
|
r"(?:^|\s|\W)(?P<main>/(?P<link_type>b|s)/(?P<id>\d+)(?:/(?P<mode>osu|taiko|fruits|mania))?(?:(?P<mods>v2|[[:^alpha:]][\w@.]+\b))?)"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
// Score hook
|
// Score hook
|
||||||
|
|
|
@ -1044,7 +1044,7 @@ pub(crate) async fn do_check(
|
||||||
osu_client
|
osu_client
|
||||||
.scores(b.beatmap_id, |f| f.user(UserID::ID(user.id)).mode(m))
|
.scores(b.beatmap_id, |f| f.user(UserID::ID(user.id)).mode(m))
|
||||||
.map_ok(move |mut v| {
|
.map_ok(move |mut v| {
|
||||||
v.retain(|s| mods.as_ref().is_none_or(|m| m.contains(&s.mods)));
|
v.retain(|s| mods.as_ref().is_none_or(|m| s.mods.contains(&m)));
|
||||||
v
|
v
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Add table
Reference in a new issue