Verified Commit 19afcaa3 authored by Mathias B.'s avatar Mathias B.
Browse files

Ajout de l'envoi de messages via le RPC

parent c011a201
use actix_web::{delete, get, HttpResponse, post, put, web};
use crate::rpc_server::DiscordClient;
use crate::rpc_server::utilities::ClientError;
use serenity::model::channel::ReactionType;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct SendMessageRequestBody {
content: String,
}
#[get("/channels/{channel_id}/{message_id}")]
#[tracing::instrument]
......@@ -21,8 +28,23 @@ pub async fn get_message(path_params: web::Path<(u64, u64)>) -> Result<HttpRespo
}
#[post("/channels/{channel_id}/send")]
pub async fn send_message() -> HttpResponse {
todo!("Implémenter la méthode")
pub async fn send_message(path_params: web::Path<u64>, body: web::Json<SendMessageRequestBody>) -> Result<HttpResponse, ClientError> {
let channel_id = path_params.into_inner();
let client = DiscordClient::get();
let channel = client.cache.channel(channel_id)
.await
.ok_or(ClientError::NotFound)?;
let message = channel.id().send_message(&client.http, |builder| {
builder.content(&body.content)
}).await
.map_err(|e| {
tracing::error!("Error from Discord: {:#?}", e);
ClientError::from(e)
})?;
Ok(HttpResponse::Ok().json(message))
}
#[delete("/channels/{channel_id}/{message_id}")]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment