Skip to content

Commit

Permalink
0.5.0 - VRCDB Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayBox committed Mar 13, 2024
1 parent 4e58d97 commit ca9e388
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 225 deletions.
304 changes: 150 additions & 154 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vrc-log"
version = "0.4.5"
version = "0.5.0"
authors = ["Shayne Hartford <[email protected]>"]
edition = "2021"
description = "VRChat Local Cache Avatar ID Logger"
Expand All @@ -27,16 +27,16 @@ regex = "1"
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlite = { version = "0.32", features = ["bundled"], optional = true }
strum = { version = "0.25", features = ["derive"] }
sqlite = { version = "0.34", features = ["bundled"], optional = true }
strum = { version = "0.26", features = ["derive"] }

[features]
default = ["cache", "ravenwood", "sqlite", "title"]
default = ["cache", "sqlite", "title", "vrcdb"]
cache = []
discord = ["dep:discord-presence"]
ravenwood = ["dep:reqwest", "discord"]
sqlite = ["dep:sqlite"]
title = ["dep:crossterm"]
vrcdb = ["dep:reqwest", "discord"]

# https://github.com/johnthagen/min-sized-rust
[profile.release]
Expand All @@ -47,6 +47,7 @@ codegen-units = 1
panic = "abort"

[lints.clippy]
pedantic = "warn"
nursery = "warn"
cargo = "warn"
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
cargo = { level = "warn", priority = -1 }
multiple_crate_versions = "allow"
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

VRChat Local Cache Avatar ID Logger

I created this as an extensible alternative to [Ravenwood-AvatarLogger]

## Notice
This project does **NOT** rip or steal avatars, it just scans your local cache for avatar ids and sends them to avatar database providers

Expand All @@ -21,16 +19,16 @@ This program prints [VRCX] avatar links when a new (to you) avatar is found
You can place a **shortcut** to this program within the [VRCX] Auto-Launch Folder (Settings > Advanced)

