Initial commit

This commit is contained in:
Aleksandr 2025-10-07 01:16:35 +03:00
commit c826b8a819
15 changed files with 4417 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake ./nix

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/target
/secrets
/.direnv

4044
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

24
Cargo.toml Normal file
View file

@ -0,0 +1,24 @@
[package]
name = "maid"
version = "0.1.0"
edition = "2024"
[workspace]
members = ["bot"]
[workspace.dependencies]
eva = { git = "ssh://forgejo@git.viende.su:61488/VienDesu/eva.git" }
eyre = "0.6.12"
viendesu = { git = "ssh://forgejo@git.viende.su:61488/VienDesu/core.git" }
[dependencies]
eva = { workspace = true, features = ["cli", "enable-tracing"] }
eyre = { workspace = true }
viendesu = { workspace = true, features = ["http-client"] }
bot.path = "bot"
[patch.crates-io]
schemars = { git = "ssh://forgejo@git.viende.su:61488/VienDesu/schemars.git", version = "1.0.0-alpha.17" }

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# VienDesu! Maid
Телеграм бот для проекта VienDesu!.
# Функции
- Уведомления о событиях: статус публикации игр, сообщения на форуме / комментарии
- Диалоги с модератором по поводу публикации игры
- Поиск игр, в том числе в inline-режиме
- Общение с поддержкой

11
bot/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "bot"
version = "0.1.0"
edition = "2024"
[dependencies]
eva = { workspace = true, features = ["tokio"] }
viendesu.workspace = true
eyre.workspace = true
teloxide = { version = "0.17.0", default-features = false, features = ["macros", "rustls", "cache-me"] }

7
bot/src/config.rs Normal file
View file

@ -0,0 +1,7 @@
use eva::{data, utils::SecretString};
#[data]
pub struct Config {
pub token: SecretString,
pub endpoint: Option<String>,
}

29
bot/src/lib.rs Normal file
View file

@ -0,0 +1,29 @@
use eva::{component_configs::ComponentConfig, supervisor::SlaveRx, trait_set};
use eyre::Context;
use teloxide::Bot;
use viendesu::service::Service;
pub use self::config::Config;
pub mod config;
trait_set! {
pub trait Api = Service + Clone;
}
pub async fn run<A: Api>(api: A, rx: SlaveRx, config: ComponentConfig<Config>) -> eyre::Result<()> {
_ = rx;
let mut bot = Bot::new(config.token.read().wrap_err("failed to read bot token")?);
if let Some(api_endpoint) = &config.endpoint {
bot = bot.set_api_url(
api_endpoint
.parse()
.wrap_err("failed to parse bot api endpoint")?,
);
}
Ok(())
}

2
config.toml Normal file
View file

@ -0,0 +1,2 @@
[viendesu]
endpoint = "http://localhost:8080"

115
nix/flake.lock generated Normal file
View file

@ -0,0 +1,115 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1758758545,
"narHash": "sha256-NU5WaEdfwF6i8faJ2Yh+jcK9vVFrofLcwlD/mP65JrI=",
"owner": "ipetkov",
"repo": "crane",
"rev": "95d528a5f54eaba0d12102249ce42f4d01f4e364",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1746858783,
"narHash": "sha256-oLrH70QIWB/KpaI+nztyP1hG4zAEEpMiNk6sA8QLQ/8=",
"owner": "nix-community",
"repo": "fenix",
"rev": "4e3cd098060cca21f2a213ce8c086948df946940",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1746663147,
"narHash": "sha256-Ua0drDHawlzNqJnclTJGf87dBmaO/tn7iZ+TCkTRpRc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dda3dcd3fe03e991015e9a74b22d35950f264a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1746722075,
"narHash": "sha256-t4ZntWiW4C3lE621lV3XyK3KltC5/SW1V9G+CSz70rQ=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8b624868e4ce2cb5b39559175f0978bee86bdeea",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

50
nix/flake.nix Normal file
View file

