do furbooru better

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-09-07 07:42:58 -04:00
parent 2cb48f9cb6
commit 1e7f19f250
5 changed files with 193 additions and 597 deletions

748
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -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 { pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
rustc latest.rustChannels.stable.rust
rust-analyzer
rustfmt
clippy
cargo
openssl openssl
pkg-config pkg-config
]; ];

View File

@ -1,5 +1,8 @@
use furbooru::Client; use furbooru::Client;
use robespierre::framework::standard::{macros::command, CommandResult, FwContext}; 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 std::sync::Arc;
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -25,6 +28,30 @@ pub fn user_agent(username: String) -> String {
} }
#[command] #[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(()) Ok(())
} }

View File

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