Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct DiscordConfig {
pub allowed_channels: Vec<String>,
#[serde(default)]
pub allowed_users: Vec<String>,
#[serde(default)]
pub monitored_bot_ids: Vec<String>,
}

#[derive(Debug, Deserialize)]
Expand Down
10 changes: 8 additions & 2 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ pub struct Handler {
pub allowed_channels: HashSet<u64>,
pub allowed_users: HashSet<u64>,
pub reactions_config: ReactionsConfig,
pub monitored_bot_ids: HashSet<u64>,
}

#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
if msg.author.bot {
// Check if message is from a monitored bot (allows auto-response without mention)
let is_monitored_bot = msg.author.bot && self.monitored_bot_ids.contains(&msg.author.id.get());

// Skip bot messages unless from a monitored bot
if msg.author.bot && !is_monitored_bot {
return;
}

Expand Down Expand Up @@ -63,7 +68,8 @@ impl EventHandler for Handler {
if !in_allowed_channel && !in_thread {
return;
}
if !in_thread && !is_mentioned {
// Require mention unless in thread or from a monitored bot
if !in_thread && !is_mentioned && !is_monitored_bot {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ async fn main() -> anyhow::Result<()> {

let allowed_channels = parse_id_set(&cfg.discord.allowed_channels, "allowed_channels")?;
let allowed_users = parse_id_set(&cfg.discord.allowed_users, "allowed_users")?;
info!(channels = allowed_channels.len(), users = allowed_users.len(), "parsed allowlists");
let monitored_bot_ids = parse_id_set(&cfg.discord.monitored_bot_ids, "monitored_bot_ids")?;
info!(channels = allowed_channels.len(), users = allowed_users.len(), monitored_bots = monitored_bot_ids.len(), "parsed allowlists");

let handler = discord::Handler {
pool: pool.clone(),
allowed_channels,
allowed_users,
reactions_config: cfg.reactions,
monitored_bot_ids,
};

let intents = GatewayIntents::GUILD_MESSAGES
Expand Down