@ -0,0 +1,50 @@
{
inputs = {
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane";
};
outputs = { flake-utils, fenix, nixpkgs, crane, ... }:
flake-utils.lib.eachDefaultSystem(system:
let
overlays = [ fenix.overlays.default ];
pkgs = import nixpkgs { inherit system overlays; };
rust = with pkgs.fenix; combine [
((fromToolchainName { name = "1.89"; sha256 = "sha256-+9FmLhAOezBZCOziO0Qct1NOrfpjNsXxc/8I0c7BdKE="; }).withComponents [
"cargo"
"rustc"
"rust-src"
"rust-analyzer"
"clippy"
"llvm-tools-preview"
])
default.rustfmt
];
llvm = pkgs.llvmPackages_20;
package = import ./package.nix { inherit crane rust pkgs; };
in
{
devShells.default = pkgs.mkShell.override {
stdenv = pkgs.llvmPackages_20.stdenv;
} {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
packages = [ rust ] ++ (with pkgs; [
libclang.lib
]);
buildInputs = with pkgs; [
stdenv.cc.cc.lib
];
};
nixosModules.default = import ./module.nix { maid = package; };
packages.maid = package;
packages.default = package;
}
);
}

63
nix/module.nix Normal file
View file

@ -0,0 +1,63 @@
{ makise-next, }:
{ config, lib, pkgs, ... }:
let
types = lib.types;
cfg = config.services.makise-next;
toml = pkgs.formats.toml {};
configs = let generated = (if cfg.config != null then [(toml.generate "config.toml" cfg.config)] else []);
all = generated ++ cfg.configFiles;
in builtins.map (x: "--config ${x}") all;
configParameters = lib.strings.concatStringsSep " " configs;
in
{
options.services.viendesu-maid = {
autoStart = lib.mkOption {
description = "start Maid with the system";
type = types.bool;
default = false;
};
user = lib.mkOption {
description = "user under which Maid will run";
type = types.str;
};
enable = lib.mkEnableOption "viendesu-maid";
config = lib.mkOption {
description = "configuration for the Maid";
type = types.nullOr types.attrs;
default = null;
};
configFiles = lib.mkOption {
description = "list of configuration files for Maid";
type = types.listOf types.str;
default = [];
};
environment = lib.mkOption {
description = "list of environment variables";
type = types.attrs;
default = {};
};
environmentFiles = lib.mkOption {
description = "environment variables files";
type = types.listOf types.str;
default = [];
};
};
config = {
systemd.services.viendesu-maid = lib.mkIf cfg.enable {
wantedBy = lib.mkIf cfg.autoStart [ "multi-user.target" ];
after = [ "network.target" ];
description = "VienDesu! Maid bot";
serviceConfig = {
Type = "simple";
User = cfg.user;
ExecStart = "${makise-next} ${configParameters}";
EnvironmentFile = cfg.environmentFiles;
Environment = builtins.map ({ name, value }: "${name}=${value}")
(lib.attrsets.attrsToList cfg.environment);
};
};
};
}

15
nix/package.nix Normal file
View file

@ -0,0 +1,15 @@
{ pkgs, rust, crane }:
let
craneLib = (crane.mkLib pkgs).overrideToolchain (p: rust);
src = craneLib.cleanCargoSource ../.;
common = {
inherit src;
strictDeps = true;
};
cargoArtifacts = craneLib.buildDepsOnly common;
in
craneLib.buildPackage (common // {
inherit cargoArtifacts;
})

6
src/lib.rs Normal file
View file

@ -0,0 +1,6 @@
use eva::data;
#[data]
pub struct Config {
pub endpoint: String,
}

34
src/main.rs Normal file
View file

@ -0,0 +1,34 @@
use eva::{
cli::{App, NoArgs},
component_configs::ComponentConfigs,
supervisor::Supervisor,
};
use viendesu::http::{
client::{ClientOptions, HttpService},
format::Format,
};
fn make_service(cfg: &maid::Config) -> HttpService {
HttpService::new(ClientOptions {
format: Format::Json,
endpoint: cfg.endpoint.clone(),
})
}
async fn entrypoint(NoArgs {}: NoArgs, configs: ComponentConfigs) -> eyre::Result<()> {
let service = make_service(&*configs.get());
Supervisor::new(configs)
.add::<bot::Config>(move |cfg, rx| bot::run(service.clone(), rx, cfg))
.wait_for_completion()
.await
}
fn main() -> eyre::Result<()> {
App::default()
.env_prefix("MAID_")
.require::<bot::Config>("bot")
.require::<maid::Config>("viendesu")
.run(entrypoint)
}