Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 22 additions & 0 deletions src/commands/mods/deny.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::entities::moderator::Feature;
use spinners::*;
fn subtract_vecs<T>(v1: &Vec<T>, v2: &Vec<T>) -> Vec<T>
where T: Eq + Clone
{
v1.iter().filter(|&x| !v2.contains(x)).cloned().collect()
}
pub fn deny(id: u128, features: Vec<Feature>) {
let token = super::expect_token();
let app_id = crate::handle_result!(super::ask_for_app(token.clone(), "modify the mod's permissions"));
let mut spinner = Spinner::new(Spinners::Toggle2, "Removing the permissions...".into());
let moderator = crate::handle_result!(crate::entities::moderator::Mod::fetch_mod(token.clone(), id, app_id));
match moderator {
Some(mut moderator) => {
crate::handle_result!(moderator.set_features(subtract_vecs(&moderator.get_features(), &features), token.clone()), spinner);
spinner.stop_with_message(super::format_log(&format!("{:?} were removed successfully!", features)));
},
None => {
spinner.stop_with_message(super::format_err("That moderator doesn't exist!"));
}
}
}
1 change: 1 addition & 0 deletions src/commands/mods/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod add;
pub mod remove;
pub mod allow;
pub mod deny;
use super::*;
2 changes: 1 addition & 1 deletion src/entities/moderator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use serde_enum_str::*;
use std::fmt::Debug;

#[derive(Deserialize_enum_str, Serialize_enum_str, Clone)]
#[derive(Deserialize_enum_str, Serialize_enum_str, Clone, Eq, PartialEq)]
pub enum Feature {
#[serde(rename = "start_app")]
Start,
Expand Down
19 changes: 19 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ fn main() -> std::io::Result<()> {
.multiple_occurrences(true)
)
)
.subcommand(
Command::new("deny")
.about("Removes permissions from a moderator")
.arg(Arg::new("id").value_parser(value_parser!(u128)).action(clap::ArgAction::Set))
.arg(
Arg::new("perm")
.value_parser(value_parser!(Feature))
.action(clap::ArgAction::Append)
.multiple_occurrences(true)
)
)
.after_help("Be careful with what people you add and what permissions you give: With Great Power comes Great Responsability.")
);
let matches = cmd.get_matches();
Expand Down Expand Up @@ -196,6 +207,14 @@ fn main() -> std::io::Result<()> {
commands::mods::remove::remove(id);
Ok(())
}
Some(("deny", matches)) => {
let id: u128 = *matches.get_one("id").unwrap();
let features: Vec<Feature> = matches.get_many("perm").unwrap()
.map(|perm: &Feature| perm.clone())
.collect();
commands::mods::deny::deny(id, features);
Ok(())
}
Some(("allow", matches)) => {
let id: u128 = *matches.get_one("id").unwrap();
let features: Vec<Feature> = matches.get_many("perm").unwrap()
Expand Down