Add Instances::is_from_known_instance
This commit is contained in:
parent
480ea3bd82
commit
f60420afa5
2 changed files with 14 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ Procedure when bumping the version number:
|
|||
- `bot::botrulez::FullHelp` now implements `bot::command::Command`
|
||||
- `bot::botrulez::Ping` now implements `bot::command::Command`
|
||||
- `bot::botrulez::ShortHelp` now implements `bot::command::Command`
|
||||
- `bot::instances::Instances::is_from_known_instance`
|
||||
|
||||
### Changed
|
||||
- Instances log to target `euphoxide::live::<name>`
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::instance::{Instance, ServerConfig};
|
||||
use super::instance::{self, Instance, ServerConfig};
|
||||
|
||||
/// A convenient way to keep a [`ServerConfig`] and some [`Instance`]s.
|
||||
pub struct Instances {
|
||||
|
|
@ -26,6 +26,18 @@ impl Instances {
|
|||
self.instances.values()
|
||||
}
|
||||
|
||||
/// Check if an event comes from an instance whose name is known.
|
||||
///
|
||||
/// Assuming every instance has a unique name, events from unknown instances
|
||||
/// should be discarded. This helps prevent "ghost instances" that were
|
||||
/// stopped but haven't yet disconnected properly from influencing your
|
||||
/// bot's state.
|
||||
///
|
||||
/// The user is responsible for ensuring that instances' names are unique.
|
||||
pub fn is_from_known_instance(&self, event: &instance::Event) -> bool {
|
||||
self.instances.contains_key(&event.config().name)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.instances.is_empty()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue