Skip to content

Implement more strict region locking check for AmiAmi items #8

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

Merged
merged 1 commit into from
May 28, 2024
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
13 changes: 13 additions & 0 deletions src/amiami/amiami-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ class Item {
return Boolean(this.#item.stock);
}

/**
* Whether an item is unavailable in any regions.
*
* This currently only works for items requested in English.
*/
regionLocked() {
// This should work for all current known cases:
// - "This product cannot be shipped to the following area: [...]"
// - "This product cannot be shipped to the following areas: [...]"
// - "This product cannot be shipped to some areas."
return this.remarks.includes("This product cannot be shipped to");
}

/**
* @returns {number} the total discount rate.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/amiami/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AmiAmiApiPreview {
.setDescription(`
**Price**: ¥${Math.trunc(priceJpy)} / $${priceUsd.toFixed(2)} ${discountRate > 0 ? `(${discountRate}% off)` : ""}
**Status**: ${item.saleStatus} ${!item.orderable() ? "(Out of stock)" : ""}
${item.remarks ? "⚠️ This item may not be available in all regions." : ""}
${item.regionLocked() ? "⚠️ This item may not be available in all regions." : ""}
`.trim())
.setTitle(item.name)
.setImage(item.image)
Expand Down