Skip to content

Commit

Permalink
Remove some warnings and fix json
Browse files Browse the repository at this point in the history
  • Loading branch information
nayvcake committed Mar 13, 2022
1 parent 6fbb5e8 commit 1fbfa26
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 45 deletions.
102 changes: 57 additions & 45 deletions src/routes/interaction/interaction_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::routes::websocket::websocket_server::convert_to_binary;
pub async fn interaction_create(pub_key: String, sign: String, timestamp: String, json: HashMap<String, Value>, clients: Clients, interactions: Interactions) -> Result<impl warp::Reply, Infallible>
{
let keys_with_space = pub_key.split(" ");
#[allow(unused_variables)]
for key in keys_with_space {
let verify_sign = sign_mod::verify_authorization(String::from(dotenv::var("PUBLIC_KEY").unwrap()), sign, format!("{}{}", timestamp, json!(json)));
match verify_sign {
Expand All @@ -25,21 +26,24 @@ pub async fn interaction_create(pub_key: String, sign: String, timestamp: String
if json.get("application_id").is_none() {
return Ok(warp::reply::with_status(warp::reply::json(&json!({ "type": 5, "message_err": "API cannot accept this metadata because application was not included! Please resend again." }).as_object_mut()), warp::http::StatusCode::NOT_ACCEPTABLE))
}
#[allow(unreachable_code)]
for (id, client) in clients.read().await.iter() {
if json.get("application_id").unwrap() == id {
if let Err(_disconnected) = client.ws.tx.send(Message::binary(convert_to_binary(&json!(json)))) {

return Ok(warp::reply::with_status(warp::reply::json(&json!({
"type": 4,
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": "#ff1212",
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
"data": {
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": 0xff1212,
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
}
}).as_object_mut()), warp::http::StatusCode::OK));

break;
Expand All @@ -53,15 +57,17 @@ pub async fn interaction_create(pub_key: String, sign: String, timestamp: String

return Ok(warp::reply::with_status(warp::reply::json(&json!({
"type": 4,
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": "#ff1212",
"description": "I didn't get a response from the bot, try again or you can contact the developer through the support server."
}
],
"allowed_mentions": []
"data": {
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": 0xff1212,
"description": "I didn't get a response from the bot, try again or you can contact the developer through the support server."
}
],
"allowed_mentions": []
}
}).as_object_mut()), warp::http::StatusCode::OK))

}
Expand All @@ -76,15 +82,17 @@ pub async fn interaction_create(pub_key: String, sign: String, timestamp: String
if let Err(_disconnected) = client.ws.tx.send(Message::binary(convert_to_binary(&json!(json)))) {
return Ok(warp::reply::with_status(warp::reply::json(&json!({
"type": 4,
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": "#ff1212",
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
"data": {
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": 0xff1212,
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
}
}).as_object_mut()), warp::http::StatusCode::OK));
}
tokio::time::sleep(Duration::from_millis(400)).await;
Expand All @@ -111,15 +119,17 @@ pub async fn interaction_create(pub_key: String, sign: String, timestamp: String
if let Err(_disconnected) = client.ws.tx.send(Message::binary(convert_to_binary(&json!(json)))) {
return Ok(warp::reply::with_status(warp::reply::json(&json!({
"type": 4,
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": "#ff1212",
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
"data": {
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": 0xff1212,
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
}
}).as_object_mut()), warp::http::StatusCode::OK));
}

Expand All @@ -138,15 +148,17 @@ pub async fn interaction_create(pub_key: String, sign: String, timestamp: String
if let Err(_disconnected) = client.ws.tx.send(Message::binary(convert_to_binary(&json!(json)))) {
return Ok(warp::reply::with_status(warp::reply::json(&json!({
"type": 4,
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": "#ff1212",
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
"data": {
"tts": false,
"content": "There was a problem with the interaction!",
"embeds": [
{
"color": 0xff1212,
"description": "The connection was lost by the bot. Contact bot developer."
}
],
"allowed_mentions": []
}
}).as_object_mut()), warp::http::StatusCode::OK));
}
tokio::time::sleep(Duration::from_millis(400)).await;
Expand Down
2 changes: 2 additions & 0 deletions src/routes/websocket/structures/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ pub struct ClientWs {
}

impl ClientBot {
#[allow(dead_code)]
fn update_id(&self) -> &String { &self.ws._id }
#[allow(dead_code)]
fn update_tx(&self) -> &UnboundedSender<Message> { &self.ws.tx }
}

Expand Down

0 comments on commit 1fbfa26

Please sign in to comment.