Implement get variable
This commit is contained in:
parent
2f60bbc643
commit
d4a041129b
|
@ -1,18 +1,20 @@
|
||||||
use tenebrous_rpc::protos::dicebot::dicebot_client::DicebotClient;
|
|
||||||
use tenebrous_rpc::protos::dicebot::UserIdRequest;
|
use tenebrous_rpc::protos::dicebot::UserIdRequest;
|
||||||
|
use tenebrous_rpc::protos::dicebot::{dicebot_client::DicebotClient, GetVariableRequest};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut client = DicebotClient::connect("http://0.0.0.0:9090").await?;
|
let mut client = DicebotClient::connect("http://0.0.0.0:9090").await?;
|
||||||
|
|
||||||
let request = tonic::Request::new(UserIdRequest {
|
let request = tonic::Request::new(GetVariableRequest {
|
||||||
user_id: "Tonic".into(),
|
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!("RESPONSE={:?}", response);
|
||||||
println!("User friendly response is: {:?}", response.room_ids);
|
println!("User friendly response is: {:?}", response.value);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,27 @@
|
||||||
use std::sync::Arc;
|
use crate::db::{errors::DataError, Variables};
|
||||||
|
|
||||||
use crate::error::BotError;
|
use crate::error::BotError;
|
||||||
use crate::{config::Config, db::sqlite::Database};
|
use crate::{config::Config, db::sqlite::Database};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use std::sync::Arc;
|
||||||
use tenebrous_rpc::protos::dicebot::{
|
use tenebrous_rpc::protos::dicebot::{
|
||||||
dicebot_server::{Dicebot, DicebotServer},
|
dicebot_server::{Dicebot, DicebotServer},
|
||||||
GetAllVariablesReply, GetAllVariablesRequest, RoomsListReply, SetVariableReply,
|
GetAllVariablesReply, GetAllVariablesRequest, RoomsListReply, SetVariableReply,
|
||||||
SetVariableRequest, UserIdRequest,
|
SetVariableRequest, UserIdRequest,
|
||||||
};
|
};
|
||||||
use tenebrous_rpc::protos::dicebot::{GetVariableReply, GetVariableRequest};
|
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 {
|
pub struct DicebotRpcService {
|
||||||
config: Arc<Config>,
|
config: Arc<Config>,
|
||||||
|
@ -29,7 +41,13 @@ impl Dicebot for DicebotRpcService {
|
||||||
&self,
|
&self,
|
||||||
request: Request<GetVariableRequest>,
|
request: Request<GetVariableRequest>,
|
||||||
) -> Result<Response<GetVariableReply>, Status> {
|
) -> 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(
|
async fn get_all_variables(
|
||||||
|
|
Loading…
Reference in New Issue