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
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- '.github/workflows/**'
code:
- 'src/**'
- 'scripts/**'
- 'Cargo.lock'
- 'Cargo.toml'
- 'Cross.toml'
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ jobs:
- name: 🔨 - Build
run: >
cross build --release --target ${{ matrix.target }} && \
mv target/**/release/alertaemcena alertaemcena-${{ matrix.build }}
mv target/**/release/alertaemcena alertaemcena-${{ matrix.build }} && \
mv target/**/release/backfill_reviews backfill_reviews-${{ matrix.build }}

- name: 📦 - Copy artifact
uses: actions/upload-artifact@v4
Expand All @@ -64,6 +65,13 @@ jobs:
path: alertaemcena-${{ matrix.build }}
if-no-files-found: error

- name: 📦 - Copy backfill_reviews artifact
uses: actions/upload-artifact@v4
with:
name: backfill_reviews-${{ matrix.build }}
path: backfill_reviews-${{ matrix.build }}
if-no-files-found: error

release:
needs: [build-code]
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ test-locally.sh
run-locally.sh
.idea
vote_backups
scripts/reviews_data.json
docs/superpowers
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name = "alertaemcena"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "backfill_reviews"
path = "scripts/backfill_reviews.rs"

[dependencies]
# Rust++
voca_rs = "1.15.2"
Expand Down
71 changes: 71 additions & 0 deletions scripts/backfill_reviews.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use alertaemcena::config::env_loader::load_config;
use alertaemcena::discord::api::DiscordAPI;
use alertaemcena::tracing::setup_tracing;
use serde::Deserialize;
use serenity::all::UserId;
use std::fs;
use tracing::{error, info, info_span, warn, Instrument};

#[derive(Deserialize)]
struct ReviewRecord {
url: String,
rating: u8,
comment: String,
}

#[tokio::main]
async fn main() {
let tracing_handles = setup_tracing().await;

let user_id: UserId = std::env::var("BACKFILL_USER_ID")
.expect("BACKFILL_USER_ID not set")
.parse()
.expect("BACKFILL_USER_ID must be a valid Discord user ID");

let input_path = std::env::args()
.nth(1)
.unwrap_or_else(|| "scripts/reviews_data.json".to_string());

let raw = fs::read_to_string(&input_path)
.unwrap_or_else(|e| panic!("Failed to read '{}': {}", input_path, e));
let records: Vec<ReviewRecord> =
serde_json::from_str(&raw).expect("Failed to parse input JSON");

let config = load_config();
let discord = DiscordAPI::default().await;
let channel_ids = [config.teatro_channel_id, config.artes_channel_id];
let total = records.len();

async {
for record in records {
if !(1..=5).contains(&record.rating) {
warn!(
"Skipping '{}': invalid rating {}",
record.url, record.rating
);
continue;
}

let comment = record.comment.trim();
let comment = if comment.is_empty() {
None
} else {
Some(comment)
};
let vote_emoji = &config.voting_emojis[(record.rating - 1) as usize];

match discord
.send_backfill_review(user_id, &record.url, vote_emoji, comment, &channel_ids)
.await
{
Ok(true) => info!("Sent review for {}", record.url),
Ok(false) => warn!("Skipped (already sent or event not found): {}", record.url),
Err(_) => error!("Failed to send review for {}", record.url),
}
}
}
.instrument(info_span!("backfill_reviews", user_id = %user_id, total))
.await;

tracing_handles.shutdown().await;
}
Loading
Loading