2020-09-28 21:35:05 +00:00
|
|
|
use crate::config::*;
|
|
|
|
use log::info;
|
2020-10-03 20:31:42 +00:00
|
|
|
use std::sync::Arc;
|
2020-09-28 21:35:05 +00:00
|
|
|
|
|
|
|
/// Holds state of the dice bot, for anything requiring mutable
|
|
|
|
/// transitions. This is a simple mutable trait whose values represent
|
|
|
|
/// the current state of the dicebot. It provides mutable methods to
|
|
|
|
/// change state.
|
|
|
|
pub struct DiceBotState {
|
|
|
|
logged_skipped_old_messages: bool,
|
2020-10-17 13:30:07 +00:00
|
|
|
_config: Arc<Config>,
|
2020-09-28 21:35:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DiceBotState {
|
|
|
|
/// Create initial dice bot state.
|
2020-10-03 20:31:42 +00:00
|
|
|
pub fn new(config: &Arc<Config>) -> DiceBotState {
|
2020-09-28 21:35:05 +00:00
|
|
|
DiceBotState {
|
|
|
|
logged_skipped_old_messages: false,
|
2020-10-17 13:30:07 +00:00
|
|
|
_config: config.clone(),
|
2020-09-28 21:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 13:30:07 +00:00
|
|
|
pub fn logged_skipped_old_messages(&self) -> bool {
|
|
|
|
self.logged_skipped_old_messages
|
|
|
|
}
|
|
|
|
|
2020-09-28 21:35:05 +00:00
|
|
|
/// Log and record that we have skipped some old messages. This
|
|
|
|
/// method will log once, and then no-op from that point on.
|
|
|
|
pub fn skipped_old_messages(&mut self) {
|
|
|
|
if !self.logged_skipped_old_messages {
|
|
|
|
info!("Skipped some messages received while offline because they are too old.");
|
|
|
|
}
|
|
|
|
|
|
|
|
self.logged_skipped_old_messages = true;
|
|
|
|
}
|
|
|
|
}
|