Rename Snapshot to ConnSnapshot
This commit is contained in:
parent
0f217a6279
commit
34f33ff038
5 changed files with 16 additions and 12 deletions
|
|
@ -24,6 +24,7 @@ Procedure when bumping the version number:
|
||||||
- **(breaking)** `bot::command::ClapCommand::execute` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
- **(breaking)** `bot::command::ClapCommand::execute` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
||||||
- **(breaking)** `bot::command::Command::execute` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
- **(breaking)** `bot::command::Command::execute` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
||||||
- **(breaking)** `bot::commands::Commands::handle_packet` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
- **(breaking)** `bot::commands::Commands::handle_packet` now returns a `Result<bool, E>` instead of a `Result<(), E>`
|
||||||
|
- **(breaking)** `bot::instance::Snapshot` renamed to `ConnSnapshot`
|
||||||
- **(breaking)** `conn::Conn::connect` now returns `conn::Result`
|
- **(breaking)** `conn::Conn::connect` now returns `conn::Result`
|
||||||
- `bot::instance::Instance` now implements `Clone`
|
- `bot::instance::Instance` now implements `Clone`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use euphoxide::api::packet::ParsedPacket;
|
use euphoxide::api::packet::ParsedPacket;
|
||||||
use euphoxide::api::{Data, Nick, Send};
|
use euphoxide::api::{Data, Nick, Send};
|
||||||
use euphoxide::bot::instance::{Event, ServerConfig, Snapshot};
|
use euphoxide::bot::instance::{ConnSnapshot, Event, ServerConfig};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ fn format_delta(delta: time::Duration) -> String {
|
||||||
parts.join(" ")
|
parts.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_packet(packet: ParsedPacket, snapshot: Snapshot) -> Result<(), ()> {
|
async fn on_packet(packet: ParsedPacket, snapshot: ConnSnapshot) -> Result<(), ()> {
|
||||||
let data = match packet.content {
|
let data = match packet.content {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use euphoxide::api::packet::ParsedPacket;
|
use euphoxide::api::packet::ParsedPacket;
|
||||||
use euphoxide::api::{Data, Nick, Send};
|
use euphoxide::api::{Data, Nick, Send};
|
||||||
use euphoxide::bot::instance::{Event, ServerConfig, Snapshot};
|
use euphoxide::bot::instance::{ConnSnapshot, Event, ServerConfig};
|
||||||
use euphoxide::bot::instances::Instances;
|
use euphoxide::bot::instances::Instances;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
@ -44,7 +44,7 @@ fn format_delta(delta: time::Duration) -> String {
|
||||||
parts.join(" ")
|
parts.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_packet(packet: ParsedPacket, snapshot: Snapshot) -> Result<(), ()> {
|
async fn on_packet(packet: ParsedPacket, snapshot: ConnSnapshot) -> Result<(), ()> {
|
||||||
let data = match packet.content {
|
let data = match packet.content {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::api::{Data, SendEvent};
|
||||||
use crate::conn;
|
use crate::conn;
|
||||||
|
|
||||||
use super::command::{Command, Context};
|
use super::command::{Command, Context};
|
||||||
use super::instance::{InstanceConfig, Snapshot};
|
use super::instance::{ConnSnapshot, InstanceConfig};
|
||||||
|
|
||||||
pub struct Commands<B, E> {
|
pub struct Commands<B, E> {
|
||||||
commands: Vec<Box<dyn Command<B, E> + Send + Sync>>,
|
commands: Vec<Box<dyn Command<B, E> + Send + Sync>>,
|
||||||
|
|
@ -55,7 +55,7 @@ impl<B, E> Commands<B, E> {
|
||||||
&self,
|
&self,
|
||||||
config: &InstanceConfig,
|
config: &InstanceConfig,
|
||||||
packet: &ParsedPacket,
|
packet: &ParsedPacket,
|
||||||
snapshot: &Snapshot,
|
snapshot: &ConnSnapshot,
|
||||||
bot: &mut B,
|
bot: &mut B,
|
||||||
) -> Result<bool, E> {
|
) -> Result<bool, E> {
|
||||||
let msg = match &packet.content {
|
let msg = match &packet.content {
|
||||||
|
|
|
||||||
|
|
@ -193,12 +193,12 @@ impl InstanceConfig {
|
||||||
|
|
||||||
/// Snapshot of a [`Conn`]'s state immediately after receiving a packet.
|
/// Snapshot of a [`Conn`]'s state immediately after receiving a packet.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Snapshot {
|
pub struct ConnSnapshot {
|
||||||
pub conn_tx: ConnTx,
|
pub conn_tx: ConnTx,
|
||||||
pub state: State,
|
pub state: State,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Snapshot {
|
impl ConnSnapshot {
|
||||||
fn from_conn(conn: &Conn) -> Self {
|
fn from_conn(conn: &Conn) -> Self {
|
||||||
Self {
|
Self {
|
||||||
conn_tx: conn.tx().clone(),
|
conn_tx: conn.tx().clone(),
|
||||||
|
|
@ -224,8 +224,8 @@ impl Snapshot {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Connecting(InstanceConfig),
|
Connecting(InstanceConfig),
|
||||||
Connected(InstanceConfig, Snapshot),
|
Connected(InstanceConfig, ConnSnapshot),
|
||||||
Packet(InstanceConfig, ParsedPacket, Snapshot),
|
Packet(InstanceConfig, ParsedPacket, ConnSnapshot),
|
||||||
Disconnected(InstanceConfig),
|
Disconnected(InstanceConfig),
|
||||||
Stopped(InstanceConfig),
|
Stopped(InstanceConfig),
|
||||||
}
|
}
|
||||||
|
|
@ -458,7 +458,10 @@ impl Instance {
|
||||||
.map_err(RunError::CouldNotConnect)?;
|
.map_err(RunError::CouldNotConnect)?;
|
||||||
|
|
||||||
Self::set_cookies(config, cookies);
|
Self::set_cookies(config, cookies);
|
||||||
on_event(Event::Connected(config.clone(), Snapshot::from_conn(&conn)));
|
on_event(Event::Connected(
|
||||||
|
config.clone(),
|
||||||
|
ConnSnapshot::from_conn(&conn),
|
||||||
|
));
|
||||||
|
|
||||||
let conn_tx = conn.tx().clone();
|
let conn_tx = conn.tx().clone();
|
||||||
select! {
|
select! {
|
||||||
|
|
@ -474,7 +477,7 @@ impl Instance {
|
||||||
) -> Result<(), RunError> {
|
) -> Result<(), RunError> {
|
||||||
loop {
|
loop {
|
||||||
let packet = conn.recv().await.map_err(RunError::Conn)?;
|
let packet = conn.recv().await.map_err(RunError::Conn)?;
|
||||||
let snapshot = Snapshot::from_conn(conn);
|
let snapshot = ConnSnapshot::from_conn(conn);
|
||||||
|
|
||||||
match &packet.content {
|
match &packet.content {
|
||||||
Ok(Data::SnapshotEvent(snapshot)) => {
|
Ok(Data::SnapshotEvent(snapshot)) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue