Convert project to workspace with Tonic for gRPC. #84
|
@ -1,18 +1,20 @@
|
|||
use tenebrous_rpc::protos::dicebot::dicebot_client::DicebotClient;
|
||||
use tenebrous_rpc::protos::dicebot::UserIdRequest;
|
||||
use tenebrous_rpc::protos::dicebot::{dicebot_client::DicebotClient, GetVariableRequest};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut client = DicebotClient::connect("http://0.0.0.0:9090").await?;
|
||||
|
||||
let request = tonic::Request::new(UserIdRequest {
|
||||
user_id: "Tonic".into(),
|
||||
let request = tonic::Request::new(GetVariableRequest {
|
||||
user_id: "@projectmoon:agnos.is".into(),
|
||||
room_id: "!agICWvldGfuCywUVUM:agnos.is".into(),
|
||||
variable_name: "stuff".into(),
|
||||
});
|
||||
|
||||
let response = client.rooms_for_user(request).await?.into_inner();
|
||||
let response = client.get_variable(request).await?.into_inner();
|
||||
|
||||
println!("RESPONSE={:?}", response);
|
||||
println!("User friendly response is: {:?}", response.room_ids);
|
||||
println!("User friendly response is: {:?}", response.value);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,15 +1,27 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::db::{errors::DataError, Variables};
|
||||
use crate::error::BotError;
|
||||
use crate::{config::Config, db::sqlite::Database};
|
||||
use log::info;
|
||||
use std::sync::Arc;
|
||||
use tenebrous_rpc::protos::dicebot::{
|
||||
dicebot_server::{Dicebot, DicebotServer},
|
||||
GetAllVariablesReply, GetAllVariablesRequest, RoomsListReply, SetVariableReply,
|
||||
SetVariableRequest, UserIdRequest,
|
||||
};
|
||||
use tenebrous_rpc::protos::dicebot::{GetVariableReply, GetVariableRequest};
|
||||
use tonic::{transport::Server, Request, Response, Status};
|
||||
use tonic::{transport::Server, Code, Request, Response, Status};
|
||||
|
||||
impl From<BotError> for Status {
|
||||
fn from(error: BotError) -> Status {
|
||||
Status::new(Code::Internal, error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DataError> for Status {
|
||||
fn from(error: DataError) -> Status {
|
||||
Status::new(Code::Internal, error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DicebotRpcService {
|
||||
config: Arc<Config>,
|
||||
|
@ -29,7 +41,13 @@ impl Dicebot for DicebotRpcService {
|
|||
&self,
|
||||
request: Request<GetVariableRequest>,
|
||||
) -> Result<Response<GetVariableReply>, Status> {
|
||||
Ok(Response::new(GetVariableReply { value: 1 }))
|
||||
let request = request.into_inner();
|
||||
let value = self
|
||||
.db
|
||||
.get_user_variable(&request.user_id, &request.room_id, &request.variable_name)
|
||||
.await?;
|
||||
|
||||
Ok(Response::new(GetVariableReply { value }))
|
||||
}
|
||||
|
||||
async fn get_all_variables(
|
||||
|
|
Loading…
Reference in New Issue