Skip to content

Commit

Permalink
✨ Add get_server block
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Apr 14, 2020
1 parent af81c21 commit fac19cf
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "./blocks/discord/base/";
import "./blocks/discord/joins/";
import "./blocks/discord/message/";
import "./blocks/discord/channels/";
import "./blocks/discord/servers/";
import "./blocks/text/";
import "./prompt";
Expand Down
59 changes: 59 additions & 0 deletions src/blocks/discord/servers/get_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_get_server";

const blockData = {
"message0": "%{BKY_GET_SERVER}",
"args0": [
{
"type": "input_value",
"name": "VALUE",
"check": "String"
},
{
"type": "field_dropdown",
"name": "SEARCH_TYPE",
"options": [
[
"%{BKY_NAME}",
"NAME"
],
[
"id",
"ID"
]
]
}
],
"colour": "#F56476",
"output": "Server",
"tooltip": "",
"helpUrl": ""
};

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

Blockly.JavaScript[blockName] = function(block){
const value = Blockly.JavaScript.valueToCode(block, "VALUE", Blockly.JavaScript.ORDER_ATOMIC);
const searchType = block.getFieldValue("SEARCH_TYPE");
if(searchType === "NAME"){
return [ `s4d.client.guilds.cache.find((guild) => guild.name === ${value}`, Blockly.JavaScript.ORDER_NONE ];
} else {
return [ `s4d.client.guilds.cache.get(${value})`, Blockly.JavaScript.ORDER_NONE ];
}
};

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_MISSING_SERVER_VALUE",
types: [
"VALUE"
]
}
]);
1 change: 1 addition & 0 deletions src/blocks/discord/servers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./get_server";
6 changes: 5 additions & 1 deletion src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ const blocklyMessages = {
TOOLBOX_JOINS: "Joins",
TOOLBOX_ACTIONS: "Actions",
TOOLBOX_MESSAGES: "Messages",
TOOLBOX_BASE: "Base"
TOOLBOX_BASE: "Base",
TOOLBOX_SERVER: "Servers",
FIND_SERVER: "Find a server",
GET_SERVER: "get the server with %2 equal to %1",
RES_GET_SERVER_SERVER: "You must specify a valid server name or ID!",
};

export const applyBlocklyLocale = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ const blocklyMessages = {
TOOLBOX_JOINS: "Arrivées",
TOOLBOX_ACTIONS: "Actions",
TOOLBOX_MESSAGES: "Messages",
TOOLBOX_BASE: "Base"
TOOLBOX_BASE: "Base",
TOOLBOX_SERVER: "Serveurs",
FIND_SERVER: "Trouver un serveur",
GET_SERVER: "obtenir le serveur dont le %2 est %1",
RES_GET_SERVER_SERVER: "Vous devez préciser un nom ou un identifiant de serveur valide !",
};

export const applyBlocklyLocale = () => {
Expand Down
4 changes: 4 additions & 0 deletions src/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ export default (Blockly) => {
<block type="s4d_joining_member_raw"></block>
<block type="s4d_joining_guild"></block>
</category>
<category name="{{ TOOLBOX_SERVER }}" colour="#547AA5">
<label text="%{BKY_FIND_SERVER}"></label>
<block type="s4d_get_server"></block>
</category>
<category name="{{ TOOLBOX_CHANNELS }}" colour="#40BF4A">
<label text="%{BKY_FIND_CHANNEL}"></label>
<block type="s4d_get_channel"></block>
Expand Down

0 comments on commit fac19cf

Please sign in to comment.