Skip to content

Commit 5356180

Browse files
committed
fix: not_long_enough
1 parent 095154d commit 5356180

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/i18n/en.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ commands:
2929
title: "❌ Join Date Not Found"
3030
description: "Failed to fetch join date"
3131
footer: "This is likely a Discord API error"
32+
not_long_enough:
33+
title: "❌ Not Long Enough"
34+
description: "You must be in the server for at least {days} days"
35+
footer: "Try again in {remaining} days"
3236
success:
3337
title: "🎫 New Invite Created"
3438
description: "Here's your invite link for **{guild}**"

src/i18n/zh-TW.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ commands:
5050
title: "❌ 找不到用戶加入日期"
5151
description: "無法取得用戶加入日期"
5252
footer: "這可能是 Discord API 錯誤"
53+
not_long_enough:
54+
title: "❌ 加入時間不足"
55+
description: "您必須在伺服器中至少待 {days} 天"
56+
footer: "請等待至少 {remaining} 天後再試"
5357
success:
5458
title: "👥 邀請資訊"
5559
user: "用戶"

src/slash_commands/invites.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ pub async fn invites(ctx: Context<'_>) -> Result<(), Error> {
5252
);
5353

5454
if let Some(join_date) = member.joined_at {
55-
if Utc::now() - join_date.to_utc() < min_stay_duration {
56-
send_error_embed(ctx, locale, "commands.invites.errors.not_long_enough").await?;
55+
let join_date_utc = join_date.naive_utc().and_utc();
56+
let joined_time = Utc::now() - join_date_utc;
57+
if joined_time < min_stay_duration {
58+
let params =
59+
create_not_long_enough_params(min_stay_duration.num_days(), joined_time.num_days());
60+
send_not_long_enough_embed(ctx, locale, params).await?;
5761
return Ok(());
5862
}
5963
} else {
@@ -173,6 +177,30 @@ async fn send_limit_reached_embed(
173177
Ok(())
174178
}
175179

180+
async fn send_not_long_enough_embed(
181+
ctx: Context<'_>,
182+
locale: &str,
183+
params: HashMap<&str, String>,
184+
) -> Result<(), Error> {
185+
let embed = CreateEmbed::default()
186+
.title(t!(locale, "commands.invites.errors.not_long_enough.title"))
187+
.description(t!(
188+
locale,
189+
"commands.invites.errors.not_long_enough.description",
190+
params.clone()
191+
))
192+
.color(0xFF3333)
193+
.footer(CreateEmbedFooter::new(t!(
194+
locale,
195+
"commands.invites.errors.not_long_enough.footer",
196+
params.clone()
197+
)));
198+
199+
ctx.send(CreateReply::default().embed(embed).ephemeral(true))
200+
.await?;
201+
Ok(())
202+
}
203+
176204
async fn send_success_embed(
177205
ctx: Context<'_>,
178206
locale: &str,
@@ -224,6 +252,13 @@ fn create_limit_params(role_with_limit: &AllowedRole, used_invites: i64) -> Hash
224252
params
225253
}
226254

255+
fn create_not_long_enough_params<'a>(days: i64, remaining: i64) -> HashMap<&'a str, String> {
256+
let mut params = HashMap::new();
257+
params.insert("days", days.to_string());
258+
params.insert("remaining", remaining.to_string());
259+
params
260+
}
261+
227262
fn create_success_params<'a>(
228263
role_with_limit: &'a AllowedRole,
229264
used_invites: i64,

0 commit comments

Comments
 (0)