prevent unexpected item ID handle as used the {ID} exec context

This commit is contained in:
yggverse 2026-04-07 16:36:15 +03:00
parent dab3454972
commit 4e2f3d5de4

View file

@ -8,6 +8,7 @@ use clap::Parser;
use config::Config; use config::Config;
use database::Database; use database::Database;
use log::*; use log::*;
use regex::Regex;
use rustypipe::client::RustyPipe; use rustypipe::client::RustyPipe;
use std::{env::var, process::Command, thread, time::Duration}; use std::{env::var, process::Command, thread, time::Duration};
@ -34,6 +35,7 @@ async fn main() {
let sleep = config.sleep.map(Duration::from_secs); let sleep = config.sleep.map(Duration::from_secs);
let mut database = Database::new(&config.database).unwrap(); let mut database = Database::new(&config.database).unwrap();
let rp = RustyPipe::new(); let rp = RustyPipe::new();
let channel_item_id_regex = Regex::new(r"^[A-z0-9_-]{11}$").unwrap();
loop { loop {
if let Some(ref before) = config.before { if let Some(ref before) = config.before {
@ -52,6 +54,12 @@ async fn main() {
channel.items_limit channel.items_limit
); );
for (i, item) in items.into_iter().enumerate() { for (i, item) in items.into_iter().enumerate() {
if !channel_item_id_regex.is_match(&item.id) {
panic!(
"received unexpected item ID `{}`; unsafe to continue in the exec context",
&item.id
)
}
if channel.items_limit.is_some_and(|l| i >= l) { if channel.items_limit.is_some_and(|l| i >= l) {
debug!("items limit for channel `{c}` reached at {i}; break."); debug!("items limit for channel `{c}` reached at {i}; break.");
break; break;