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 @@
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.
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").
When choosing "content", you can type in the text you want to send as the body of the webhook.
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.
When choosing "icon", you can type in a URL to the image you want to set as the profile picture of the webhook.
+When choosing "embed", you can insert embed data reporters and/or embed connector reporters to send an embed to your webhook.
+When choosing "json", you can type in your own data to send to your webhook. When using "json", the format should be:
+ + +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.
+The "author" option has three sub options:
+When choosing "name", you can type in the text you want to send as the name of the author in the embed.
+When choosing "url", you can type in the URL you want to send as the link of the author in the embed.
+When choosing "icon url", you can type in the URL you want to send as the icon of the author in the embed.
+When choosing "title", you can type in the text you want to send as the title of the embed.
+When choosing "url", you can type in the URL you want to send as the link of the title of the embed.
+When choosing "description", you can type in the text you want to send as the description of the embed.
+The "fields" option has three sub options:
+When choosing "name", you can type in the text you want to send as the name of the field in the embed.
+When choosing "value", you can type in the text you want to send as the value of the field in the embed.
+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.
+When choosing "thumbnail", you can type in the URL you want to send as the thumbnail of the embed.
+When choosing "image", you can type in the URL you want to send as the image next to the title of the embed.
+The "footer" option has two sub options:
+When choosing "text", you can type in the text you want to send as the footer of the embed.
+When choosing "icon url", you can type in the URL you want to send as the icon of the footer in the embed.
+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:
+ +When choosing "color", you can type in the hex code you want to send as the color of the embed.
+ +This reporter connects two same embed data reporters (that have sub options) together.
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.