Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Restriction #62

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
User restriction CLI
Sleitnick committed Aug 14, 2024
commit c3e2144e8a766877f3c09c0ba371b2dfc3d58425
12 changes: 9 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -9,10 +9,12 @@ mod place_cli;
mod subscription_cli;
mod universe_cli;
mod user_cli;
mod user_restriction_cli;

use clap::{Parser, Subcommand};
use universe_cli::Universe;
use user_cli::User;
use user_restriction_cli::UserRestriction;

use self::{
assets_cli::Assets, datastore_cli::DataStore, experience_cli::Experience, group_cli::Group,
@@ -22,13 +24,13 @@ use self::{

#[derive(Debug, Parser)]
#[clap(name = "rbxcloud", version)]
pub struct Cli {
pub(crate) struct Cli {
#[clap(subcommand)]
pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
pub(crate) enum Command {
/// Access the Roblox Assets API
Assets(Assets),

@@ -61,10 +63,13 @@ pub enum Command {

/// Access the Roblox User API
User(User),

/// Access to the Roblox User Restriction API
UserRestriction(UserRestriction),
}

impl Cli {
pub async fn run(self) -> anyhow::Result<Option<String>> {
pub(crate) async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
Command::Assets(command) => command.run().await,
Command::Experience(command) => command.run().await,
@@ -77,6 +82,7 @@ impl Cli {
Command::Place(command) => command.run().await,
Command::Universe(command) => command.run().await,
Command::User(command) => command.run().await,
Command::UserRestriction(command) => command.run().await,
}
}
}
278 changes: 278 additions & 0 deletions src/cli/user_restriction_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
use clap::{Args, Subcommand};
use rbxcloud::rbx::{
types::{PlaceId, RobloxUserId, UniverseId},
v2::{Client, UserRestrictionParams},
};

#[derive(Debug, Subcommand)]
pub(crate) enum UserRestrictionCommands {
/// Get user restriction information
Get {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// User ID
#[clap(short = 'U', long, value_parser)]
user_id: u64,

/// Place ID
#[clap(short = 'P', long, value_parser)]
place_id: Option<u64>,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},

/// Update user restriction information
Update {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// User ID
#[clap(short = 'U', long, value_parser)]
user_id: u64,

/// Place ID
#[clap(short = 'P', long, value_parser)]
place_id: Option<u64>,

/// Restriction active
#[clap(short = 'A', long, value_parser)]
active: Option<bool>,

/// Restriction duration (seconds)
#[clap(short, long, value_parser)]
duration: Option<u64>,

/// Private reason
#[clap(short = 'r', long, value_parser)]
private_reason: Option<String>,

/// Display reason
#[clap(short = 'D', long, value_parser)]
display_reason: Option<String>,

/// Exclude alternate accounts
#[clap(short, long, value_parser)]
exclude_alts: Option<bool>,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},

/// List user restrictions
List {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short = 'P', long, value_parser)]
place_id: Option<u64>,

/// Max page size
#[clap(short = 's', long, value_parser)]
page_size: Option<u32>,

/// Next page token
#[clap(short, long, value_parser)]
token: Option<String>,

/// Filter
#[clap(short, long, value_parser)]
filter: Option<String>,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},

/// List user restriction logs
Logs {
/// Universe ID
#[clap(short, long, value_parser)]
universe_id: u64,

/// Place ID
#[clap(short = 'P', long, value_parser)]
place_id: Option<u64>,

/// Max page size
#[clap(short = 's', long, value_parser)]
page_size: Option<u32>,

/// Next page token
#[clap(short, long, value_parser)]
token: Option<String>,

/// Filter
#[clap(short, long, value_parser)]
filter: Option<String>,

/// Pretty-print the JSON response
#[clap(short, long, value_parser, default_value_t = false)]
pretty: bool,

/// Roblox Open Cloud API Key
#[clap(short, long, value_parser, env = "RBXCLOUD_API_KEY")]
api_key: String,
},
}

#[derive(Debug, Args)]
pub(crate) struct UserRestriction {
#[clap(subcommand)]
command: UserRestrictionCommands,
}

impl UserRestriction {
pub(crate) async fn run(self) -> anyhow::Result<Option<String>> {
match self.command {
UserRestrictionCommands::Get {
universe_id,
user_id,
place_id,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let user_restriction_client = client.user_restriction(UniverseId(universe_id));
let res = user_restriction_client
.get_user_restriction(
RobloxUserId(user_id),
place_id.and_then(|id| Some(PlaceId(id))),
)
.await;
match res {
Ok(info) => {
let r = if pretty {
serde_json::to_string_pretty(&info)?
} else {
serde_json::to_string(&info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

UserRestrictionCommands::Update {
universe_id,
user_id,
place_id,
active,
duration,
private_reason,
display_reason,
exclude_alts,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let mut user_restriction_client = client.user_restriction(UniverseId(universe_id));
let res = user_restriction_client
.update_user_restriction(&UserRestrictionParams {
user_id: RobloxUserId(user_id),
place_id: place_id.and_then(|id| Some(PlaceId(id))),
active,
duration,
private_reason,
display_reason,
exclude_alt_accounts: exclude_alts,
})
.await;
match res {
Ok(info) => {
let r = if pretty {
serde_json::to_string_pretty(&info)?
} else {
serde_json::to_string(&info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

UserRestrictionCommands::List {
universe_id,
place_id,
page_size,
token,
filter,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let user_restriction_client = client.user_restriction(UniverseId(universe_id));
let res = user_restriction_client
.list_user_restrictions(
place_id.and_then(|id| Some(PlaceId(id))),
page_size,
filter,
token,
)
.await;
match res {
Ok(info) => {
let r = if pretty {
serde_json::to_string_pretty(&info)?
} else {
serde_json::to_string(&info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}

UserRestrictionCommands::Logs {
universe_id,
place_id,
page_size,
token,
filter,
pretty,
api_key,
} => {
let client = Client::new(&api_key);
let user_restriction_client = client.user_restriction(UniverseId(universe_id));
let res = user_restriction_client
.list_user_restriction_logs(
place_id.and_then(|id| Some(PlaceId(id))),
page_size,
filter,
token,
)
.await;
match res {
Ok(info) => {
let r = if pretty {
serde_json::to_string_pretty(&info)?
} else {
serde_json::to_string(&info)?
};
Ok(Some(r))
}
Err(err) => Err(anyhow::anyhow!(err)),
}
}
}
}
}