Skip to content

Commit

Permalink
🔀 Merge branch develop for 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Apr 26, 2020
1 parent 0e04699 commit 33f6098
Show file tree
Hide file tree
Showing 46 changed files with 1,377 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
patreon: androz2091
github: Androz2091
173 changes: 173 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "blockly-vue-sample",
"name": "scratch-for-discord",
"version": "1.4.0",
"private": true,
"scripts": {
Expand All @@ -11,11 +11,12 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@blockly/field-date": "^3.20200313.0",
"@blockly/field-date": "^3.20200313.2",
"blockly": "^3.20200123.1",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.12.0",
"core-js": "^3.6.4",
"easy-json-database-browser": "^1.1.0",
"js-beautify": "^1.11.0",
"jszip": "^3.4.0",
"sweetalert2": "^9.10.12",
Expand Down
6 changes: 5 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>scratch.png">
<script src="<%= BASE_URL %>discord.min.js" type="text/javascript"></script>
<title>Scratch For Discord</title>
<title>Scratch For Discord - Make your own bot using blocks</title>
<meta name="description" content="Make your own discord bot in 5 minutes using blocks with no coding required. Try your bot online and export it on your computer or server." />
<meta name="keywords" content="discord, bot, no-coding, scratch, blocks" />
<meta name="author" content="Androz2091" />
<meta name="theme-color" content="#f6bc34" />
</head>
<body>
<noscript>
Expand Down
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ Blockly.Tooltip.HOVER_MS = 100;
// Load blocks
import "./blocks/discord/base/";
import "./blocks/discord/joins/";
import "./blocks/discord/leaves/";
import "./blocks/discord/message/";
import "./blocks/discord/channels/";
import "./blocks/discord/servers/";
import "./blocks/discord/roles/";
import "./blocks/discord/members/";
import "./blocks/discord/reactions/";
import "./blocks/database/";
import "./blocks/text/";
import "./blocks/loops/";
import "./prompt";
export default {
Expand Down
35 changes: 35 additions & 0 deletions src/blocks/database/add_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Blockly from "blockly/core";

const blockName = "s4d_add_data";

const blockData = {
"message0": "%{BKY_ADD_DATA}",
"args0": [
{
"type": "input_value",
"name": "COUNT",
"check": "Number"
},
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
}
],
"nextStatement": null,
"previousStatement": null,
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
const count = Blockly.JavaScript.valueToCode(block, "COUNT", Blockly.JavaScript.ORDER_ATOMIC);
return `s4d.database.add(String(${key}), parseInt(${count}));\n`;
};
29 changes: 29 additions & 0 deletions src/blocks/database/delete_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Blockly from "blockly/core";

const blockName = "s4d_delete_data";

const blockData = {
"message0": "%{BKY_DELETE_DATA}",
"args0": [
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
}
],
"previousStatement": null,
"nextStatement": null,
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
return `s4d.database.delete(String(${key});\n`;
};
28 changes: 28 additions & 0 deletions src/blocks/database/get_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Blockly from "blockly/core";

const blockName = "s4d_get_data";

const blockData = {
"message0": "%{BKY_GET_DATA}",
"args0": [
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
}
],
"output": null,
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
return [ 's4d.database.get(String('+key+'))', Blockly.JavaScript.ORDER_ATOMIC ];
};
28 changes: 28 additions & 0 deletions src/blocks/database/has_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Blockly from "blockly/core";

const blockName = "s4d_has_data";

const blockData = {
"message0": "%{BKY_HAS_DATA}",
"args0": [
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
}
],
"output": "Boolean",
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
return [ 's4d.database.has(String('+key+'))', Blockly.JavaScript.ORDER_ATOMIC ];
};
6 changes: 6 additions & 0 deletions src/blocks/database/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "./add_data";
import "./delete_data";
import "./get_data";
import "./has_data";
import "./set_data";
import "./subtract_data";
34 changes: 34 additions & 0 deletions src/blocks/database/set_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Blockly from "blockly/core";

const blockName = "s4d_set_data";

const blockData = {
"message0": "%{BKY_SET_DATA}",
"args0": [
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
},
{
"type": "input_value",
"name": "VALUE"
}
],
"previousStatement": null,
"nextStatement": null,
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
const value = Blockly.JavaScript.valueToCode(block, "VALUE", Blockly.JavaScript.ORDER_ATOMIC);
return `s4d.database.set(String(${key}), ${value});\n`;
};
35 changes: 35 additions & 0 deletions src/blocks/database/subtract_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Blockly from "blockly/core";

const blockName = "s4d_subtract_data";

