Skip to content
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

Title of new preview #457

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import "./blocks/discord/message-event/";
import "./blocks/discord/join-event/";
import "./blocks/discord/leave-event/";
import "./blocks/discord/reaction-event/";
import "./blocks/discord/edited-event/";
import "./blocks/discord/thread-event";
import "./blocks/discord/direct";
import "./blocks/discord/slash";

import "./blocks/discord/channels/";
import "./blocks/discord/servers/";
Expand Down
40 changes: 40 additions & 0 deletions src/blocks/discord/channels/channel_category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_channel_category";

const blockData = {
"message0": "%{BKY_CHANNEL_CATEGORY}",
"args0": [
{
"type": "input_value",
"name": "CHANNEL",
"check": "Channel"
}
],
"colour": "#50a6c9",
"output": "Category",
"tooltip": "",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function(block){
const channel = Blockly.JavaScript.valueToCode(block, "CHANNEL", Blockly.JavaScript.ORDER_ATOMIC);
return [ `${channel}.parent`, Blockly.JavaScript.ORDER_NONE ];
};

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_VALID_CHANNEL",
types: [
"CHANNEL"
]
}
]);
2 changes: 2 additions & 0 deletions src/blocks/discord/channels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ import "./get_channel";
import "./send_channel";
import "./send_wait_reply";
import "./send_wait_reply_value";
import "./start_typing";
import "./channel_category";
42 changes: 16 additions & 26 deletions src/blocks/discord/channels/send_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ const blockData = {
{
"type": "input_value",
"name": "CONTENT",
"check": [ "MessageEmbed", "String", "Number" ]
"check": ["Number", "String"]
},
{
"type": "input_value",
"name": "EMBED",
"check": "MessageEmbed"
},
{
"type": "input_value",
"name": "CHANNEL",
"check": "Channel"
},
}
],
"colour": "#4C97FF",
"inputsInline": false,
"previousStatement": null,
"nextStatement": null,
"tooltip": "",
Expand All @@ -31,38 +37,22 @@ Blockly.Blocks[blockName] = {
};

Blockly.JavaScript[blockName] = function(block){
const channel = Blockly.JavaScript.valueToCode(block, "CHANNEL", Blockly.JavaScript.ORDER_ATOMIC);
const content = Blockly.JavaScript.valueToCode(block, "CONTENT", Blockly.JavaScript.ORDER_ATOMIC);
if(block.getInput("CONTENT").connection.targetConnection){
const contentType = block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection.check_ ?
block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection.check_[0] :
null;
if((contentType === "MessageEmbed") || (!contentType && typeof contentType === "object")){
const code = `${channel}.send(${content});\n`;
return code;
} else {
const code = `${channel}.send(String(${content}));\n`;
return code;
}
const embed = Blockly.JavaScript.valueToCode(block, "EMBED", Blockly.JavaScript.ORDER_ATOMIC) || null;
const channel = Blockly.JavaScript.valueToCode(block, "CHANNEL", Blockly.JavaScript.ORDER_ATOMIC) || "false";
if(content.length > 2){
return(`${channel}.send({embeds: ${embed}, content: ${content}});\n`)
} else {
const code = `${channel}.send(String(${content}));\n`;
return code;
return(`${channel}.send({embeds: ${embed}});\n`)
}
};
}

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_SEND_CHANNEL_CONTENT",
types: [
"CONTENT"
]
},
{
type: "notempty",
message: "RES_SEND_CHANNEL_CHANNEL",
message: "RES_MISSING_CONTENT",
types: [
"CHANNEL"
"CONTENT"
]
}
]);
46 changes: 46 additions & 0 deletions src/blocks/discord/channels/start_typing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_start_typing";

const blockData = {
"message0": "%{BKY_START_TYPING}",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_value",
"name": "CHANNEL",
"check": "Channel"
}
],
"colour": "#4C97FF",
"tooltip": "Will type in channel for 3 seconds",
"helpUrl": "",
"inputsInline": false,
"previousStatement": null,
"nextStatement": null
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function(block){
const channel = Blockly.JavaScript.valueToCode(block, "CHANNEL", Blockly.JavaScript.ORDER_ATOMIC);
return `${channel}.sendTyping();\n`;
};

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_VALID_MEMBER",
types: [
"CHANNEL"
]
}
]);
69 changes: 69 additions & 0 deletions src/blocks/discord/direct/direct_author_raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as Blockly from "blockly";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_direct_author_raw";

