Browse Source

do furbooru better

Signed-off-by: Christine Dodrill <[email protected]>
main
Cadey Ratio 1 month ago
parent
commit
1e7f19f250
  1. 740
      Cargo.lock
  2. 2
      Cargo.toml
  3. 10
      shell.nix
  4. 29
      src/commands/furbooru.rs
  5. 1
      src/main.rs

740
Cargo.lock

File diff suppressed because it is too large

2
Cargo.toml

@ -6,7 +6,7 @@ edition = "2018"
[dependencies]
anyhow = "1"
envy = "0.4"
furbooru = "0.3"
furbooru = "0.4"
kankyo = "0.3"
reqwest = { version = "0.11.4", default-features = false, features = ["json", "multipart", "rustls-tls"] }
serde = { version = "1", features = ["derive"] }

10
shell.nix

@ -1,12 +1,10 @@
{ pkgs ? import <nixpkgs> { } }:
{ moz_overlay ? import (builtins.fetchTarball
"https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz")
, pkgs ? import <nixpkgs> { overlays = [ moz_overlay ]; } }:
pkgs.mkShell {
buildInputs = with pkgs; [
rustc
rust-analyzer
rustfmt
clippy
cargo
latest.rustChannels.stable.rust
openssl
pkg-config
];

29
src/commands/furbooru.rs

@ -1,5 +1,8 @@
use furbooru::Client;
use robespierre::framework::standard::{macros::command, CommandResult, FwContext};
use robespierre::model::MessageExt;
use robespierre::UserData;
use robespierre_models::channel::Message;
use std::sync::Arc;
use tokio::sync::Mutex;
@ -25,6 +28,30 @@ pub fn user_agent(username: String) -> String {
}
#[command]
pub async fn search(ctx: &FWContext, msg: &Message, args: &str) -> CommandResult {
pub async fn search_impl(ctx: &FwContext, msg: &Message, args: &str) -> CommandResult {
let data = ctx.data_lock_read().await;
let client = data.get::<ClientKey>().unwrap().clone();
let client = client.lock().await;
let mut imgs = client.image_search(args, 0_u64).await?;
let mut response = String::new();
imgs.truncate(3);
for mut post in imgs.into_iter() {
post.tags.sort();
post.tags.truncate(8);
response.push_str(&format!(
"<{}> - {} - <{}>\n",
format!("http://furbooru.org/{}", post.id),
post.tags.join(", "),
post.view_url,
));
}
msg.reply(ctx, response).await?;
Ok(())
}

1
src/main.rs

@ -70,6 +70,7 @@ async fn main() -> Result<()> {
.command(|| Command::new("ping", ping as CommandCodeFn))
.command(|| Command::new("command_counter", command_counter as CommandCodeFn))
.command(|| Command::new("front", current_front as CommandCodeFn))
// .command(|| Command::new("fb", furbooru::search as CommandCodeFn))
});
let handler = FrameworkWrap::new(fw, Handler);
let handler = CacheWrap::new(EventHandlerWrap::new(handler));

Loading…
Cancel
Save