fixed dispatching, prototype handler

This commit is contained in:
Brandon Thomas committed 2021-04-29 00:49:16 -04:00
1 parent 1780c6c0cf
commit 28e8f4e67c
4 files changed
+38 -6

No files matched your search

+11 -5
View File
@@ -42,13 +42,19 @@ impl Dispatcher {
Some(caps) => caps,
};
info!("Captures: {:?}", captures);
let command = match captures.get(1) {
None => return,
Some(cmd) => cmd.as_str().trim().to_lowercase(),
};
if let Some(ref handler) = self.handlers.get(&captures[0]) {
info!("Captures: {:?}", captures);
handler.handle_message(&captures[0], &captures[1], twitch_message);
let unparsed_payload = match captures.get(2) {
None => return,
Some(p) => p.as_str().trim(),
};
if let Some(ref handler) = self.handlers.get(&command) {
handler.handle_message(&command, unparsed_payload, twitch_message);
}
}
}
@@ -0,0 +1,17 @@
use crate::dispatcher::Handler;
use crate::protos::protos;
pub struct CoordinateAndGeocodeHandler {
}
impl CoordinateAndGeocodeHandler {
pub fn new() -> Self {
Self {}
}
}
impl Handler for CoordinateAndGeocodeHandler {
fn handle_message(&self, command: &str, unparsed_command_args: &str, twitch_message: protos::TwitchMessage) {
todo!()
}
}
+1
View File
@@ -0,0 +1 @@
pub mod coordinate_and_geocode_handler;
+9 -1
View File
@@ -2,10 +2,12 @@
extern crate serde_derive;
mod dispatcher;
mod handlers;
mod protos;
mod redis_client;
mod redis_subscriber;
mod secrets;
use anyhow::anyhow;
use anyhow::{Context, Error};
use log::{warn, info};
@@ -18,6 +20,7 @@ use crate::secrets::Secrets;
use crate::redis_client::RedisClient;
use crate::redis_subscriber::RedisSubscribeClient;
use crate::dispatcher::Dispatcher;
use crate::handlers::coordinate_and_geocode_handler::CoordinateAndGeocodeHandler;
pub type AnyhowResult<T> = anyhow::Result<T>;
@@ -33,7 +36,12 @@ async fn main() -> anyhow::Result<()> {
let secrets = Secrets::from_file("secrets.toml")?;
let dispatcher = Dispatcher::new();
let mut dispatcher = Dispatcher::new();
let coord_geo_handler = CoordinateAndGeocodeHandler::new();
dispatcher.add_handler("goto", Box::new(coord_geo_handler));
let mut redis_client = RedisSubscribeClient::new(
&secrets.redis,