Skip to content

Commit d7dfaba

Browse files
committed
feat(bot): add maintenance mode state to BotState
1 parent 17d8868 commit d7dfaba

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

rustmail/src/bot.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use serenity::prelude::TypeMapKey;
1111
use std::collections::HashMap;
1212
use std::process;
1313
use std::sync::Arc;
14+
use std::sync::atomic::AtomicBool;
1415
use std::time::Duration;
1516
use tokio::sync::Mutex;
1617
use tokio::{select, spawn};
@@ -36,6 +37,7 @@ pub async fn init_bot_state() -> Arc<Mutex<BotState>> {
3637
command_tx: command_tx.clone(),
3738
bot_http: None,
3839
bot_context: Arc::new(tokio::sync::RwLock::new(None)),
40+
maintenance_mode: Arc::new(AtomicBool::new(false)),
3941
};
4042

4143
Arc::new(Mutex::new(bot_state))
@@ -90,12 +92,15 @@ pub async fn run_bot(
9092
state_lock.db_pool.clone().expect("Database pool not set")
9193
};
9294

93-
let mut config = {
95+
let (mut config, maintenance_mode) = {
9496
let state_lock = bot_state.lock().await;
9597
if state_lock.config.is_none() {
9698
panic!("Config not set before starting rustmail!");
9799
}
98-
state_lock.config.clone().expect("Config not set")
100+
(
101+
state_lock.config.clone().expect("Config not set"),
102+
state_lock.maintenance_mode.clone(),
103+
)
99104
};
100105

101106
let pagination = Arc::new(Mutex::new(HashMap::<String, PaginationContext>::new()));
@@ -157,6 +162,7 @@ pub async fn run_bot(
157162
registry.clone(),
158163
shutdown_rx.clone(),
159164
pagination.clone(),
165+
maintenance_mode.clone(),
160166
)
161167
.await,
162168
)
@@ -169,6 +175,7 @@ pub async fn run_bot(
169175
registry.clone(),
170176
shutdown_rx,
171177
pagination,
178+
maintenance_mode,
172179
))
173180
.event_handler(GuildHandler::new(&config))
174181
.await

rustmail/src/types/bot.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::prelude::config::*;
22
use serenity::all::{Context, Http};
33
use std::sync::Arc;
4+
use std::sync::atomic::AtomicBool;
45
use tokio::sync::{RwLock, watch::Sender};
56
use tokio::task::JoinHandle;
67

@@ -26,4 +27,5 @@ pub struct BotState {
2627
pub command_tx: tokio::sync::mpsc::Sender<BotCommand>,
2728
pub bot_http: Option<Arc<Http>>,
2829
pub bot_context: Arc<RwLock<Option<Context>>>,
30+
pub maintenance_mode: Arc<AtomicBool>,
2931
}

0 commit comments

Comments
 (0)