Skip to content

Add support for #RRGGBB hex colour values for embed#203

Open
Wolfdv1 wants to merge 1 commit intoErdbeerbaerLP:masterfrom
Wolfdv1:patch-1
Open

Add support for #RRGGBB hex colour values for embed#203
Wolfdv1 wants to merge 1 commit intoErdbeerbaerLP:masterfrom
Wolfdv1:patch-1

Conversation

@Wolfdv1
Copy link

@Wolfdv1 Wolfdv1 commented Jan 22, 2025

The embed creator I initially used gave hex rather than the decimal representation, this function checks against a quick regex to see if #RRGGBB hex value has been used and if so converts it to decimal and returns the string as normal.

Example:

jsonColorHexToDec("{\r\n  \"author\": {\r\n    \"name\": \"%name%\",\r\n    \"icon_url\": \"https://crafthead.net/avatar/%uuid%\"\r\n  },\r\n  \"description\": \"%msg%\",\r\n  \"color\": \"#4F545C\"\r\n}")

gives:

{\r\n  \"author\": {\r\n    \"name\": \"%name%\",\r\n    \"icon_url\": \"https://crafthead.net/avatar/%uuid%\"\r\n  },\r\n  \"description\": \"%msg%\",\r\n  \"color\": \"5198940\"\r\n}

And if decimal is given originally, no changes are made.
Currently if a Hex value #RRGGBB is given the following crash error is given:

java.lang.NumberFormatException: For input string: "#4F545C"
        at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:?]
        at java.base/java.lang.Integer.parseInt(Unknown Source) ~[?:?]
        at java.base/java.lang.Integer.parseInt(Unknown Source) ~[?:?]
        at knot/net.dv8tion.jda.api.utils.data.DataObject.get(DataObject.java:913) ~[de_erdbeerbaerlp_dcintegration_common-3.1.0-55dc154341f71a65.jar:?]
        at knot/net.dv8tion.jda.api.utils.data.DataObject.getInt(DataObject.java:575) ~[de_erdbeerbaerlp_dcintegration_common-3.1.0-55dc154341f71a65.jar:?]
        at knot/net.dv8tion.jda.api.EmbedBuilder.fromData(EmbedBuilder.java:115) ~[de_erdbeerbaerlp_dcintegration_common-3.1.0-55dc154341f71a65.jar:?]
        at knot/de.erdbeerbaerlp.dcintegration.common.storage.Configuration$EmbedMode$EmbedEntry.toEmbedJson(Configuration.java:238) ~[de_erdbeerbaerlp_dcintegration_common-3.1.0-55dc154341f71a65.jar:?]

The above function would prevent this, and also may be altered for formats of 0xRRGGBB along with #RRGGBB as needed.

ps, the function itself is tested standalone- but has not been integration tested

The [embed creator](https://embed.dan.onl/) I initially used gave hex rather than the decimal representation, this function checks against a quick regex to see if #RRGGBB hex value has been used and if so converts it to decimal and returns the string as normal.  

Example:
```jsonColorHexToDec("{\r\n  \"author\": {\r\n    \"name\": \"%name%\",\r\n    \"icon_url\": \"https://crafthead.net/avatar/%uuid%\"\r\n  },\r\n  \"description\": \"%msg%\",\r\n  \"color\": \"#4F545C\"\r\n}")  
gives: ```{\r\n  \"author\": {\r\n    \"name\": \"%name%\",\r\n    \"icon_url\": \"https://crafthead.net/avatar/%uuid%\"\r\n  },\r\n  \"description\": \"%msg%\",\r\n  \"color\": \"5198940\"\r\n}  

And if decimal is given originally, no changes are made  

##### ps, the function itself is tested standalone- has not been integration tested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant