diff --git a/src/dispatcher.rs b/src/dispatcher.rs index 2003268d61..ff13349950 100644 --- a/src/dispatcher.rs +++ b/src/dispatcher.rs @@ -5,7 +5,7 @@ use log::{info, warn, debug}; use regex::Regex; use std::collections::HashMap; -use crate::proto_utils::{InboundEventSource, InboundEvent}; +use crate::inbound_proto_utils::{InboundEventSource, InboundEvent}; use crate::AnyhowResult; use crate::handlers::coordinate_and_geocode_handler::CoordinateAndGeocodeHandler; use crate::text_chat_parsers::first_pass_command_parser::FirstPassParsedCommand; @@ -48,9 +48,12 @@ impl Dispatcher { } }; + // TODO... other event types, including non-text commands. + Ok(()) } + /// Handle text-based commands. fn handle_text_command(&self, command: &FirstPassParsedCommand, event: &InboundEvent, @@ -68,4 +71,3 @@ impl Dispatcher { handler.handle_text_command(command, event, event_source) } } - diff --git a/src/handlers/coordinate_and_geocode_handler.rs b/src/handlers/coordinate_and_geocode_handler.rs index a2697e9da9..9ab0151f8a 100644 --- a/src/handlers/coordinate_and_geocode_handler.rs +++ b/src/handlers/coordinate_and_geocode_handler.rs @@ -8,7 +8,7 @@ use prost::Message; use regex::Regex; use std::sync::{RwLock, Arc, Mutex}; use crate::text_chat_parsers::first_pass_command_parser::FirstPassParsedCommand; -use crate::proto_utils::{InboundEvent, InboundEventSource}; +use crate::inbound_proto_utils::{InboundEvent, InboundEventSource}; use crate::AnyhowResult; // TODO: maybe separate text command handling and data source concerns @@ -24,25 +24,35 @@ impl CoordinateAndGeocodeHandler { } } - /*fn handle_lat_long(&self, lat_long: LatLong, twitch_message: protos::TwitchMessage) { + fn handle_lat_long(&self, + lat_long: LatLong, + event: &InboundEvent, + event_source: &InboundEventSource) + -> AnyhowResult<()> { + let mut cesium_proto = protos::CesiumWarpRequest::default(); // Cesium cesium_proto.latitude = lat_long.latitude; cesium_proto.longitude = lat_long.longitude; - // Twitch - cesium_proto.twitch_channel = twitch_message.channel.clone().unwrap_or("".to_string()); - cesium_proto.twitch_username = twitch_message.username.clone().unwrap_or("".to_string()); - cesium_proto.twitch_user_id = twitch_message.user_id.clone().unwrap_or(0); - cesium_proto.twitch_user_is_mod = twitch_message.is_mod.unwrap_or(false); - cesium_proto.twitch_user_is_subscribed = twitch_message.is_subscribed.unwrap_or(false); + match event_source { + InboundEventSource::Twitch(ref twitch_source) => { + // Twitch + cesium_proto.twitch_channel = twitch_source.username().to_string(); + //cesium_proto.twitch_username = twitch_message.username.clone().unwrap_or("".to_string()); + //cesium_proto.twitch_user_id = twitch_message.user_id.clone().unwrap_or(0); + //cesium_proto.twitch_user_is_mod = twitch_message.is_mod.unwrap_or(false); + //cesium_proto.twitch_user_is_subscribed = twitch_message.is_subscribed.unwrap_or(false); + } + } + + // TODO: Populate source data info!("Proto: {:?}", cesium_proto); let mut unreal_proto = protos::UnrealEventPayloadV1::default(); unreal_proto.payload_type = protos::unreal_event_payload_v1::PayloadType::CesiumWarp as i32; - unreal_proto.debug_message = "Hello from Rust!".to_string(); let mut buffer : Vec = Vec::with_capacity(cesium_proto.encoded_len()); @@ -53,7 +63,7 @@ impl CoordinateAndGeocodeHandler { match encode_result { Err(e) => { warn!("Inner proto encode result: {:?}", e); - return; + return Ok(()); } Ok(_) => { unreal_proto.payload_data = buffer; @@ -68,7 +78,7 @@ impl CoordinateAndGeocodeHandler { match encode_result { Err(e) => { warn!("Outer proto encode result: {:?}", e); - return; + return Ok(()); } Ok(_) => {} } @@ -85,7 +95,9 @@ impl CoordinateAndGeocodeHandler { }, Err(_) => {}, } - }*/ + + Ok(()) + } } impl TextCommandHandler for CoordinateAndGeocodeHandler { diff --git a/src/proto_utils.rs b/src/inbound_proto_utils.rs similarity index 100% rename from src/proto_utils.rs rename to src/inbound_proto_utils.rs diff --git a/src/main.rs b/src/main.rs index 77e9526d2a..950308f689 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,8 @@ extern crate serde_derive; mod dispatcher; mod handlers; -mod proto_utils; +mod inbound_proto_utils; +mod outbound_proto_utils; mod protos; mod redis_client; mod redis_subscriber; diff --git a/src/outbound_proto_utils.rs b/src/outbound_proto_utils.rs new file mode 100644 index 0000000000..65ef4e366e --- /dev/null +++ b/src/outbound_proto_utils.rs @@ -0,0 +1,16 @@ +use anyhow::anyhow; +use crate::AnyhowResult; +use crate::protos::protos::IngestionTwitchMessage; +use crate::protos::protos::IngestionTwitchMetadata; +use crate::protos::protos::PubsubEventPayloadV1; +use crate::protos::protos::pubsub_event_payload_v1::IngestionPayloadType; +use crate::protos::protos::pubsub_event_payload_v1::IngestionSourceType; +use crate::protos::protos; +use prost::Message; + +pub enum OutboundPayload { +} + +pub enum OutboundSourceInfo { + Twitch(), +} \ No newline at end of file