Skip to content

Commit 32d55a8

Browse files
committed
Wizebot API Integration AddOn ready
- Added Configs for Wizebot API - Added Wizebot API AddOn Script
1 parent b94a10d commit 32d55a8

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

plugins/Denizen/scripts/SpikeCodeRedeem-Config.dsc

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ SpikeCodeRedeemData:
7171
# As soon as it is possible we'll do it that way.
7272
devKey: Put Your Key Here!
7373

74+
# + Not AddOn specific configs
75+
# This setting is used by the following AddOns:
76+
# - Wizebot API
77+
server:
78+
name: My Minecraft Server
79+
ip: mc.example.tld
80+
7481
# + Add-On configs.
7582
# ------ Auto Generate ------
7683
# For these feature you need the Auto Generate Addon
@@ -99,12 +106,44 @@ SpikeCodeRedeemData:
99106
# Set to false to keep the old one but you need to
100107
# set auto.code to random then or it will throw errors.
101108
delete: true
102-
109+
103110
# ------ Wizebot API -------
104111
# For these feature you need the Wizebot Addon
105112
wizebot:
106113
web:
114+
# Only change this if you use nginx or something similar. If you do it anyway Wizebot won't be able to connect to your server.
107115
port: 80
116+
API:
117+
# Set here a SECURE API key.
118+
# If set to none it's not usable
119+
key: none
120+
121+
shop:
122+
# ID = Uses the item_id to check which commands to assign.
123+
# group = Uses the "group" query parameter to get the - Easier
124+
# For more info and to get t know how to get the item IDs take a look at the wiki on Github
125+
# https://github.com/spikehidden/coderedeemscript/wiki
126+
mode: ID
127+
128+
# Map of group IDs which will be used for group mode.
129+
groups:
130+
# Group ID
131+
group_01:
132+
# List of Wizebot item IDs that shall be part of this group.
133+
# Won't be used if mode is set to group
134+
ids:
135+
- 45761
136+
commands:
137+
# The amount of random commands to choose.
138+
amount: 1
139+
# The commands to randomly assign.
140+
# Set amount to 0 to disable
141+
random:
142+
- minecraft:give <p> diamond 64
143+
# A list of commands that are always assigned to a code.
144+
# Set to "alwaysCommand: none" to disable
145+
always:
146+
- minecraft:say <p> redeemed <code>
108147

109148

110149
#+ ------ Debug & Log ------

plugins/Denizen/scripts/SpikeCodeRedeem-Wizebot.dsc

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,82 @@ SpikeCodeRedeemWizebotAPI:
8484
type: world
8585
debug: true
8686
events:
87-
webserver web request method:post path:/wizebot:
88-
-
87+
webserver web request method:post path:/wizebot/create:
88+
# Get query parameters
89+
- define query <context.query>
90+
- define code <[query].get[code].if_null[random]>
91+
- define queryKey <[query].get[key].if_null[null]>
92+
- define duration <[query].get[duration].if_null[unlimited]>
93+
- define prefix <[query].get[prefix].if_null[<empty>]>
94+
- define group <[query].get[group].if_null[null]>
95+
96+
# Map POST parameters:
97+
- define post <context.body.as_map>
98+
- define item_id <[post].get[item_id]>
99+
- define item_name <[post].get[item_name]>
100+
- define viewer_id <[post].get[item_id]>
101+
- define viewer_name <[post].get[item_id]>
102+
103+
# Get stuff from config
104+
- define key <script[SpikeCodeRedeemData].data_key[wizebot.web.key].if_null[none]>
105+
- define mode <script[SpikeCodeRedeemData].data_key[wizebot.shop.mode].if_null[ID]>
106+
- define groupList <script[SpikeCodeRedeemData].data_key[wizebot.shop.groups].if_null[none]>
107+
108+
# If key is missing, invalid or not configerured send 401 ERROR
109+
- if <[key]> == none || <[queryKey]> != <[key]>:
110+
- define answer "UNAUTHORIZED - KEY IS MISSING OR INVALID"
111+
- determine code:401 passively
112+
- determine headers:[Content-Type=text/plain] passively
113+
- determine RAW_TEXT_CONTENT:<[answer]>
114+
115+
# If nothing is set up in the Config send KO status and ERROR
116+
- if <[groupList]> == none:
117+
- define text "Configuration Error! - Please tell the Streamer that something went wrong."
118+
- define status KO
119+
- define answer "{<&dq>status<&dq>: <&dq><[status]><&dq>, <&dq>text_to_return<&dq>: <&dq><[text]><&dq>}"
120+
- determine code:200 passively
121+
- determine headers:[Content-Type=application/json] passively
122+
- determine RAW_TEXT_CONTENT:<[answer]>
123+
124+
# Get group if in ID mode
125+
- if <[mode]> == ID:
126+
- foreach <[groupList]>:
127+
- if <[key].get[ids].contains_text[<[item_id]>]>:
128+
- define group <[key]>
129+
- foreach stop
130+
131+
# Get group Data
132+
- define groupData <script[SpikeCodeRedeemData].data_key[wizebot.shop.groups.<[group]>].if_null[none]>
133+
- define randomAmount <[groupData].get[amount].if_null[0]>
134+
- define random <[groupData].get[commands.random].if_null[null]>
135+
- define always <[groupData].get[commands.always].if_null[none]>
136+
137+
# Add always commands.
138+
- if <[always]> != none:
139+
- define commands <[always].as_list>
140+
141+
# Choose radnom commands.
142+
- if <[randomAmount]> <= 0 || <[random]> == null:
143+
- define commands:->:<[random].random[<[randomAmount]>]>
144+
145+
# If commands are empty run error.
146+
- if !<[commands].exists>:
147+
- define text "Configuration Error! - Please tell the Streamer that something went wrong."
148+
- define status KO
149+
- define answer "{<&dq>status<&dq>: <&dq><[status]><&dq>, <&dq>text_to_return<&dq>: <&dq><[text]><&dq>}"
150+
- determine code:200 passively
151+
- determine headers:[Content-Type=application/json] passively
152+
- determine RAW_TEXT_CONTENT:<[answer]>
153+
154+
#Inject Code Creation Task
155+
- define amount 1
156+
- inject SpikeCodeCreateCode
157+
158+
# Finaly send the code to Wizebot
159+
- define text "Your code for <[server.name]> is <&dq><[code]><&dq>"
160+
- define status OK
161+
- define answer "{<&dq>status<&dq>: <&dq><[status]><&dq>, <&dq>text_to_return<&dq>: <&dq><[text]><&dq>}"
162+
- determine code:401 passively
163+
- determine headers:[Content-Type=application/json] passively
164+
- determine RAW_TEXT_CONTENT:<[answer]>
165+

0 commit comments

Comments
 (0)