Skip to content

Commit

Permalink
Add support for gif stickers (#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Jan 10, 2023
1 parent 993c877 commit e20f53a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Expand Up @@ -4582,7 +4582,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
* @param description
* The sticker description (2-100 characters, or empty)
* @param file
* The sticker file containing the asset (png/apng/lottie) with valid file extension (png or json)
* The sticker file containing the asset (png/apng/gif/lottie) with valid file extension (png, gif, or json)
* @param tags
* The tags to use for auto-suggestions (Up to 200 characters in total)
*
Expand All @@ -4592,7 +4592,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
* <ul>
* <li>If the name is not between 2 and 30 characters long</li>
* <li>If the description is more than 100 characters long or exactly 1 character long</li>
* <li>If the asset file is null or of an invalid format (must be PNG or LOTTIE)</li>
* <li>If the asset file is null or of an invalid format (must be PNG, GIF, or LOTTIE)</li>
* <li>If anything is {@code null}</li>
* </ul>
*
Expand All @@ -4618,7 +4618,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
* @param description
* The sticker description (2-100 characters, or empty)
* @param file
* The sticker file containing the asset (png/apng/lottie) with valid file extension (png or json)
* The sticker file containing the asset (png/apng/gif/lottie) with valid file extension (png, gif, or json)
* @param tag
* The sticker tag used for suggestions (emoji or tag words)
* @param tags
Expand All @@ -4630,7 +4630,7 @@ default RoleAction createCopyOfRole(@Nonnull Role role)
* <ul>
* <li>If the name is not between 2 and 30 characters long</li>
* <li>If the description is more than 100 characters long or exactly 1 character long</li>
* <li>If the asset file is null or of an invalid format (must be PNG or LOTTIE)</li>
* <li>If the asset file is null or of an invalid format (must be PNG, GIF, or LOTTIE)</li>
* <li>If anything is {@code null}</li>
* </ul>
*
Expand Down
Expand Up @@ -145,6 +145,10 @@ enum StickerFormat
* @see <a href="https://airbnb.io/lottie/">Lottie website</a>
*/
LOTTIE(3, "json"),
/**
* The GIF format.
*/
GIF(4, "gif"),
/**
* Represents any unknown or unsupported format types.
*/
Expand Down
Expand Up @@ -1785,7 +1785,7 @@ public AuditableRestAction<GuildSticker> createSticker(@Nonnull String name, @No

// Extract file extension and map to media type
int index = file.getName().lastIndexOf('.');
Checks.check(index > -1, "Filename for sticker is missing file extension. Provided: '" + file.getName() + "'. Must be PNG or JSON.");
Checks.check(index > -1, "Filename for sticker is missing file extension. Provided: '" + file.getName() + "'. Must be PNG, GIF, or JSON.");

// Convert file extension to media-type
String extension = file.getName().substring(index + 1).toLowerCase(Locale.ROOT);
Expand All @@ -1796,11 +1796,14 @@ public AuditableRestAction<GuildSticker> createSticker(@Nonnull String name, @No
case "png":
mediaType = Requester.MEDIA_TYPE_PNG;
break;
case "gif":
mediaType = Requester.MEDIA_TYPE_GIF;
break;
case "json":
mediaType = Requester.MEDIA_TYPE_JSON;
break;
default:
throw new IllegalArgumentException("Unsupported file extension: '." + extension + "', must be PNG or JSON.");
throw new IllegalArgumentException("Unsupported file extension: '." + extension + "', must be PNG, GIF, or JSON.");
}

// Add sticker metadata as form parts (because payload_json is broken)
Expand Down
Expand Up @@ -55,6 +55,7 @@ public class Requester
public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
public static final MediaType MEDIA_TYPE_OCTET = MediaType.parse("application/octet-stream; charset=utf-8");
public static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
public static final MediaType MEDIA_TYPE_GIF = MediaType.parse("image/gif");

protected final JDAImpl api;
protected final AuthorizationConfig authConfig;
Expand Down

0 comments on commit e20f53a

Please sign in to comment.