const blockData = {
"message0": "%{BKY_DIRECT_AUTHOR_RAW}",
"args0": [
{
"type": "field_dropdown",
"name": "SEARCH_TYPE",
"options": [
[
"%{BKY_USERNAME}",
"USERNAME"
],
[
"%{BKY_DISCRIMINATOR}",
"DISCRIMINATOR"
],
[
"id",
"ID"
],
[
"%{BKY_TAG}",
"TAG"
]
]
}
],
"output": "String",
"colour": "#5BA58C",
"tooltip": "",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function(block) {
const searchType = block.getFieldValue("SEARCH_TYPE");
if(searchType === "ID"){
const code = ["s4dmessage.author.id", Blockly.JavaScript.ORDER_NONE];
return code;
} else if(searchType === "USERNAME"){
const code = ["s4dmessage.author.username", Blockly.JavaScript.ORDER_NONE];
return code;
} else if(searchType === "DISCRIMINATOR"){
const code = ["s4dmessage.author.discriminator", Blockly.JavaScript.ORDER_NONE];
return code;
}else if(searchType === "TAG"){
const code = ["s4dmessage.author.tag", Blockly.JavaScript.ORDER_NONE];
return code
}
};

registerRestrictions(blockName, [
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_MESSAGE",
types: [
"s4d_on_direct"
]
}
]);
33 changes: 33 additions & 0 deletions src/blocks/discord/direct/direct_bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_direct_bot";

const blockData = {
"message0": "%{BKY_DIRECT_BOT}",
"colour": "#5B80A5",
"tooltip": "",
"output": "Boolean",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function() {
const code = ["s4dmessage.author.bot", Blockly.JavaScript.ORDER_NONE];
return code;
};

registerRestrictions(blockName, [
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_DIRECT",
types: [
"s4d_on_direct"
]
}
]);
33 changes: 33 additions & 0 deletions src/blocks/discord/direct/direct_content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_direct_content";

const blockData = {
"message0": "%{BKY_DIRECT_CONTENT}",
"colour": "#5BA58C",
"tooltip": "",
"output": "String",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function() {
const code = ["s4dmessage.content", Blockly.JavaScript.ORDER_NONE];
return code;
};

registerRestrictions(blockName, [
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_DIRECT",
types: [
"s4d_on_direct"
]
}
]);
33 changes: 33 additions & 0 deletions src/blocks/discord/direct/direct_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_direct_id";

const blockData = {
"message0": "%{BKY_DIRECT_ID}",
"colour": "#5BA58C",
"tooltip": "",
"output": "String",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function() {
const code = ["s4dmessage.id", Blockly.JavaScript.ORDER_NONE];
return code;
};

registerRestrictions(blockName, [
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_DIRECT",
types: [
"s4d_on_direct"
]
}
]);
49 changes: 49 additions & 0 deletions src/blocks/discord/direct/direct_react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_direct_reaction";

const blockData = {
"message0": "%{BKY_DIRECT_REACTION}",
"args0": [
{
"type": "input_value",
"name": "REACTION",
"check": "String"
}
],
"previousStatement": null,
"nextStatement": null,
"colour": "#4C97FF",
"tooltip": "",
"helpUrl": ""
};

Blockly.Blocks[blockName] = {
init: function() {
this.jsonInit(blockData);
}
};

Blockly.JavaScript[blockName] = function(block) {
const reaction = Blockly.JavaScript.valueToCode(block, "REACTION", Blockly.JavaScript.ORDER_ATOMIC);
const code = `s4dmessage.react(${reaction});`;
return code;
};

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_ADD_REACTION_MISSING_REACTION",
types: [
"REACTION"
]
},
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_MESSAGE",
types: [
"s4d_on_direct"
]
}
]);
Loading