enable furbooru command

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-09-08 18:18:18 -04:00
parent 622f150b70
commit b5da275320
3 changed files with 60 additions and 62 deletions

56
Cargo.lock generated
View File

@ -733,9 +733,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "js-sys"
version = "0.3.53"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d"
checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254"
dependencies = [
"wasm-bindgen",
]
@ -1230,8 +1230,8 @@ dependencies = [
[[package]]
name = "robespierre"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"async-std",
"async-trait",
@ -1251,8 +1251,8 @@ dependencies = [
[[package]]
name = "robespierre-cache"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"async-trait",
"robespierre-models",
@ -1261,8 +1261,8 @@ dependencies = [
[[package]]
name = "robespierre-events"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"async-std",
"async-trait",
@ -1279,8 +1279,8 @@ dependencies = [
[[package]]
name = "robespierre-fw-macros"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"proc-macro2",
"quote",
@ -1289,8 +1289,8 @@ dependencies = [
[[package]]
name = "robespierre-http"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"reqwest",
"robespierre-models",
@ -1301,8 +1301,8 @@ dependencies = [
[[package]]
name = "robespierre-models"
version = "0.1.0"
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
version = "0.2.0"
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
dependencies = [
"bitflags",
"chrono",
@ -1932,9 +1932,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0"
checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c"
dependencies = [
"cfg-if",
"serde",
@ -1944,9 +1944,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041"
checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523"
dependencies = [
"bumpalo",
"lazy_static",
@ -1959,9 +1959,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.26"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95fded345a6559c2cfee778d562300c581f7d4ff3edb9b0d230d69800d213972"
checksum = "a87d738d4abc4cf22f6eb142f5b9a81301331ee3c767f2fef2fda4e325492060"
dependencies = [
"cfg-if",
"js-sys",
@ -1971,9 +1971,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef"
checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1981,9 +1981,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad"
checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92"
dependencies = [
"proc-macro2",
"quote",
@ -1994,15 +1994,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29"
checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4"
[[package]]
name = "web-sys"
version = "0.3.53"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c"
checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a"
dependencies = [
"js-sys",
"wasm-bindgen",

View File

@ -1,21 +1,20 @@
use furbooru::Client;
use robespierre::framework::standard::{macros::command, CommandResult, FwContext};
use robespierre::framework::standard::{
extractors::RawArgs, macros::command, CommandResult, FwContext,
};
use robespierre::model::MessageExt;
use robespierre::UserData;
use robespierre_models::channel::Message;
use std::sync::Arc;
use tokio::sync::Mutex;
pub struct ClientKey;
impl robespierre::typemap::Key for ClientKey {
type Value = Arc<Mutex<Client>>;
type Value = Arc<Client>;
}
pub fn make(username: String, api_key: String) -> Arc<Mutex<Client>> {
Arc::new(Mutex::new(
Client::new(user_agent(username), api_key).unwrap(),
))
pub fn make(username: String, api_key: String) -> Arc<Client> {
Arc::new(Client::new(user_agent(username), api_key).unwrap())
}
pub fn user_agent(username: String) -> String {
@ -27,31 +26,31 @@ pub fn user_agent(username: String) -> String {
)
}
// #[command]
// pub async fn search_impl(ctx: &FwContext, msg: &Message) -> CommandResult {
// let data = ctx.data_lock_read().await;
// let client = data.get::<ClientKey>().unwrap().clone();
// let client = client.lock().await;
#[command]
pub async fn search(ctx: &FwContext, msg: &Message, args: RawArgs) -> CommandResult {
let data = ctx.data_lock_read().await;
let client = data.get::<ClientKey>().unwrap().clone();
let args = format!("{}", args.0);
// let mut imgs = client.image_search(args, 0_u64).await?;
let mut imgs = client.image_search(args, 0_u64).await?;
// let mut response = String::new();
let mut response = String::new();
// imgs.truncate(3);
imgs.truncate(3);
// for mut post in imgs.into_iter() {
// post.tags.sort();
// post.tags.truncate(8);
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,
// ));
// }
response.push_str(&format!(
"<{}> - {} - <{}>\n",
format!("http://furbooru.org/{}", post.id),
post.tags.join(", "),
post.view_url,
));
}
// msg.reply(ctx, response).await?;
msg.reply(ctx, response).await?;
// Ok(())
// }
Ok(())
}

View File

@ -14,7 +14,6 @@ use robespierre_http::Http;
use robespierre_models::{channel::Message, events::ReadyEvent};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use tokio::sync::Mutex;
struct CommandCounterKey;
@ -25,7 +24,7 @@ impl robespierre::typemap::Key for CommandCounterKey {
struct ReqwestClientKey;
impl robespierre::typemap::Key for ReqwestClientKey {
type Value = Arc<Mutex<reqwest::Client>>;
type Value = Arc<reqwest::Client>;
}
mod commands;
@ -55,12 +54,12 @@ async fn main() -> Result<()> {
config.furbooru_bot_owner,
));
data.insert::<CommandCounterKey>(Arc::new(AtomicUsize::new(0)));
data.insert::<ReqwestClientKey>(Arc::new(Mutex::new(
data.insert::<ReqwestClientKey>(Arc::new(
reqwest::Client::builder()
.user_agent(APP_USER_AGENT)
.build()
.unwrap(),
)));
));
let context = Context::new(http, data).with_cache(CacheConfig::default());
let fw = StandardFramework::default()
@ -70,7 +69,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))
.command(|| Command::new("fb", furbooru::search as CommandCodeFn))
});
let handler = FrameworkWrap::new(fw, Handler);
let handler = CacheWrap::new(EventHandlerWrap::new(handler));
@ -109,7 +108,7 @@ async fn command_counter(ctx: &FwContext, msg: &Message) -> CommandResult {
async fn current_front(ctx: &FwContext, msg: &Message) -> CommandResult {
let data = ctx.data_lock_read().await;
let client = data.get::<ReqwestClientKey>().unwrap().clone();
let client = client.lock().await;
let client = client;
let front = client
.get("https://home.cetacean.club/front")