Skip to content

Commit

Permalink
✨ Add members blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Apr 15, 2020
1 parent 51c3981 commit 692ddc2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import "./blocks/discord/message/";
import "./blocks/discord/channels/";
import "./blocks/discord/servers/";
import "./blocks/discord/roles/";
import "./blocks/discord/members/";
import "./blocks/text/";
import "./prompt";
Expand Down
72 changes: 72 additions & 0 deletions src/blocks/discord/members/get_member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import * as Blockly from "blockly/core";
import { registerRestrictions } from "../../../restrictions";

const blockName = "s4d_get_member";

const blockData = {
"message0": "%{BKY_GET_MEMBER}",
"args0": [
{
"type": "input_value",
"name": "VALUE",
"check": "String"
},
{
"type": "field_dropdown",
"name": "SEARCH_TYPE",
"options": [
[
"%{BKY_USERNAME}",
"USERNAME"
],
[
"id",
"ID"
]
]
},
{
"type": "input_value",
"name": "SERVER",
"check": "Server"
}
],
"colour": "#F56476",
"output": "Role",
"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");
const server = block.getFieldValue("SERVER");
if(searchType === "USERNAME"){
return [ `${server}.members.cache.find((m) => m.user.username === ${value})`, Blockly.JavaScript.ORDER_NONE ];
} else {
return [ `(${server}.members.cache.get(${value}) || await ${server}.members.fetch(${value}))`, Blockly.JavaScript.ORDER_NONE ];
}
};

registerRestrictions(blockName, [
{
type: "notempty",
message: "RES_GET_MEMBER_VALUE",
types: [
"VALUE"
]
},
{
type: "notempty",
message: "RES_GET_MEMBER_SERVER",
types: [
"SERVER"
]
}
]);
1 change: 1 addition & 0 deletions src/blocks/discord/members/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./get_member";
7 changes: 6 additions & 1 deletion src/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const blocklyMessages = {
TOOLBOX_BASE: "Base",
TOOLBOX_SERVER: "Serveurs",
TOOLBOX_ROLES: "Rôles",
TOOLBOX_MEMBERS: "Membres",
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 !",
Expand All @@ -136,7 +137,11 @@ const blocklyMessages = {
RES_GET_ROLE_VALUE: "Vous devez préciser un nom ou un identifiant de rôle valide !",
RES_GET_SERVER_VALUE: "Vous devez préciser un nom ou un identifiant de serveur valide !",
FIND_ROLE: "Trouver un rôle",
ROLE_ASSIGNMENT: "Affectation des rôles"
ROLE_ASSIGNMENT: "Affectation des rôles",
RES_GET_MEMBER_VALUE: "Vous devez préciser un nom ou un identifiant de membre valide !",
RES_GET_MEMBER_SERVER: "Vous devez préciser un serveur valide sur lequel chercher le membre !",
GET_MEMBER: "obtenir le membre dont le %2 est %1 sur le serveur %3",
FIND_MEMBER: "Trouver un membre"
};

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 @@ -423,6 +423,10 @@ export default (Blockly) => {
<block type="s4d_add_role"></block>
<block type="s4d_remove_role"></block>
</category>
<category name="{{ TOOLBOX_MEMBERS }}" colour="#003F91">
<label text="%{BKY_FIND_MEMBER}"></label>
<block type="s4d_get_member"></block>
</category>
</xml>
`.replace(/{{\s([A-z]{3,})\s}}/g, (x) => {
return Blockly.Msg[x.replace("{{ ", "").replace(" }}", "")];
Expand Down

0 comments on commit 692ddc2

Please sign in to comment.