Date: 2021/11/30 20:28:21 UTC-08:00
Type: Diff Report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
tag_parser_bot:
type: world
debug: false
samples:
link: (UNSET)
sample_bool: true
sample_0: 0
sample_1: 1
sample_10: 10
sample_0p5: 0.5
sample_text: Hello, world!
help: try typing 'help' to the bot!
- script_paths:
- stop_bot:
- - if <server.has_flag[tag_parser_bot_running]>:
- - ~discord id:tag_parser disconnect
- - flag server tag_parser_bot_running:!
- start_bot:
- - inject tag_parser_bot.script_paths.stop_bot
- - yaml load:data/tag_parser.yml id:tag_parser_temp
- - if !<yaml.list.contains[tag_parser_temp]>:
- - debug error "Load failed."
- - stop
- - flag server tag_parser_logpath:<yaml[tag_parser_temp].read[bot.discord.log_path]>
- - flag server tag_parser_validchannels:!
- - flag server tag_parser_validchannels:|:<yaml[tag_parser_temp].read[bot.discord.valid_channels]>
- - flag server tag_parser_barredchannels:!
- - flag server tag_parser_barredchannels:|:<yaml[tag_parser_temp].read[bot.discord.barred_channels]>
- - flag server tag_parser_barredchannelmessages:!
- - flag server tag_parser_barredchannelmessages:|:<yaml[tag_parser_temp].read[bot.discord.barred_channel_messages]>
- - flag server tag_parser_link:<yaml[tag_parser_temp].read[script.link]>
- - yaml unload id:tag_parser_temp
- - define samples <script.data_key[samples].with[link].as[<server.flag[tag_parser_link]>].with[version].as[<server.version>].with[denizen_version].as[<server.denizen_version>]>
- - flag server tag_parser_samples:<[samples]>
- - ~discordconnect id:tag_parser tokenfile:data/tagparser_token.txt
- - flag server tag_parser_bot_running
- process_tag:
- - log "<util.time_now.format> [<[name]>] in [<[origin]>] wants to process tag <[tag]>" file:<server.flag[tag_parser_logpath]>
- - flag server tag_parser_result_temp:!
- # If you ever enable this on your own copy of the bot I will break your knees. Don't do it. Official dTagParser instance only.
- - define should_record false
- - ~run tag_run_task def:<list_single[<[tag]>].include[<[should_record]>]>
- - define result <server.flag[tag_parser_result_temp].if_null[<map.with[failed].as[FAILED=FLAG_MISSING]>]>
- - flag server tag_parser_result_temp:!
- - log "<util.time_now.format> [<[name]>] in [<[origin]>] got result <[result]>" file:<server.flag[tag_parser_logpath]>
- crunch_result:
- - define final_result <empty>
- - if <[result].contains[valid]>:
- - define final_result <[result].get[valid]><n>
- - if <[result].contains[failed]>:
- - foreach <[result].get[failed]>:
- - if <[value].starts_with[Error=]>:
- - define final_result "<[final_result]>Had error: <[value].after[Error=]><n>"
- - else if <[value].starts_with[Exception=]>:
- - define final_result "<[final_result]>Had internal exception: <[value].after[Exception=]><n>"
- - else if <[value].starts_with[FAILED=]>:
- - define fail_reason <[value].after[FAILED=]>
- - if <[fail_reason]> == FLAG_MISSING:
- - define final_result "<[final_result]>Got no result value.<n>"
- - else:
- - define final_result "<[final_result]>Got failure '<[fail_reason]>'.<n>"
- - if <[final_result].trim.length> == 0:
- - define final_result <empty>
- - if <[final_result].length> > 1000 || <[tag].length.add[<[final_result].length>]> > 1500:
- - define tag (Spam)
- - define final_result "Input too long, refused."
- - if <[final_result].to_list.filter[is[==].to[<n>]].size> > 10:
- - define final_result "Newline spam, refused."
events:
- on server start:
+ after server start:
- wait 5s
- flag server tag_parser_bot_running:!
- - inject tag_parser_bot.script_paths.start_bot
+ - inject tag_parser_start_bot_task
on script generates error:
- flag server tag_parser_result_temp.failed:|:Error=<context.message.strip_color>
on server generates exception:
- flag server tag_parser_result_temp.failed:|:Exception=<context.type>-<context.message>
- on discord message received for:tag_parser:
+ after discord message received for:tag_parser:
- flag server tag_parser_bot_running
- - define name <context.new_message.author.id>/<context.new_message.author.name>
- - define origin <context.group>/<context.channel>/<context.group.name>/<context.channel.name>
- - announce to_console "Discord chatter! [<[name]>] in [<[origin]>] saying <context.new_message.text> and mentioning <context.new_message.mentioned_users>"
- if !<context.new_message.mentioned_users.parse[id].contains[<context.bot.self_user.id>]>:
- stop
- - if !<server.flag[tag_parser_validchannels].contains[<context.channel.id>]>:
- - define found <server.flag[tag_parser_barredchannels].find[<context.channel.id>]>
+ # Ensure it's an actual '@' not just a reply
+ - if !<context.new_message.text.contains_text[<<>@<context.bot.self_user.id><>>]> && !<context.new_message.text.contains_text[<<>@!<context.bot.self_user.id><>>]>:
- - if <[found]> > 0:
- - ~discordmessage id:tag_parser channel:<context.channel> "Cannot parse that in this channel! <server.flag[tag_parser_barredchannelmessages].get[<[found]>]>"
- stop
- - if <context.new_message.text_no_mentions.trim> == link:
- - ~discordmessage id:tag_parser channel:<context.channel> "The source script for **dTagParser** can be found at <<><server.flag[tag_parser_samples].as_map.get[link]><>>"
- - stop
- - waituntil rate:1s !<server.has_flag[tag_parser_bot_processing_now]>
- - flag server tag_parser_bot_processing_now duration:1m
- - define tag <context.new_message.text_no_mentions.replace_text[<n>].with[<&sp>].trim>
- - inject tag_parser_bot.script_paths.process_tag player:<server.players.get[1]> npc:<server.npcs.get[1]>
- - inject tag_parser_bot.script_paths.crunch_result
- - ~discordmessage id:tag_parser channel:<context.channel> "Tag parse results for `<[tag].replace_text[`].with[']>`<&co> <[result].get[recording].if_null[]><n>```<n><[final_result].replace_text[`].with[']>```"
- - flag server tag_parser_bot_processing_now:!
+ - definemap args:
+ author: <context.new_message.author>
+ channel: <context.channel>
+ to_parse: <context.new_message.text_no_mentions>
+ reply_to: <context.new_message>
+ handle_output: tag_parser_message_reply_task
+ - run tag_parse_core_task defmap:<[args]>
+ on discord slash command name:parsetag:
+ - ~discordinteraction defer interaction:<context.interaction>
+ - definemap args:
+ author: <context.interaction.user>
+ channel: <context.channel>
+ to_parse: <context.options.get[tag].if_null[<empty>]>
+ reply_to: <context.interaction>
+ handle_output: tag_parser_interaction_reply_task
+ handle_fail: tag_parser_interaction_fail_task
+ - run tag_parse_core_task defmap:<[args]>
+
+tag_parser_stop_bot_task:
+ type: task
+ debug: false
+ script:
+ - if <server.has_flag[tag_parser_bot_running]>:
+ - ~discord id:tag_parser disconnect
+ - flag server tag_parser_bot_running:!
+
+tag_parser_start_bot_task:
+ type: task
+ debug: false
+ script:
+ - inject tag_parser_stop_bot_task
+ - yaml load:data/tag_parser.yml id:tag_parser_temp
+ - if !<yaml.list.contains[tag_parser_temp]>:
+ - debug error "Load failed."
+ - stop
+ - flag server tag_parser_logpath:<yaml[tag_parser_temp].read[bot.discord.log_path]>
+ - flag server tag_parser_validchannels:!
+ - flag server tag_parser_validchannels:|:<yaml[tag_parser_temp].read[bot.discord.valid_channels]>
+ - flag server tag_parser_barredchannels:!
+ - flag server tag_parser_barredchannels:|:<yaml[tag_parser_temp].read[bot.discord.barred_channels]>
+ - flag server tag_parser_barredchannelmessages:!
+ - flag server tag_parser_barredchannelmessages:|:<yaml[tag_parser_temp].read[bot.discord.barred_channel_messages]>
+ - flag server tag_parser_link:<yaml[tag_parser_temp].read[script.link]>
+ - yaml unload id:tag_parser_temp
+ - define samples <script.data_key[samples].with[link].as[<server.flag[tag_parser_link]>].with[version].as[<server.version>].with[denizen_version].as[<server.denizen_version>]>
+ - flag server tag_parser_samples:<[samples]>
+ - ~discordconnect id:tag_parser tokenfile:data/tagparser_token.txt
+ - flag server tag_parser_bot_running
+
+tag_parse_core_task:
+ type: task
+ debug: false
+ definitions: author|channel|to_parse|reply_to|handle_output|handle_fail
+ script:
+ - define name <[author].id>/<[author].name>
+ - define origin <[channel].group>/<[channel]>/<[channel].group.name>/<[channel].name>
+ - if !<server.flag[tag_parser_validchannels].contains[<[channel].id>]>:
+ - define found <server.flag[tag_parser_barredchannels].find[<[channel].id>]>
+ - if <[found]> > 0:
+ - ~run <[handle_output]> def.reply_to:<[reply_to]> "Cannot parse that in this channel! <server.flag[tag_parser_barredchannelmessages].get[<[found]>]>"
+ - else:
+ - if <[handle_fail].exists>:
+ - run <[handle_fail]> def.reply_to:<[reply_to]>
+ - stop
+ - if <[to_parse].trim> == link:
+ - ~run <[handle_output]> def.reply_to:<[reply_to]> "def.message:The source script for **dTagParser** can be found at <<><server.flag[tag_parser_samples].as_map.get[link]><>>"
+ - stop
+ - waituntil rate:1s !<server.has_flag[tag_parser_bot_processing_now]>
+ - flag server tag_parser_bot_processing_now duration:1m
+ - define tag <[to_parse].replace_text[<n>].with[<&sp>].trim>
+ - inject tag_parser_process_tag_task player:<server.players.get[1]> npc:<server.npcs.get[1]>
+ - inject tag_parser_crunch_result_task
+ - ~run <[handle_output]> def.reply_to:<[reply_to]> "def.message:Tag parse results for `<[tag].replace_text[`].with[']>`<&co> <[result].get[recording].if_null[]><n>```<n><[final_result].replace_text[`].with[']>```"
+ - flag server tag_parser_bot_processing_now:!
+
+tag_parser_message_reply_task:
+ type: task
+ debug: false
+ definitions: reply_to|message
+ script:
+ - ~discordmessage id:tag_parser reply:<[reply_to]> <[message]>
+ - wait 1t
+
+tag_parser_interaction_reply_task:
+ type: task
+ debug: false
+ definitions: reply_to|message
+ script:
+ - ~discordinteraction reply interaction:<[reply_to]> <[message]>
+ - wait 1t
+
+tag_parser_interaction_fail_task:
+ type: task
+ debug: false
+ definitions: reply_to
+ script:
+ - ~discordinteraction delete interaction:<[reply_to]>
+ - wait 1t
+
+tag_parser_process_tag_task:
+ type: task
+ debug: false
+ definitions: name|origin|tag|channel
+ script:
+ - log "<util.time_now.format> [<[name]>] in [<[origin]>] wants to process tag <[tag]>" file:<server.flag[tag_parser_logpath]>
+ - flag server tag_parser_result_temp:!
+ # If you ever enable this on your own copy of the bot I will break your knees. Don't do it. Official dTagParser instance only.
+ - if <server.has_flag[dtagparser_allowed_to_record_ever]>:
+ - inject dtag_determine_shouldrecord
+ - else:
+ - define should_record false
+ - ~run tag_run_task def:<list_single[<[tag]>].include[<[should_record]>]>
+ - define result <server.flag[tag_parser_result_temp].if_null[<map.with[failed].as[FAILED=FLAG_MISSING]>]>
+ - flag server tag_parser_result_temp:!
+ - log "<util.time_now.format> [<[name]>] in [<[origin]>] got result <[result]>" file:<server.flag[tag_parser_logpath]>
tag_run_task:
type: task
definitions: tag|record
debug: false
script:
- define samples <server.flag[tag_parser_samples].as_map.with[sample_player].as[<player>].with[sample_npc].as[<npc>]>
- foreach <[samples].keys> as:key:
- define <[key]> <[samples].get[<[key]>]>
- define help "Tell me any valid Denizen tags, like <<>player.name<>> and I'll parse them for you! Alternately, tell me a valid definition name (like 'samples') and I'll tell you its contents."
- if !<[tag].contains_text[<<>]> && <[<[tag]>].exists>:
- flag server tag_parser_result_temp.valid:<[<[tag]>]>
- else:
- #- if <[record]>:
- # - debug record start
+ - if <[record]>:
+ - inject dtag_record_start
- inject tag_parser_task
- #- if <[record]>:
- # - ~debug record submit save:recorded
+ - if <[record]>:
+ - inject dtag_record_finish
- # - if !<entry[recorded].submitted.exists>:
- # - define record_url "(Submit Failed)"
- # - else:
- # - define record_url <<><entry[recorded].submitted><>>
- # - flag server tag_parser_result_temp.recording:<[record_url]>
- flag server tag_parser_result_temp.valid:<[result]>
tag_parser_task:
type: task
definitions: tag
script:
- define result <[tag].parsed>
+
+tag_parser_crunch_result_task:
+ type: task
+ debug: false
+ definitions: tag|result
+ script:
+ - define final_result <empty>
+ - if <[result].contains[valid]>:
+ - define final_result <[result].get[valid]><n>
+ - if <[result].contains[failed]>:
+ - foreach <[result].get[failed]>:
+ - if <[value].starts_with[Error=]>:
+ - define final_result "<[final_result]>Had error: <[value].after[Error=]><n>"
+ - else if <[value].starts_with[Exception=]>:
+ - define final_result "<[final_result]>Had internal exception: <[value].after[Exception=]><n>"
+ - else if <[value].starts_with[FAILED=]>:
+ - define fail_reason <[value].after[FAILED=]>
+ - if <[fail_reason]> == FLAG_MISSING:
+ - define final_result "<[final_result]>Got no result value.<n>"
+ - else:
+ - define final_result "<[final_result]>Got failure '<[fail_reason]>'.<n>"
+ - if <[final_result].trim.length> == 0:
+ - define final_result <empty>
+ - if <[final_result].length> > 1000 || <[tag].length.add[<[final_result].length>]> > 1500:
+ - define tag (Spam)
+ - define final_result "Input too long, refused."
+ - if <[final_result].to_list.filter[is[==].to[<n>]].size> > 10:
+ - define final_result "Newline spam, refused."
+
+# This is enabled via /ex run tag_parser_generate_command
+# only needs to be ran once ever
+tag_parser_generate_command:
+ type: task
+ debug: false
+ script:
+ - definemap options:
+ 1:
+ type: string
+ name: tag
+ description: The tag to be parsed.
+ required: true
+ - ~discordcommand id:tag_parser create name:parsetag "description:Parses a Denizen tag insta-magically on Discord." options:<[options]>
+ - narrate "Command registered"
+