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::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::instance::Snapshot` renamed to `ConnSnapshot`
|
||||
- **(breaking)** `conn::Conn::connect` now returns `conn::Result`
|
||||
- `bot::instance::Instance` now implements `Clone`
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use euphoxide::api::packet::ParsedPacket;
|
||||
use euphoxide::api::{Data, Nick, Send};
|
||||
use euphoxide::bot::instance::{Event, ServerConfig, Snapshot};
|
||||
use euphoxide::bot::instance::{ConnSnapshot, Event, ServerConfig};
|
||||
use time::OffsetDateTime;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ fn format_delta(delta: time::Duration) -> String {
|
|||
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 {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use euphoxide::api::packet::ParsedPacket;
|
||||
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 time::OffsetDateTime;
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -44,7 +44,7 @@ fn format_delta(delta: time::Duration) -> String {
|
|||
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 {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::api::{Data, SendEvent};
|
|||
use crate::conn;
|
||||
|
||||
use super::command::{Command, Context};
|
||||
use super::instance::{InstanceConfig, Snapshot};
|
||||
use super::instance::{ConnSnapshot, InstanceConfig};
|
||||
|
||||
pub struct Commands<B, E> {
|
||||
commands: Vec<Box<dyn Command<B, E> + Send + Sync>>,
|
||||
|
|
@ -55,7 +55,7 @@ impl<B, E> Commands<B, E> {
|
|||
&self,
|
||||
config: &InstanceConfig,
|
||||
packet: &ParsedPacket,
|
||||
snapshot: &Snapshot,
|
||||
snapshot: &ConnSnapshot,
|
||||
bot: &mut B,
|
||||
) -> Result<bool, E> {
|
||||
let msg = match &packet.content {
|
||||
|
|
|
|||
|
|
@ -193,12 +193,12 @@ impl InstanceConfig {
|
|||
|
||||
/// Snapshot of a [`Conn`]'s state immediately after receiving a packet.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Snapshot {
|
||||
pub struct ConnSnapshot {
|
||||
pub conn_tx: ConnTx,
|
||||
pub state: State,
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
impl ConnSnapshot {
|
||||
fn from_conn(conn: &Conn) -> Self {
|
||||
Self {
|
||||
conn_tx: conn.tx().clone(),
|
||||
|
|
@ -224,8 +224,8 @@ impl Snapshot {
|
|||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
Connecting(InstanceConfig),
|
||||
Connected(InstanceConfig, Snapshot),
|
||||
Packet(InstanceConfig, ParsedPacket, Snapshot),
|
||||
Connected(InstanceConfig, ConnSnapshot),
|
||||
Packet(InstanceConfig, ParsedPacket, ConnSnapshot),
|
||||
Disconnected(InstanceConfig),
|
||||
Stopped(InstanceConfig),
|
||||
}
|
||||
|
|
@ -458,7 +458,10 @@ impl Instance {
|
|||
.map_err(RunError::CouldNotConnect)?;
|
||||
|
||||
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();
|
||||
select! {
|
||||
|
|
@ -474,7 +477,7 @@ impl Instance {
|
|||
) -> Result<(), RunError> {
|
||||
loop {
|
||||
let packet = conn.recv().await.map_err(RunError::Conn)?;
|
||||
let snapshot = Snapshot::from_conn(conn);
|
||||
let snapshot = ConnSnapshot::from_conn(conn);
|
||||
|
||||
match &packet.content {
|
||||
Ok(Data::SnapshotEvent(snapshot)) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue