Add config setting controlling if a self-introduction message is posted after joining a room

Fixes https://github.com/etkecc/baibot/issues/32
This commit is contained in:
Slavi Pantaleev
2025-02-26 20:30:02 +02:00
parent 1ff7e8cf79
commit c051da2f4a
7 changed files with 49 additions and 0 deletions

View File

@@ -140,6 +140,10 @@ impl Bot {
&self.inner.config.command_prefix
}
pub(crate) fn post_join_self_introduction_enabled(&self) -> bool {
self.inner.config.room.post_join_self_introduction_enabled
}
pub(crate) fn homeserver_name(&self) -> &str {
&self.inner.config.homeserver.server_name
}

View File

@@ -35,6 +35,9 @@ pub fn load() -> anyhow::Result<Config> {
}
cfg_env::BAIBOT_USER_NAME => config.user.name = value,
cfg_env::BAIBOT_COMMAND_PREFIX => config.command_prefix = value,
cfg_env::BAIBOT_ROOM_POST_JOIN_SELF_INTRODUCTION_ENABLED => {
config.room.post_join_self_introduction_enabled = value.parse::<bool>()?;
}
cfg_env::BAIBOT_LOGGING => {
config.logging = value;
}

View File

@@ -8,6 +8,12 @@ pub async fn handle(
room: &mxlink::matrix_sdk::Room,
room_config_context: &RoomConfigContext,
) -> anyhow::Result<()> {
if !bot.post_join_self_introduction_enabled() {
tracing::debug!("Post-join self-introduction is disabled - not sending introduction message");
return Ok(());
}
let agent_manager = bot.agent_manager();
bot.messaging()

View File

@@ -19,6 +19,9 @@ pub struct Config {
#[serde(default = "super::defaults::command_prefix")]
pub command_prefix: String,
#[serde(default)]
pub room: ConfigRoom,
pub access: ConfigAccess,
pub agents: ConfigAgents,
@@ -37,6 +40,7 @@ impl Config {
self.homeserver.validate()?;
self.user.validate()?;
self.persistence.validate()?;
self.room.validate()?;
self.access.validate()?;
if self.command_prefix.is_empty() {
@@ -243,6 +247,27 @@ impl PersistenceConfig {
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigRoom {
#[serde(default = "super::defaults::room_post_join_self_introduction_enabled")]
pub post_join_self_introduction_enabled: bool,
}
impl ConfigRoom {
pub fn validate(&self) -> anyhow::Result<()> {
Ok(())
}
}
impl Default for ConfigRoom {
fn default() -> Self {
Self {
post_join_self_introduction_enabled: super::defaults::room_post_join_self_introduction_enabled(),
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ConfigAccess {
// Contains the admin whitelist patterns before parsing into regex.

View File

@@ -18,6 +18,10 @@ pub(super) fn command_prefix() -> String {
COMMAND_PREFIX.to_owned()
}
pub(super) fn room_post_join_self_introduction_enabled() -> bool {
true
}
pub(super) fn persistence_data_dir_path() -> Option<String> {
None
}

View File

@@ -11,6 +11,9 @@ pub const BAIBOT_USER_ENCRYPTION_RECOVERY_PASSPHRASE: &str =
pub const BAIBOT_COMMAND_PREFIX: &str = "BAIBOT_COMMAND_PREFIX";
pub const BAIBOT_ROOM_POST_JOIN_SELF_INTRODUCTION_ENABLED: &str =
"BAIBOT_ROOM_POST_JOIN_SELF_INTRODUCTION_ENABLED";
pub const BAIBOT_LOGGING: &str = "BAIBOT_LOGGING";
pub const BAIBOT_ACCESS_ADMIN_PATTERNS: &str = "BAIBOT_ACCESS_ADMIN_PATTERNS";