Compare commits

..

1 Commits

Author SHA1 Message Date
Sam W ad118fbec9 Add mastodon posting, update deps, go async 2023-06-16 16:12:47 +01:00
3 changed files with 14 additions and 62 deletions

30
Cargo.lock generated
View File

@ -881,15 +881,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "home"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
dependencies = [
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "html5ever" name = "html5ever"
version = "0.26.0" version = "0.26.0"
@ -1137,18 +1128,16 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]] [[package]]
name = "jni" name = "jni"
version = "0.21.1" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" checksum = "039022cdf4d7b1cf548d31f60ae783138e5fd42013f6271049d7df7afadef96c"
dependencies = [ dependencies = [
"cesu8", "cesu8",
"cfg-if",
"combine", "combine",
"jni-sys", "jni-sys",
"log", "log",
"thiserror", "thiserror",
"walkdir", "walkdir",
"windows-sys 0.45.0",
] ]
[[package]] [[package]]
@ -3269,19 +3258,16 @@ dependencies = [
[[package]] [[package]]
name = "webbrowser" name = "webbrowser"
version = "0.8.10" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd222aa310eb7532e3fd427a5d7db7e44bc0b0cf1c1e21139c345325511a85b6"
dependencies = [ dependencies = [
"core-foundation",
"home",
"jni", "jni",
"log",
"ndk-context", "ndk-context",
"objc", "objc",
"raw-window-handle", "raw-window-handle",
"url", "url",
"web-sys", "web-sys",
"widestring",
"winapi",
] ]
[[package]] [[package]]
@ -3309,6 +3295,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "widestring"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View File

@ -52,45 +52,5 @@
packages = with pkgs; [rust rust-analyzer]; packages = with pkgs; [rust rust-analyzer];
}; };
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
}) // { });
overlays.default = final: prev: {
iso7010-a-day = self.packages.${prev.system}.default;
};
nixosModules.default = {
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.services.iso7010-a-day;
in {
options.services.iso7010-a-day = {
enable = mkEnableOption "Enable the iso7010 bot";
environmentFile = mkOption {
type = types.path;
description = "Path to the environment file";
};
};
config = mkIf cfg.enable {
nixpkgs.overlays = [self.overlays.default];
systemd.services.iso7010-a-day = {
description = "Samw's ISO7010 bot";
serviceConfig = {
Type = "oneshot";
DynamicUser = true;
User = "iso7010";
ExecStart = "${pkgs.iso7010-a-day}/bin/iso7010_a_day run-bot";
EnvironmentFile = cfg.environmentFile;
};
};
systemd.timers.iso7010-a-day = {
wantedBy = [ "timers.target" ];
partOf = [ "iso7010-a-day.service" ];
timerConfig.OnCalendar = [ "*-*-* 12:00:00" ];
};
};
};
};
} }

View File

@ -2,7 +2,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use megalodon::entities::UploadMedia; use megalodon::entities::{Attachment, UploadMedia};
use megalodon::generator; use megalodon::generator;
use megalodon::megalodon::PostStatusInputOptions; use megalodon::megalodon::PostStatusInputOptions;
use megalodon::{self, megalodon::UploadMediaInputOptions}; use megalodon::{self, megalodon::UploadMediaInputOptions};
@ -28,7 +28,7 @@ pub async fn toot(text: &str, img: Option<Cow<'static, [u8]>>) -> StdError<()> {
let mut ops = PostStatusInputOptions::default(); let mut ops = PostStatusInputOptions::default();
if let Some(img) = img { if let Some(img) = img {
let media = client let media = client
.upload_media_bytes( .upload_media_raw(
// TODO: get better at lifetimes // TODO: get better at lifetimes
Box::leak(Box::new(img)), Box::leak(Box::new(img)),
Some(&UploadMediaInputOptions::default()), Some(&UploadMediaInputOptions::default()),