enable furbooru command
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
622f150b70
commit
b5da275320
|
@ -733,9 +733,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.53"
|
version = "0.3.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d"
|
checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
@ -1230,8 +1230,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre"
|
name = "robespierre"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -1251,8 +1251,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre-cache"
|
name = "robespierre-cache"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"robespierre-models",
|
"robespierre-models",
|
||||||
|
@ -1261,8 +1261,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre-events"
|
name = "robespierre-events"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -1279,8 +1279,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre-fw-macros"
|
name = "robespierre-fw-macros"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1289,8 +1289,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre-http"
|
name = "robespierre-http"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"robespierre-models",
|
"robespierre-models",
|
||||||
|
@ -1301,8 +1301,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "robespierre-models"
|
name = "robespierre-models"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/dblanovschi/robespierre#0806bc28e7cd06f258457f719ceb5d6408c3d010"
|
source = "git+https://github.com/dblanovschi/robespierre#988ea48917d7169e86d1c91bdfb16aac29b9dbe3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
@ -1932,9 +1932,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
version = "0.2.76"
|
version = "0.2.77"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0"
|
checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -1944,9 +1944,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-backend"
|
name = "wasm-bindgen-backend"
|
||||||
version = "0.2.76"
|
version = "0.2.77"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041"
|
checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -1959,9 +1959,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-futures"
|
name = "wasm-bindgen-futures"
|
||||||
version = "0.4.26"
|
version = "0.4.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95fded345a6559c2cfee778d562300c581f7d4ff3edb9b0d230d69800d213972"
|
checksum = "a87d738d4abc4cf22f6eb142f5b9a81301331ee3c767f2fef2fda4e325492060"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
@ -1971,9 +1971,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro"
|
name = "wasm-bindgen-macro"
|
||||||
version = "0.2.76"
|
version = "0.2.77"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef"
|
checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"wasm-bindgen-macro-support",
|
"wasm-bindgen-macro-support",
|
||||||
|
@ -1981,9 +1981,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-macro-support"
|
name = "wasm-bindgen-macro-support"
|
||||||
version = "0.2.76"
|
version = "0.2.77"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad"
|
checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1994,15 +1994,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasm-bindgen-shared"
|
name = "wasm-bindgen-shared"
|
||||||
version = "0.2.76"
|
version = "0.2.77"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29"
|
checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.53"
|
version = "0.3.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c"
|
checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
use furbooru::Client;
|
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::model::MessageExt;
|
||||||
use robespierre::UserData;
|
use robespierre::UserData;
|
||||||
use robespierre_models::channel::Message;
|
use robespierre_models::channel::Message;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
pub struct ClientKey;
|
pub struct ClientKey;
|
||||||
|
|
||||||
impl robespierre::typemap::Key for 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>> {
|
pub fn make(username: String, api_key: String) -> Arc<Client> {
|
||||||
Arc::new(Mutex::new(
|
Arc::new(Client::new(user_agent(username), api_key).unwrap())
|
||||||
Client::new(user_agent(username), api_key).unwrap(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_agent(username: String) -> String {
|
pub fn user_agent(username: String) -> String {
|
||||||
|
@ -27,31 +26,31 @@ pub fn user_agent(username: String) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[command]
|
#[command]
|
||||||
// pub async fn search_impl(ctx: &FwContext, msg: &Message) -> CommandResult {
|
pub async fn search(ctx: &FwContext, msg: &Message, args: RawArgs) -> CommandResult {
|
||||||
// let data = ctx.data_lock_read().await;
|
let data = ctx.data_lock_read().await;
|
||||||
// let client = data.get::<ClientKey>().unwrap().clone();
|
let client = data.get::<ClientKey>().unwrap().clone();
|
||||||
// let client = client.lock().await;
|
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() {
|
for mut post in imgs.into_iter() {
|
||||||
// post.tags.sort();
|
post.tags.sort();
|
||||||
// post.tags.truncate(8);
|
post.tags.truncate(8);
|
||||||
|
|
||||||
// response.push_str(&format!(
|
response.push_str(&format!(
|
||||||
// "<{}> - {} - <{}>\n",
|
"<{}> - {} - <{}>\n",
|
||||||
// format!("http://furbooru.org/{}", post.id),
|
format!("http://furbooru.org/{}", post.id),
|
||||||
// post.tags.join(", "),
|
post.tags.join(", "),
|
||||||
// post.view_url,
|
post.view_url,
|
||||||
// ));
|
));
|
||||||
// }
|
}
|
||||||
|
|
||||||
// msg.reply(ctx, response).await?;
|
msg.reply(ctx, response).await?;
|
||||||
|
|
||||||
// Ok(())
|
Ok(())
|
||||||
// }
|
}
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -14,7 +14,6 @@ use robespierre_http::Http;
|
||||||
use robespierre_models::{channel::Message, events::ReadyEvent};
|
use robespierre_models::{channel::Message, events::ReadyEvent};
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
struct CommandCounterKey;
|
struct CommandCounterKey;
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ impl robespierre::typemap::Key for CommandCounterKey {
|
||||||
struct ReqwestClientKey;
|
struct ReqwestClientKey;
|
||||||
|
|
||||||
impl robespierre::typemap::Key for ReqwestClientKey {
|
impl robespierre::typemap::Key for ReqwestClientKey {
|
||||||
type Value = Arc<Mutex<reqwest::Client>>;
|
type Value = Arc<reqwest::Client>;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
@ -55,12 +54,12 @@ async fn main() -> Result<()> {
|
||||||
config.furbooru_bot_owner,
|
config.furbooru_bot_owner,
|
||||||
));
|
));
|
||||||
data.insert::<CommandCounterKey>(Arc::new(AtomicUsize::new(0)));
|
data.insert::<CommandCounterKey>(Arc::new(AtomicUsize::new(0)));
|
||||||
data.insert::<ReqwestClientKey>(Arc::new(Mutex::new(
|
data.insert::<ReqwestClientKey>(Arc::new(
|
||||||
reqwest::Client::builder()
|
reqwest::Client::builder()
|
||||||
.user_agent(APP_USER_AGENT)
|
.user_agent(APP_USER_AGENT)
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)));
|
));
|
||||||
let context = Context::new(http, data).with_cache(CacheConfig::default());
|
let context = Context::new(http, data).with_cache(CacheConfig::default());
|
||||||
|
|
||||||
let fw = StandardFramework::default()
|
let fw = StandardFramework::default()
|
||||||
|
@ -70,7 +69,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))
|
.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));
|
||||||
|
@ -109,7 +108,7 @@ async fn command_counter(ctx: &FwContext, msg: &Message) -> CommandResult {
|
||||||
async fn current_front(ctx: &FwContext, msg: &Message) -> CommandResult {
|
async fn current_front(ctx: &FwContext, msg: &Message) -> CommandResult {
|
||||||
let data = ctx.data_lock_read().await;
|
let data = ctx.data_lock_read().await;
|
||||||
let client = data.get::<ReqwestClientKey>().unwrap().clone();
|
let client = data.get::<ReqwestClientKey>().unwrap().clone();
|
||||||
let client = client.lock().await;
|
let client = client;
|
||||||
|
|
||||||
let front = client
|
let front = client
|
||||||
.get("https://home.cetacean.club/front")
|
.get("https://home.cetacean.club/front")
|
||||||
|
|
Loading…
Reference in New Issue