Skip to content

Commit

Permalink
feat: send incoming messages using bevys event system
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianSpeitel committed Jul 10, 2024
1 parent f5b4b2b commit 8913e78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl bevy_app::Plugin for IRCPlugin {
app.add_plugins(bevy_time::TimePlugin);
}

app.add_event::<components::Incoming>();
app.world_mut()
.observe(systems::send::<irc_prelude::Message>);
app.world_mut()
Expand Down
9 changes: 7 additions & 2 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ pub fn request_capabilities(
}
}

pub fn poll_stream(mut commands: Commands, mut streams: Query<(Entity, &mut Stream)>) {
pub fn poll_stream(
mut commands: Commands,
mut streams: Query<(Entity, &mut Stream)>,
mut incoming: EventWriter<Incoming>,
) {
use futures_util::StreamExt;
for (id, mut stream) in &mut streams {
loop {
Expand All @@ -180,7 +184,8 @@ pub fn poll_stream(mut commands: Commands, mut streams: Query<(Entity, &mut Stre
trace!(message = "Received message", ?msg);
let command = Incoming(msg.command.clone());
commands.trigger_targets(command, id);
commands.trigger_targets(Incoming(msg), id);
commands.trigger_targets(Incoming(msg.clone()), id);
incoming.send(Incoming(msg));
}
Some(Err(e)) => {
error!(message = "Failed to poll stream", error=%e, ?stream);
Expand Down

0 comments on commit 8913e78

Please sign in to comment.