### Provider Support
- [Ravenwood] (Web & VRCX)
- [VRCDB] (World) - Uses the Ravenwood database
- ~~[Just H Party]~~ (Web & VRCX) - There's no way to submit avatars
- ~~[Prismic's Avatar Search]~~ (World) - There's no way to submit avatars
- [Avatar Search (Discord)] - Uses VRCDB
- [Avatar Search (World)] - Uses VRCDB
- ~~Ravenwood (Web & VRCX)~~ - Used VRCDB - Shutdown
- ~~[Just H Party (Web & VRCX)]~~ - There's no way to submit avatars
- ~~[Prismic's Avatar Search (World)]~~ - There's no way to submit avatars

Additional providers are welcome, please open an issue, pull request, or join Discord

[Ravenwood]: https://vrcdb.ravenwood.dev
[Just H Party]: https://avtr.just-h.party
[Avatar Search (Discord)]: https://discord.gg/q427ecnUvj
[Avatar Search (World)]: https://vrchat.com/home/world/wrld_1146f625-5d42-40f5-bfe7-06a7664e2796
[Just H Party (Web & VRCX)]: https://avtr.just-h.party
[Prismic's Avatar Search (World)]: https://vrchat.com/home/world/wrld_57514404-7f4e-4aee-a50a-57f55d3084bf
[VRCX]: https://github.com/vrcx-team/VRCX?tab=readme-ov-file#--vrcx
[VRCDB]: https://vrchat.com/home/world/wrld_1146f625-5d42-40f5-bfe7-06a7664e2796
[Ravenwood-AvatarLogger]: https://github.com/Lua-Ravenwood/Ravenwood-AvatarLogger
[Prismic's Avatar Search]: https://vrchat.com/home/world/wrld_57514404-7f4e-4aee-a50a-57f55d3084bf
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl VRChat {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(path)?;

let mut text = String::new();
Expand Down
37 changes: 20 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crossterm::{execute, terminal::SetTitle};
use vrc_log::{
box_db,
config::VRChat,
get_local_time,
provider::{prelude::*, Providers, Type},
};

Expand All @@ -16,8 +15,8 @@ fn main() -> anyhow::Result<()> {
let mut providers = Providers::from([
#[cfg(all(feature = "cache", feature = "sqlite"))]
(Type::Cache, box_db!(Sqlite::new()?)),
#[cfg(feature = "ravenwood")]
(Type::Ravenwood, box_db!(Ravenwood::default())),
#[cfg(feature = "vrcdb")]
(Type::VRCDB, box_db!(VRCDB::default())),
#[cfg(all(feature = "sqlite", not(feature = "cache")))]
(Type::Sqlite, box_db!(Sqlite::new()?)),
]);
Expand All @@ -32,28 +31,32 @@ fn main() -> anyhow::Result<()> {
};

for avatar_id in avatar_ids {
#[cfg(feature = "cache")] // Check if the avatar is unique
let mut unique_and_submitted = cache.check_avatar_id(&avatar_id).unwrap_or(true);

#[cfg(feature = "cache")] // Skip if the avatar is not unique
if !unique_and_submitted {
#[cfg(feature = "cache")] // Avatar is already in cache
if !cache.check_avatar_id(&avatar_id).unwrap_or(true) {
continue;
}
};

let local_time = get_local_time();
#[cfg(feature = "cache")] // Don't send to cache if sending failed
let mut send_to_cache = true;
let local_time = vrc_log::get_local_time();

vrc_log::print_colorized(&avatar_id); // Submit the avatar to providers
vrc_log::print_colorized(&avatar_id);
for (provider_type, provider) in &providers {
if let Err(error) = provider.send_avatar_id(&avatar_id) {
unique_and_submitted = false; // Failed to submit
eprintln!("^{local_time}: Failed to submit to {provider_type}: {error}");
} else {
println!("^{local_time}: Successfully Submitted to {provider_type} ^");
match provider.send_avatar_id(&avatar_id) {
Ok(unique) => {
if unique {
println!("^ {local_time}: Successfully Submitted to {provider_type}");
}
}
Err(error) => {
send_to_cache = false;
eprintln!("^ {local_time}: Failed to submit to {provider_type}: {error}");
}
}
}

#[cfg(feature = "cache")]
if unique_and_submitted {
if send_to_cache {
cache.send_avatar_id(&avatar_id)?;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ use indexmap::IndexMap;
use strum::Display;

pub mod prelude;
#[cfg(feature = "ravenwood")]
pub mod ravenwood;
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[cfg(feature = "vrcdb")]
pub mod vrcdb;

#[derive(Display, Eq, Hash, PartialEq)]
pub enum Type {
#[cfg(feature = "cache")]
Cache,
#[cfg(feature = "ravenwood")]
Ravenwood,
#[cfg(feature = "sqlite")]
Sqlite,
#[cfg(feature = "vrcdb")]
#[strum(to_string = "Avatar Search")]
VRCDB,
}

pub trait Provider {
Expand Down
4 changes: 2 additions & 2 deletions src/provider/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "ravenwood")]
pub use super::ravenwood::Ravenwood;
#[cfg(feature = "sqlite")]
pub use super::sqlite::Sqlite;
#[cfg(feature = "vrcdb")]
pub use super::vrcdb::VRCDB;
45 changes: 16 additions & 29 deletions src/provider/ravenwood.rs → src/provider/vrcdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use std::collections::HashMap;

use anyhow::{bail, Result};
use reqwest::blocking::Client;
use serde::{Deserialize, Serialize};

use crate::{
discord::{User, DEVELOPER_ID, USER},
provider::Provider,
provider::{Provider, Type},
};

const USER_AGENT: &str = concat!(
Expand All @@ -15,33 +14,22 @@ const USER_AGENT: &str = concat!(
" [email protected]"
);

#[derive(Deserialize, Serialize)]
pub struct Response {
status: Status,
pub struct VRCDB {
client: Client,
userid: String,
}

#[derive(Deserialize, Serialize)]
pub struct Status {
message: String,
status: i64,
}

pub struct Ravenwood {
client: Client,
user_id: String,
}

impl Ravenwood {
impl VRCDB {
#[must_use]
pub const fn new(client: Client, user_id: String) -> Self {
Self { client, user_id }
pub const fn new(client: Client, userid: String) -> Self {
Self { client, userid }
}
}

impl Default for Ravenwood {
impl Default for VRCDB {
fn default() -> Self {
let client = Client::default();
let user_id = USER.clone().map_or_else(
let userid = USER.clone().map_or_else(
|| {
eprintln!("Error: Discord RPC Connection Failed\n");
eprintln!("This may be due to one of the following reasons:");
Expand All @@ -53,33 +41,32 @@ impl Default for Ravenwood {
},
|user| {
let User { id, name, nick } = user;
println!("[Ravenwood] Authenticated as {nick} ({name})");
println!("{} Authenticated as {nick} ({name})", Type::VRCDB);

id
},
);

Self::new(client, user_id)
Self::new(client, userid)
}
}

impl Provider for Ravenwood {
impl Provider for VRCDB {
fn check_avatar_id(&self, _avatar_id: &str) -> Result<bool> {
bail!("Unsupported")
}

fn send_avatar_id(&self, avatar_id: &str) -> Result<bool> {
let response = self
.client
.put("https://api.ravenwood.dev/avatars/putavatar")
.put("https://search.bs002.de/api/Avatar/putavatar")
.header("User-Agent", USER_AGENT)
.json(&HashMap::from([
("id", avatar_id),
("userid", &self.user_id),
("userid", &self.userid),
]))
.send()?
.json::<Response>()?;
.send()?;

Ok(response.status.status == 201)
Ok(response.status() == 201)
}
}

0 comments on commit ca9e388

Please sign in to comment.