Skip to content

Commit

Permalink
bugfix: No access caused deadlock in bot
Browse files Browse the repository at this point in the history
  • Loading branch information
hiibolt committed Sep 9, 2024
1 parent afba64e commit a787ae5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
96 changes: 48 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,44 @@ All commands are alternatively available as slash commands that better indicate

## Commands

### R6

#### OPSEC

` >>r6 opsec pc <username>`
- Looks up a Ubisoft account based on their registered PC username.

` >>r6 opsec xbox <username>`
- Looks up a Ubisoft account based on their registered Xbox username.

` >>r6 opsec psn <username>`
- Looks up a Ubisoft account based on their registered PSN username.

` >>r6 opsec recon <username>`
- Analyzes a Ubisoft account for suspicious behaviour based on their username (PC only).

` >>r6 opsec applications <username>`
- Looks up a Ubisoft account based on their username (PC only).

#### Economy

` >>r6 econ analyze <item name | item id>`
- Creates a detailed data sheet on an item.

` >>r6 econ list`
` >>r6 econ list <page #>`
- Lists all available skins.

` >>r6 econ graph <item name | item id>`
- Graphs the all-time history of an item.

` >>r6 econ transfer`
` >>r6 econ transfer <ubisoft email> <ubisoft password>`
- Finds the items with the least sellers either globally or on the account with the provided login.

` >>r6 econ profit <$ bought for> <item name | item id>`
- Calculates the amount you would make if you sold your item right now.

### OSINT

#### Hashing
Expand All @@ -37,21 +75,21 @@ All commands are alternatively available as slash commands that better indicate
` >>osint query ip <ip>`
- Queries for leaks based on a last IP.

` >>osint query password <password>`
- Queries for leaks based on a password.

` >>osint query name <name>`
- Queries for leaks based on a name.

` >>osint query username <username>`
- Queries for leaks based on a username.

` >>osint query password <password>`
- Queries for leaks based on a password.

` >>osint query email <email>`
- Queries for leaks based on an email.

` >>osint query hash <hash>`
- Queries for leaks based on a hash.

` >>osint query username <username>`
- Queries for leaks based on a username.

#### Other

` >>osint sherlock <username>`
Expand All @@ -63,57 +101,19 @@ All commands are alternatively available as slash commands that better indicate
` >>osint geolocate <ip>`
- Geolocates an IP.

### R6

#### Economy

` >>r6 econ profit <$ bought for> <item name | item id>`
- Calculates the amount you would make if you sold your item right now.

` >>r6 econ list`
` >>r6 econ list <page #>`
- Lists all available skins.

` >>r6 econ analyze <item name | item id>`
- Creates a detailed data sheet on an item.

` >>r6 econ graph <item name | item id>`
- Graphs the all-time history of an item.

` >>r6 econ transfer`
` >>r6 econ transfer <ubisoft email> <ubisoft password>`
- Finds the items with the least sellers either globally or on the account with the provided login.

#### OPSEC

` >>r6 opsec psn <username>`
- Looks up a Ubisoft account based on their registered PSN username.

` >>r6 opsec applications <username>`
- Looks up a Ubisoft account based on their username (PC only).

` >>r6 opsec recon <username>`
- Analyzes a Ubisoft account for suspicious behaviour based on their username (PC only).

` >>r6 opsec pc <username>`
- Looks up a Ubisoft account based on their registered PC username.

` >>r6 opsec xbox <username>`
- Looks up a Ubisoft account based on their registered Xbox username.

### Admin

` >>admin dm <user id> <message>`
- DMs a message to a specific user.
` >>admin whitelist <section> <user id>`
- Adds a person to the authorized user list.

` >>admin blacklist <section> <user id>`
- Removes a person from the authorized user list.

` >>admin announce <sections> <message>`
- Announces a message to all whitelisted users.

` >>admin whitelist <section> <user id>`
- Adds a person to the authorized user list.
` >>admin dm <user id> <message>`
- DMs a message to a specific user.


## Setup
Expand Down
33 changes: 23 additions & 10 deletions src/helper/command.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::{bot::Sendable, lib::{get_random_anime_girl, AsyncFnPtr}};
use crate::helper::bot::BackendHandles;
use crate::{helper::bot::BackendHandles, info};

use std::{collections::{HashMap, VecDeque}, sync::Arc};

use anyhow::{Result, anyhow, bail};
use async_recursion::async_recursion;
use serenity::all::{CreateCommand, CreateCommandOption};
use tokio::sync::Mutex;
use colored::Colorize;


pub struct R6RSLeafCommand {
Expand Down Expand Up @@ -245,8 +246,10 @@ impl R6RSCommand {
R6RSCommandType::LeafCommand(R6RSLeafCommand{function, required_authorization, valid_args: _}) => {
// This only applies to Discord sendables
let value = sendable.lock().await;

// Verify that the sender of the message is in the required section
let mut auth = true;
if let Sendable::DiscordResponseSender(ref inner) = *value {
// Verify that the sender of the message is in the required section
if let Some(required_section) = required_authorization {
if !backend_handles.state.lock().await
.bot_data
Expand All @@ -256,17 +259,27 @@ impl R6RSCommand {
.iter()
.any(|val| val.as_i64().expect("Unreachable") == inner.author.id.get() as i64) {

sendable.lock().await.send(
"No Access".to_string(),
"You do not have access to this command!".to_string(),
get_random_anime_girl().to_string()
).await
.unwrap();

return Ok(());
auth = false;
}
}
}

// Prevents a deadlock
drop(value);

if !auth {
sendable.lock().await.send(
"No Access".to_string(),
"You do not have access to this command!".to_string(),
get_random_anime_girl().to_string()
).await
.unwrap();

info!("Unauthorized access to command!");

return Ok(());
}


function.run(backend_handles, sendable.clone(), args).await
.map_err(|e| anyhow!("Encountered an error!\n\n{e:#?}"))
Expand Down

0 comments on commit a787ae5

Please sign in to comment.