Skip to content

Commit

Permalink
fix: not_long_enough
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoOwO committed Jan 12, 2025
1 parent 095154d commit 5356180
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ commands:
title: "❌ Join Date Not Found"
description: "Failed to fetch join date"
footer: "This is likely a Discord API error"
not_long_enough:
title: "❌ Not Long Enough"
description: "You must be in the server for at least {days} days"
footer: "Try again in {remaining} days"
success:
title: "🎫 New Invite Created"
description: "Here's your invite link for **{guild}**"
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ commands:
title: "❌ 找不到用戶加入日期"
description: "無法取得用戶加入日期"
footer: "這可能是 Discord API 錯誤"
not_long_enough:
title: "❌ 加入時間不足"
description: "您必須在伺服器中至少待 {days} 天"
footer: "請等待至少 {remaining} 天後再試"
success:
title: "👥 邀請資訊"
user: "用戶"
Expand Down
39 changes: 37 additions & 2 deletions src/slash_commands/invites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ pub async fn invites(ctx: Context<'_>) -> Result<(), Error> {
);

if let Some(join_date) = member.joined_at {
if Utc::now() - join_date.to_utc() < min_stay_duration {
send_error_embed(ctx, locale, "commands.invites.errors.not_long_enough").await?;
let join_date_utc = join_date.naive_utc().and_utc();
let joined_time = Utc::now() - join_date_utc;
if joined_time < min_stay_duration {
let params =
create_not_long_enough_params(min_stay_duration.num_days(), joined_time.num_days());
send_not_long_enough_embed(ctx, locale, params).await?;
return Ok(());
}
} else {
Expand Down Expand Up @@ -173,6 +177,30 @@ async fn send_limit_reached_embed(
Ok(())
}

async fn send_not_long_enough_embed(
ctx: Context<'_>,
locale: &str,
params: HashMap<&str, String>,
) -> Result<(), Error> {
let embed = CreateEmbed::default()
.title(t!(locale, "commands.invites.errors.not_long_enough.title"))
.description(t!(
locale,
"commands.invites.errors.not_long_enough.description",
params.clone()
))
.color(0xFF3333)
.footer(CreateEmbedFooter::new(t!(
locale,
"commands.invites.errors.not_long_enough.footer",
params.clone()
)));

ctx.send(CreateReply::default().embed(embed).ephemeral(true))
.await?;
Ok(())
}

async fn send_success_embed(
ctx: Context<'_>,
locale: &str,
Expand Down Expand Up @@ -224,6 +252,13 @@ fn create_limit_params(role_with_limit: &AllowedRole, used_invites: i64) -> Hash
params
}

fn create_not_long_enough_params<'a>(days: i64, remaining: i64) -> HashMap<&'a str, String> {
let mut params = HashMap::new();
params.insert("days", days.to_string());
params.insert("remaining", remaining.to_string());
params
}

fn create_success_params<'a>(
role_with_limit: &'a AllowedRole,
used_invites: i64,
Expand Down

0 comments on commit 5356180

Please sign in to comment.