Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build config-rs for configuration management #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
updated configuration management
Harshith-2208 committed Mar 11, 2025
commit 35e035dfbe94322352cad48a780ac84c8ce66cf1
68 changes: 7 additions & 61 deletions src/tasks/status_update.rs
Original file line number Diff line number Diff line change
@@ -24,33 +24,17 @@ use serenity::all::{
use serenity::async_trait;

use super::Task;
<<<<<<< HEAD
use crate::graphql::models::{Member, StreakWithMemberId};
use crate::graphql::queries::{fetch_members, fetch_streaks, increment_streak, reset_streak};
use crate::ids::{
GROUP_FOUR_CHANNEL_ID, GROUP_ONE_CHANNEL_ID, GROUP_THREE_CHANNEL_ID, GROUP_TWO_CHANNEL_ID,
STATUS_UPDATE_CHANNEL_ID,
=======
use crate::utils::time::time_until;
use crate::{
graphql::{
models::Member,
queries::{fetch_members, increment_streak, reset_streak},
},
>>>>>>> 948e8e3 (It now uses config-rs for configuration management instead of hard coded values)
};
use crate::utils::time::time_until;

<<<<<<< HEAD
/// Checks for status updates daily at 5 AM.
=======
const TITLE_URL: &str = &CONFIG.status_update.title_url;
const IMAGE_URL: &str = &CONFIG.status_update.image_url;
const AUTHOR_URL: &str = &CONFIG.status_update.author_url;
const ICON_URL: &str = &CONFIG.status_update.icon_url;

/// Checks for status updates daily at 9 AM.
>>>>>>> 948e8e3 (It now uses config-rs for configuration management instead of hard coded values)
pub struct StatusUpdateCheck;

#[async_trait]
@@ -96,7 +80,6 @@ async fn status_update_check(ctx: Context) -> anyhow::Result<()> {
Ok(())
}

<<<<<<< HEAD
async fn get_updates(ctx: &Context) -> anyhow::Result<Vec<Message>> {
let channel_ids = get_channel_ids();
let mut updates = Vec::new();
@@ -111,20 +94,6 @@ async fn get_updates(ctx: &Context) -> anyhow::Result<Vec<Message>> {
Ok(updates)
}

// TODO: Replace hardcoded set with configurable list
fn get_channel_ids() -> Vec<ChannelId> {
vec![
ChannelId::new(GROUP_ONE_CHANNEL_ID),
ChannelId::new(GROUP_TWO_CHANNEL_ID),
ChannelId::new(GROUP_THREE_CHANNEL_ID),
ChannelId::new(GROUP_FOUR_CHANNEL_ID),
]
}

fn is_valid_status_update(msg: &Message) -> bool {
let report_config = get_report_config();
let content = msg.content.to_lowercase();
=======
// TOOD: Get IDs through ENV instead
fn get_channel_ids() -> anyhow::Result<Vec<ChannelId>> {
Ok(vec![
@@ -135,25 +104,9 @@ fn get_channel_ids() -> anyhow::Result<Vec<ChannelId>> {
])
}


async fn send_and_save_limiting_messages(
channel_ids: &Vec<ChannelId>,
ctx: &Context,
) -> anyhow::Result<()> {
trace!("Running send_and_save_limiting_messages()");
let mut msg_ids: Vec<MessageId> = vec![];
for channel_id in channel_ids {
debug!("Sending message in {}", channel_id);
let msg = channel_id
.say(
&ctx.http,
"Collecting messages for status update report. Please do not delete this message.",
)
.await
.with_context(|| {
anyhow::anyhow!("Failed to send limiting message in channel {}", channel_id)
})?;
>>>>>>> 948e8e3 (It now uses config-rs for configuration management instead of hard coded values)
fn is_valid_status_update(msg: &Message) -> bool {
let report_config = get_report_config();
let content = msg.content.to_lowercase();

let is_within_timeframe = DateTime::<Utc>::from_timestamp(msg.timestamp.timestamp(), 0)
.expect("Valid timestamp")
@@ -263,12 +216,6 @@ async fn generate_embed(
description.push_str(&format_defaulters(&naughty_list));
}

<<<<<<< HEAD
let embed = CreateEmbed::new()
.title("Status Update Report")
.description(description)
.color(serenity::all::Colour::new(0xeab308));
=======
let description = build_description(
highest_streak,
all_time_high,
@@ -283,20 +230,19 @@ async fn generate_embed(

let mut embed = CreateEmbed::default()
.title(format!("Status Update Report - {}", today))
.url(&CONFIG.status_update.title_url)
.url(TITLE_URL)
.description(description)
.color(serenity::all::Colour::new(0xeab308))
.timestamp(Timestamp::now())
.author(
CreateEmbedAuthor::new("amD")
.url(&CONFIG.status_update.author_url)
.icon_url(&CONFIG.status_update.icon_url),
.url(AUTHOR_URL)
.icon_url(ICON_URL),
);

if naughty_list.is_empty() {
embed = embed.image(&CONFIG.status_update.image_url);
embed = embed.image(IMAGE_URL);
}
>>>>>>> 948e8e3 (It now uses config-rs for configuration management instead of hard coded values)

Ok(embed)
}