const blockData = {
"message0": "%{BKY_SUBTRACT_DATA}",
"args0": [
{
"type": "input_value",
"name": "COUNT",
"check": "Number"
},
{
"type": "input_value",
"name": "KEY",
"check": [ "String", "Number" ]
}
],
"nextStatement": null,
"previousStatement": null,
"colour": "#5ba58b",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block) {
const key = Blockly.JavaScript.valueToCode(block, "KEY", Blockly.JavaScript.ORDER_ATOMIC);
const count = Blockly.JavaScript.valueToCode(block, "COUNT", Blockly.JavaScript.ORDER_ATOMIC);
return `s4d.database.subtract(String(${key}), parseInt(${count}));\n`;
};
2 changes: 1 addition & 1 deletion src/blocks/discord/base/set_bot_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Blockly.Blocks[blockName] = {

Blockly.JavaScript[blockName] = function(block){
const game = Blockly.JavaScript.valueToCode(block, "GAME", Blockly.JavaScript.ORDER_ATOMIC);
const code = `s4d.client.setActivity(String(${game}));\n`;
const code = `s4d.client.user.setActivity(String(${game}));\n`;
return code;
};

Expand Down
4 changes: 3 additions & 1 deletion src/blocks/discord/channels/send_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ 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_[0];
const contentType = block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection._check ?
block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection.check_[0] :
null;
if(contentType === "MessageEmbed"){
const code = `${channel}.send({ embed: ${content} });\n`;
return code;
Expand Down
6 changes: 4 additions & 2 deletions src/blocks/discord/channels/send_wait_reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ Blockly.JavaScript[blockName] = function(block){
const statementCatch = Blockly.JavaScript.statementToCode(block, "CATCH");
let code = "";
if(block.getInput("CONTENT").connection.targetConnection){
const contentType = block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection.check_[0];
const contentType = block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection._check ?
block.getInput("CONTENT").connection.targetConnection.getSourceBlock().outputConnection.check_[0] :
null;
if(contentType === "MessageEmbed"){
code = `${channel}.send({ embed: ${content} });\n`;
} else {
Expand All @@ -66,7 +68,7 @@ Blockly.JavaScript[blockName] = function(block){
} else {
code = `${channel}.send(String(${content}));\n`;
}
code += `${channel}.awaitMessages((m) => m.author.id === ${member}.id, { time: (${time}*60*1000), max: 1 }).then((collected) => { s4d.reply = collected.first().content; \n ${statementThen} \n s4d.reply = null; }).catch((e) => { console.error(e); ${statementCatch} });`;
code += `${channel}.awaitMessages((m) => m.author.id === ${member}.id, { time: (${time}*60*1000), max: 1 }).then(async (collected) => { s4d.reply = collected.first().content; \n ${statementThen} \n s4d.reply = null; }).catch(async (e) => { console.error(e); ${statementCatch} });`;
return code;
};

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/discord/joins/joining_member.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Blockly.Blocks[blockName] = {
};

Blockly.JavaScript[blockName] = function() {
const code = ["s4d.memberJoining", Blockly.JavaScript.ORDER_NONE];
const code = ["s4d.joiningMember", Blockly.JavaScript.ORDER_NONE];
return code;
};

Expand Down
2 changes: 1 addition & 1 deletion src/blocks/discord/joins/on_member_join.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ Blockly.Blocks[blockName] = {

Blockly.JavaScript[blockName] = function(block) {
const statements = Blockly.JavaScript.statementToCode(block, "STATEMENTS");
const code = `s4d.client.on('guildMemberAdd', async (param1) => {\ns4d.memberJoining = param1;\n${statements}s4d.memberArriving = null\n});\n`;
const code = `s4d.client.on('guildMemberAdd', async (param1) => {\ns4d.joiningMember = param1;\n${statements}s4d.joiningMember = null\n});\n`;
return code;
};
4 changes: 4 additions & 0 deletions src/blocks/discord/leaves/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "./leaving_guild";
import "./leaving_guild_raw";
import "./leaving_member_raw";
import "./on_member_leave";
33 changes: 33 additions & 0 deletions src/blocks/discord/leaves/leaving_guild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_leaving_guild";

const blockData = {
"message0": "%{BKY_LEAVING_GUILD}",
"colour": "#D85E47",
"output": "Server",
"tooltip": "",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function() {
const code = ["s4d.leavingMember.guild", Blockly.JavaScript.ORDER_NONE];
return code;
};

registerRestrictions(blockName, [
{
type: "toplevelparent",
message: "RES_MUST_BE_IN_ON_MEMBER_LEAVE",
types: [
"s4d_on_member_leave"
]
}
]);
Loading

0 comments on commit 33f6098

Please sign in to comment.