wip
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
use std::num::NonZeroU64;
|
||||
|
||||
use async_nats::Client;
|
||||
use async_trait::async_trait;
|
||||
use postcard::{from_bytes, to_stdvec};
|
||||
use types::{
|
||||
error::{CorroError, CorroErrorType},
|
||||
jobs::{JobResponse, JobsMap, JobsResponseMap},
|
||||
jobs::{JobResponse, JobsMap, JobsResponseMap, TriggerMaster},
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
pub trait JobClient {
|
||||
async fn send_job(&self, job: JobsMap) -> Result<JobsResponseMap, CorroError>;
|
||||
async fn trigger_master(&self, id: NonZeroU64) -> Result<(), CorroError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -22,7 +25,7 @@ impl JobClient for Client {
|
||||
|
||||
match self
|
||||
.request(
|
||||
format!("corro-dj.{subject}"),
|
||||
format!("corro-dj.job.{subject}"),
|
||||
to_stdvec(&job).unwrap().into(),
|
||||
)
|
||||
.await
|
||||
@@ -47,4 +50,20 @@ impl JobClient for Client {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
async fn trigger_master(&self, id: NonZeroU64) -> Result<(), CorroError> {
|
||||
match self
|
||||
.request(
|
||||
format!("corro-dj.queue.{id}"),
|
||||
to_stdvec(&TriggerMaster { guild_id: id }).unwrap().into(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
Err(why) => Err(CorroError {
|
||||
error_type: CorroErrorType::NatsError,
|
||||
message: why.to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ fn get_key(id: NonZeroU64) -> String {
|
||||
pub trait KVClient {
|
||||
async fn get_queue(&self, id: NonZeroU64) -> Result<Queue, CorroError>;
|
||||
async fn set_queue(&self, id: NonZeroU64, queue: &Queue) -> Result<u64, CorroError>;
|
||||
async fn delete_queue(&self, id: NonZeroU64) -> Result<(), CorroError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -51,4 +52,14 @@ impl KVClient for Store {
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete_queue(&self, id: NonZeroU64) -> Result<(), CorroError> {
|
||||
match self.delete(get_key(id)).await {
|
||||
Ok(_) => Ok(()),
|
||||
Err(why) => Err(CorroError {
|
||||
error_type: CorroErrorType::KVError,
|
||||
message: why.to_string(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ impl CustomInteraction for CommandInteraction {
|
||||
async fn create_text_response(&self, ctx: &Context, content: String) -> Result<(), CorroError> {
|
||||
match self
|
||||
.create_response(
|
||||
&ctx,
|
||||
&ctx.http,
|
||||
CreateInteractionResponse::Message(
|
||||
CreateInteractionResponseMessage::new().content(&content),
|
||||
),
|
||||
@@ -36,7 +36,7 @@ impl CustomInteraction for CommandInteraction {
|
||||
|
||||
async fn edit_text_response(&self, ctx: &Context, content: String) -> Result<(), CorroError> {
|
||||
match self
|
||||
.edit_response(&ctx, EditInteractionResponse::new().content(&content))
|
||||
.edit_response(&ctx.http, EditInteractionResponse::new().content(&content))
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
|
||||
@@ -6,6 +6,11 @@ use uuid::Uuid;
|
||||
|
||||
use crate::{error::CorroError, queue::YoutubeSong};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct TriggerMaster {
|
||||
pub guild_id: NonZeroU64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum JobsResponseMap {
|
||||
Search(SearchResponse),
|
||||
|
||||
@@ -4,6 +4,12 @@ use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub enum QueueStatus {
|
||||
Playing,
|
||||
Paused,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct YoutubeSong {
|
||||
pub title: String,
|
||||
@@ -23,5 +29,6 @@ pub struct YoutubePlaylist {
|
||||
pub struct Queue {
|
||||
pub uuid: Uuid,
|
||||
pub guild_id: NonZeroU64,
|
||||
pub status: QueueStatus,
|
||||
pub songs: Vec<YoutubeSong>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user