-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51c3981
commit 692ddc2
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./get_member"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters