Skip to content
Merged
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
10 changes: 3 additions & 7 deletions src/agenda_cultural/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::RetryTransientMiddleware;
use scraper::{Html, Selector};
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::ops::Add;
use std::time::Duration;
use std::{cmp::Ordering};
use tracing::{debug, info, instrument, trace, warn};
use voca_rs::strip::strip_tags;

Expand Down Expand Up @@ -127,10 +127,7 @@ impl AgendaCulturalAPI {
while min_date.cmp(&max_date) != Ordering::Greater {
events_by_date.insert(min_date, Vec::from([]));
trace!("Going for {:?}", min_date);
min_date = min_date
.add(TimeDelta::days(31))
.with_day(1)
.unwrap();
min_date = min_date.add(TimeDelta::days(31)).with_day(1).unwrap();
}
}
}
Expand Down Expand Up @@ -231,8 +228,7 @@ impl AgendaCulturalAPI {
.map_err(APIError::InvalidResponse)
.await?;

serde_json::from_str::<Vec<EventResponse>>(&json_response)
.map_err(APIError::ParseError)
serde_json::from_str::<Vec<EventResponse>>(&json_response).map_err(APIError::ParseError)
}

async fn get_full_description(link: &str) -> Option<String> {
Expand Down
2 changes: 1 addition & 1 deletion src/discord/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl DiscordAPI {
.await
{
Ok(_) => {
debug!("Successfully added '{}' reaction", emoji.name);
trace!("Successfully added '{}' reaction", emoji.name);
}
Err(err) => {
error!(
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use alertaemcena::config::model::{Config, DebugConfig, EmojiConfig};
use alertaemcena::discord::api::{DiscordAPI, EventsThread};
use alertaemcena::tracing::setup_loki;
use lazy_static::lazy_static;
use serenity::all::{ChannelId, GuildChannel};
use serenity::all::{ChannelId, GuildChannel, MessageType};
use std::collections::BTreeMap;
use std::process::exit;
use tracing::{debug, error, info, instrument, warn};
use tracing::{debug, error, info, instrument, trace, warn};

lazy_static! {
pub static ref SAVE_FOR_LATER_EMOJI: char = '🔖';
Expand Down Expand Up @@ -74,8 +74,8 @@ async fn run(config: &Config, discord: &DiscordAPI, category: Category, channel_
return;
}

let events = AgendaCulturalAPI::get_events_by_month(&category, config.debug_config.event_limit)
.await;
let events =
AgendaCulturalAPI::get_events_by_month(&category, config.debug_config.event_limit).await;

if events.is_err() {
let err = events.unwrap_err();
Expand Down Expand Up @@ -112,6 +112,11 @@ async fn handle_reaction_features(
vote_emojis: &[EmojiConfig; 5],
) {
for thread in threads {
if thread.thread_metadata.expect("Should be a thread!").locked {
trace!("Ignoring locked thread (probably out-of-date)");
continue;
}

let messages = discord
.get_all_messages(thread.id)
.await
Expand All @@ -132,6 +137,11 @@ async fn handle_reaction_features(
continue;
}

if message.kind != MessageType::Regular {
trace!("Ignoring non-regular message (id={})", message.id);
continue;
}

if message.embeds.is_empty() {
warn!(
"Found message without embed (id={}; content={})",
Expand Down
Loading