diff --git a/extensions/CubesterYT/TurboHook.js b/extensions/CubesterYT/TurboHook.js index 864b3c474c..83b033bc4c 100644 --- a/extensions/CubesterYT/TurboHook.js +++ b/extensions/CubesterYT/TurboHook.js @@ -1,3 +1,8 @@ +/*! + * TurboHook (V.1.1.0) + * Made by CubesterYT + */ + (function (Scratch) { "use strict"; @@ -48,6 +53,30 @@ } } }, + { + opcode: "embedParams", + blockType: Scratch.BlockType.REPORTER, + text: "[MENU1] [MENU2] [DATA]", + arguments: { + MENU1: { + type: Scratch.ArgumentType.STRING, + menu: "EMBEDPARAMS" + }, + MENU2: { + type: Scratch.ArgumentType.STRING, + menu: "EMBEDSUBPARAMS", + defaultValue: "name" + }, + DATA: { + type: Scratch.ArgumentType.STRING + } + } + }, + { + opcode: "embedConnector", + blockType: Scratch.BlockType.REPORTER, + text: "sub options: [STRING1] & [STRING2]" + }, { opcode: "connector", blockType: Scratch.BlockType.REPORTER, @@ -57,18 +86,31 @@ menus: { PARAMS: { acceptReporters: true, - items: ["content", "name", "icon"] + items: ["content", "name", "icon", "embed", "json"] + }, + EMBEDPARAMS: { + acceptReporters: true, + items: ["author", "title", "url", "description", "fields", "thumbnail", "image", "footer", "timestamp", "color"] + }, + EMBEDSUBPARAMS: { + acceptReporters: true, + items: ["empty", "name", "url", "icon url", "text", "value", "inline"] } } }; } webhook ({hookDATA, hookURL}) { - const data = parseOrEmptyObject(hookDATA); - if (!data.content) { - // Typically this can't be empty, so put something there if they forgot to + hookDATA = Scratch.Cast.toString(hookDATA); + hookURL = Scratch.Cast.toString(hookURL); + let data = parseOrEmptyObject(hookDATA); + if (data.embeds) { + } else if (hookDATA.includes("json ")) { + const jsonFix = hookDATA.replace("json ", ""); + data = JSON.parse(jsonFix); + } else if (!data.content) { data.content = "(empty)"; - } + }; Scratch.fetch(hookURL, { method: "POST", headers: { @@ -85,9 +127,98 @@ return JSON.stringify({ username: DATA }); } else if (MENU == "icon") { return JSON.stringify({ avatar_url: DATA }); + } else if (MENU == "embed") { + const embedDATA = JSON.stringify({ embeds: ["!"] }); + return embedDATA.replace('"!"', DATA); + } else if (MENU == "json") { + return `json ${DATA}`; } return "{}"; } + embedParams ({MENU1, MENU2, DATA}) { + DATA = Scratch.Cast.toString(DATA); + if (MENU1 == "author") { + if (MENU2 == "name") { + return JSON.stringify({ author: { name: DATA } }); + } else if (MENU2 == "url") { + return JSON.stringify({ author: { url: DATA } }); + } else if (MENU2 == "icon url") { + return JSON.stringify({ author: { icon_url: DATA } }); + } + } else if (MENU1 == "title" && MENU2 == "empty") { + return JSON.stringify({ title: DATA }); + } else if (MENU1 == "url" && MENU2 == "empty") { + return JSON.stringify({ url: DATA }); + } else if (MENU1 == "description" && MENU2 == "empty") { + return JSON.stringify({ description: DATA }); + } else if (MENU1 == "fields") { + if (MENU2 == "name") { + return JSON.stringify({ fields: [ { name: DATA } ] }); + } else if (MENU2 == "value") { + return JSON.stringify({ fields: [ { value: DATA } ] }); + } else if (MENU2 == "inline") { + return JSON.stringify({ fields: [ { inline: DATA } ] }); + } + } else if (MENU1 == "thumbnail") { + if (MENU2 == "url") { + return JSON.stringify({ thumbnail: { url: DATA } }); + } + } else if (MENU1 == "image") { + if (MENU2 == "url") { + return JSON.stringify({ image: { url: DATA } }); + } + } else if (MENU1 == "footer") { + if (MENU2 == "text") { + return JSON.stringify({ footer: { text: DATA } }); + } else if (MENU2 == "icon url") { + return JSON.stringify({ footer: { icon_url: DATA } }); + } + } else if (MENU1 == "timestamp" && MENU2 == "empty") { + return JSON.stringify({ timestamp: DATA }); + } else if (MENU1 == "color" && MENU2 == "empty") { + function hexToDecimal(hex) { + return parseInt(hex.replace("#",""), 16); + } + const color = JSON.stringify(hexToDecimal(DATA)); + return JSON.stringify({ color: color }); + } else { + return "{}"; + } + } + embedConnector ({STRING1, STRING2}) { + STRING1 = Scratch.Cast.toString(STRING1); + STRING2 = Scratch.Cast.toString(STRING2); + if (STRING1.includes("author") && STRING2.includes("author")) { + STRING1 = STRING1.replace('{"author":', ""); + STRING1 = STRING1.slice(0,-1); + STRING2 = STRING2.replace('{"author":', ""); + STRING2 = STRING2.slice(0,-1); + return `{"author":${JSON.stringify({ + ...parseOrEmptyObject(STRING1), + ...parseOrEmptyObject(STRING2) + })}}`; + } else if (STRING1.includes("fields") && STRING2.includes("fields")) { + STRING1 = STRING1.replace('{"fields":[', ""); + STRING1 = STRING1.slice(0,-2); + STRING2 = STRING2.replace('{"fields":[', ""); + STRING2 = STRING2.slice(0,-2); + return `{"fields":[${JSON.stringify({ + ...parseOrEmptyObject(STRING1), + ...parseOrEmptyObject(STRING2) + })}]}`; + } else if (STRING1.includes("footer") && STRING2.includes("footer")) { + STRING1 = STRING1.replace('{"footer":', ""); + STRING1 = STRING1.slice(0,-1); + STRING2 = STRING2.replace('{"footer":', ""); + STRING2 = STRING2.slice(0,-1); + return `{"footer":${JSON.stringify({ + ...parseOrEmptyObject(STRING1), + ...parseOrEmptyObject(STRING2) + })}}`; + } else { + return "{}" + } + } connector ({STRING1, STRING2}) { return JSON.stringify({ ...parseOrEmptyObject(STRING1), diff --git a/website/CubesterYT/TurboHook.html b/website/CubesterYT/TurboHook.html index 1222e12df7..b8a71bf285 100644 --- a/website/CubesterYT/TurboHook.html +++ b/website/CubesterYT/TurboHook.html @@ -71,7 +71,7 @@

About this extension

-

This extension allows you to post to webhooks from some common third-party websites or programs.

+

This extension allows you to post to webhooks from some common third-party websites or programs. It can also post to webhooks for any other site and program using JSON.


@@ -84,22 +84,98 @@

Webhook Block


Data Reporter

-

The Menu area of the Data Reporter currently has three options, ("content","name","icon").

+

The menu area of the Data Reporter has five options, ("content", "name", "icon", "embed", "json").

Content

When choosing "content", you can type in the text you want to send as the body of the webhook.

Name

-

When choosing "name", you can type in the name of the name you want the webhook to display as on the third-party website.

+

When choosing "name", you can type in the name of the webhook you want to display as on the third-party website.

Icon

When choosing "icon", you can type in a URL to the image you want to set as the profile picture of the webhook.

+

Embed

+ +

When choosing "embed", you can insert embed data reporters and/or embed connector reporters to send an embed to your webhook.

+

JSON

+ +

When choosing "json", you can type in your own data to send to your webhook. When using "json", the format should be:

+ + +
+ +

Embed Data Reporter

+

The first menu area of the Embed Data Reporter has ten options, ("author", "title", "url", "description", "fields", "thumbnail", "image", "footer", "timestamp", "color").

+

The second menu area of the Embed Data Reporter has seven options, ("empty", "name", "url", "icon url", "text", "value", "inline").

+

Note: Embed Data Reporters use a system to make the second menu area dependent on the first menu as a failsafe. Such as those listed below with "empty" as a second option, then it should be set to empty.

+

Author

+

The "author" option has three sub options:

+
Name
+ +

When choosing "name", you can type in the text you want to send as the name of the author in the embed.

+
URL
+ +

When choosing "url", you can type in the URL you want to send as the link of the author in the embed.

+
Icon URL
+ +

When choosing "icon url", you can type in the URL you want to send as the icon of the author in the embed.

+

Title

+ +

When choosing "title", you can type in the text you want to send as the title of the embed.

+

URL

+ +

When choosing "url", you can type in the URL you want to send as the link of the title of the embed.

+

Description

+ +

When choosing "description", you can type in the text you want to send as the description of the embed.

+

Fields

+

The "fields" option has three sub options:

+
Name
+ +

When choosing "name", you can type in the text you want to send as the name of the field in the embed.

+
Value
+ +

When choosing "value", you can type in the text you want to send as the value of the field in the embed.

+
Inline
+ +

When choosing "inline", you can type in either "true" or "false". "false" is the default, but if "true", then sets field objects in same line, but if you have more than 3 objects with enabled inline or just too long you will get rows with 3 fields in each one or with 2 fields if you used thumbnail objects.

+

Thumbnail

+ +

When choosing "thumbnail", you can type in the URL you want to send as the thumbnail of the embed.

+

Image

+ +

When choosing "image", you can type in the URL you want to send as the image next to the title of the embed.

+

Footer

+

The "footer" option has two sub options:

+
Text
+ +

When choosing "text", you can type in the text you want to send as the footer of the embed.

+
Icon URL
+ +

When choosing "icon url", you can type in the URL you want to send as the icon of the footer in the embed.

+

Timestamp

+ +

When choosing "timestamp", you can type in the ISO-8601 format of the date you want to send as the date of the embed in the footer area. The format is:

+ +

Color

+ +

When choosing "color", you can type in the hex code you want to send as the color of the embed.

+ +
+ +

Embed Data Connector Reporter

+ +

This reporter connects two same embed data reporters (that have sub options) together.


Connector Reporter

-

This reporter connects two different data reporters together and/or another connector reporter so you can send multiple pieces of data to the webhook.

+

This reporter connects two different data reporters together and/or another connector reporter and/or embed data reporters and/or embed data connector reporters so you can send multiple pieces of data to the webhook.

- + \ No newline at end of file diff --git a/website/CubesterYT/author_iconurl.png b/website/CubesterYT/author_iconurl.png new file mode 100644 index 0000000000..1fd673c78f Binary files /dev/null and b/website/CubesterYT/author_iconurl.png differ diff --git a/website/CubesterYT/author_name.png b/website/CubesterYT/author_name.png new file mode 100644 index 0000000000..e084a1b185 Binary files /dev/null and b/website/CubesterYT/author_name.png differ diff --git a/website/CubesterYT/author_url.png b/website/CubesterYT/author_url.png new file mode 100644 index 0000000000..45d7040157 Binary files /dev/null and b/website/CubesterYT/author_url.png differ diff --git a/website/CubesterYT/color_empty.png b/website/CubesterYT/color_empty.png new file mode 100644 index 0000000000..bf6dc39649 Binary files /dev/null and b/website/CubesterYT/color_empty.png differ diff --git a/website/CubesterYT/description_empty.png b/website/CubesterYT/description_empty.png new file mode 100644 index 0000000000..700a410a02 Binary files /dev/null and b/website/CubesterYT/description_empty.png differ diff --git a/website/CubesterYT/embed.png b/website/CubesterYT/embed.png new file mode 100644 index 0000000000..08a4d1ceb9 Binary files /dev/null and b/website/CubesterYT/embed.png differ diff --git a/website/CubesterYT/fields_inline.png b/website/CubesterYT/fields_inline.png new file mode 100644 index 0000000000..c5962d1d21 Binary files /dev/null and b/website/CubesterYT/fields_inline.png differ diff --git a/website/CubesterYT/fields_name.png b/website/CubesterYT/fields_name.png new file mode 100644 index 0000000000..7d989429b8 Binary files /dev/null and b/website/CubesterYT/fields_name.png differ diff --git a/website/CubesterYT/fields_value.png b/website/CubesterYT/fields_value.png new file mode 100644 index 0000000000..f9a90147be Binary files /dev/null and b/website/CubesterYT/fields_value.png differ diff --git a/website/CubesterYT/footer_iconurl.png b/website/CubesterYT/footer_iconurl.png new file mode 100644 index 0000000000..cda0347186 Binary files /dev/null and b/website/CubesterYT/footer_iconurl.png differ diff --git a/website/CubesterYT/footer_text.png b/website/CubesterYT/footer_text.png new file mode 100644 index 0000000000..fab6945c35 Binary files /dev/null and b/website/CubesterYT/footer_text.png differ diff --git a/website/CubesterYT/image_url.png b/website/CubesterYT/image_url.png new file mode 100644 index 0000000000..03362858f0 Binary files /dev/null and b/website/CubesterYT/image_url.png differ diff --git a/website/CubesterYT/json.png b/website/CubesterYT/json.png new file mode 100644 index 0000000000..275c26c840 Binary files /dev/null and b/website/CubesterYT/json.png differ diff --git a/website/CubesterYT/sub_options.png b/website/CubesterYT/sub_options.png new file mode 100644 index 0000000000..f2669a4f1f Binary files /dev/null and b/website/CubesterYT/sub_options.png differ diff --git a/website/CubesterYT/thumbnail_url.png b/website/CubesterYT/thumbnail_url.png new file mode 100644 index 0000000000..34df8bc5af Binary files /dev/null and b/website/CubesterYT/thumbnail_url.png differ diff --git a/website/CubesterYT/timestamp_empty.png b/website/CubesterYT/timestamp_empty.png new file mode 100644 index 0000000000..a5c7be12a9 Binary files /dev/null and b/website/CubesterYT/timestamp_empty.png differ diff --git a/website/CubesterYT/title_empty.png b/website/CubesterYT/title_empty.png new file mode 100644 index 0000000000..9e67cb1677 Binary files /dev/null and b/website/CubesterYT/title_empty.png differ diff --git a/website/CubesterYT/url_empty.png b/website/CubesterYT/url_empty.png new file mode 100644 index 0000000000..bf76b1c3dd Binary files /dev/null and b/website/CubesterYT/url_empty.png differ