|
|
|
|
@@ -1,18 +1,16 @@
|
|
|
|
|
use std::{sync::Arc, pin::Pin};
|
|
|
|
|
|
|
|
|
|
use actix_web::{get, post, web, HttpResponse, ResponseError};
|
|
|
|
|
use log::warn;
|
|
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
|
use serenity::model::prelude::{GuildChannel, ChannelType};
|
|
|
|
|
use siren::{ServiceError, Response};
|
|
|
|
|
|
|
|
|
|
use crate::{AppState, bot::commands::audio::{play::play_track, join}, storage::guilds::QueryGuild, auth::{JwtAuth, verify_role}};
|
|
|
|
|
use crate::{AppState, bot::commands::audio::{play::play_track, join}, bot::guilds::QueryGuild, auth::{JwtAuth, verify_role}};
|
|
|
|
|
|
|
|
|
|
#[get("/guilds")]
|
|
|
|
|
async fn get_guilds(data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_results = &data.http.get_guilds(None, None).await;
|
|
|
|
|
let guilds = match guild_results {
|
|
|
|
|
@@ -30,9 +28,8 @@ async fn get_guilds(data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpRespon
|
|
|
|
|
|
|
|
|
|
#[get("/{id}/text")]
|
|
|
|
|
async fn get_text_channels(id: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let channel_results = &data.http.get_channels(id.parse::<u64>().unwrap()).await;
|
|
|
|
|
let channels = match channel_results {
|
|
|
|
|
@@ -50,9 +47,8 @@ async fn get_text_channels(id: web::Path<String>, data: web::Data<Arc<AppState>>
|
|
|
|
|
|
|
|
|
|
#[get("/{id}/voice")]
|
|
|
|
|
async fn get_voice_channels(id: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let channel_results = &data.http.get_channels(id.parse::<u64>().unwrap()).await;
|
|
|
|
|
let channels = match channel_results {
|
|
|
|
|
@@ -75,9 +71,8 @@ struct ChannelMessage {
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/text/{channel_id}/message")]
|
|
|
|
|
async fn send_message(path: web::Path<(String, String)>, text: web::Json<ChannelMessage>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let (guild_id, channel_id) = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -136,9 +131,8 @@ struct PlayRequest {
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/{channel_id}/play")]
|
|
|
|
|
async fn play(path: web::Path<(String, String)>, play_request: web::Json<PlayRequest>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let (guild_id, channel_id) = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -186,9 +180,8 @@ async fn play(path: web::Path<(String, String)>, play_request: web::Json<PlayReq
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/stop")]
|
|
|
|
|
async fn stop(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -211,9 +204,8 @@ async fn stop(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: Jwt
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/resume")]
|
|
|
|
|
async fn resume(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -241,9 +233,8 @@ async fn resume(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: J
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/pause")]
|
|
|
|
|
async fn pause(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -276,9 +267,8 @@ struct SetVolume {
|
|
|
|
|
|
|
|
|
|
#[get("/{guild_id}/voice/volume")]
|
|
|
|
|
async fn get_volume(path: web::Path<String>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -306,9 +296,8 @@ async fn get_volume(path: web::Path<String>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/volume")]
|
|
|
|
|
async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|
|
|
|
|
@@ -337,9 +326,8 @@ async fn set_volume(path: web::Path<String>, volume: web::Json::<SetVolume>, dat
|
|
|
|
|
|
|
|
|
|
#[post("/{guild_id}/voice/skip")]
|
|
|
|
|
async fn skip(path: web::Path<String>, data: web::Data<Arc<AppState>>, auth: JwtAuth) -> HttpResponse {
|
|
|
|
|
let _ = match verify_role(&auth, "admin") {
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
Err(err) => return ResponseError::error_response(&err)
|
|
|
|
|
if let Err(err) = verify_role(&auth, "admin") {
|
|
|
|
|
return ResponseError::error_response(&err)
|
|
|
|
|
};
|
|
|
|
|
let guild_id = path.into_inner();
|
|
|
|
|
let guild_id = match guild_id.parse::<u64>() {
|