Date: 2018/03/16 19:12:20 UTC-07:00
Type: Denizen Script
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
# This is more a simple script error check that runs through all scripts and check if anything is missing
# This script checks for the following errors of a script:
# - file can't be parse as YAML
# - contains the right types (and correct format)
# - contains the script keys
# - typo mistakes (has definition which should be definitions for task types)
# This script cannot:
# - fix the errors for you as that can result in re-formatting your scripts
# - show the exact line of the error (recommended to use monkeybot on IRC/Discord)
# - find all errors as that requires knowledge of available commands/events/tags etc.
ScriptErrorHelper_Data:
type: yaml data
config:
types:
- "world"
- "task"
- "command"
- "interact"
- "assignment"
- "yaml data"
- "yaml data"
- "format"
- "inventory"
ScriptErrorHelper_Events:
type: world
events:
on reload scripts:
- if <context.haderror> {
- wait 10t
- inject ScriptErrorHelper_CheckAllScripts
}
ScriptErrorHelper_CheckAllScripts:
type: task
script:
- announce "<&e>Starting search of errors in denizen scripts..." to_ops
- flag server SEH_Errors:0
- foreach <server.list_files[/scripts]> {
- if <def[value].ends_with[.yml]> {
- ~run ScriptErrorHelper_CheckScripts_Task instantly context:<def[value]>
}
}
- if <server.flag[SEH_Errors].round> > 0 {
- announce "<&e>Found <&c><server.flag[SEH_Errors].round> <&e>errors in total"
}
else {
- announce "<&a>All scripts has been verfied"
}
ScriptErrorHelper_Found:
type: task
definitions: message
script:
- announce "SEH<&co> <&c><def[message]>" to_ops
- flag server SEH_Errors:++
ScriptErrorHelper_CheckScripts_Task:
type: task
definitions: file
script:
- define full_path "/scripts/<def[file]>"
- define id "SEH_File"
- if <server.has_file[<def[full_path]>].not> {
- define message "Could not find script file <def[file]>"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- yaml "load:<def[full_path]>" id:<def[id]>
- if <yaml.list.contains[<def[id]>].not> {
- define message "could not parse YAML to <def[file]>"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- foreach <yaml[<def[id]>].list_keys[]> {
- narrate "<&7><def[value]>"
- define path <def[value]>
- inject ScriptErrorHelper_CheckScript
}
ScriptErrorHelper_CheckScript:
type: task
# definitions: path
script:
- define check_path <def[path]>
- inject ScriptErrorHelper_CheckPath
- if <def[result]> == end_path {
- define message "<def[path]> is not a right script"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- if <def[list].contains[type].not> {
- define message "<def[path]> does not contain a type"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- define type <yaml[<def[id]>].read[<def[path]>.type]>
- if <s@ScriptErrorHelper_Data.yaml_key[config.types].contains[<def[type]>].not> {
- define message "<def[type]> is not a valid type in <def[path]>"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- if <def[type]> == task {
- if <def[list].contains[script].not> {
- define message "<def[path]> as <def[type]> type does not have the script key"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- if <def[list].contains[definition]> {
- define message "<def[path]> has typo for definitions"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
}
else if <def[type]> == world {
- if <def[list].contains[events].not> {
- define message "<def[path]> as <def[type]> type does not have the events key"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
}
else if <def[type]> == command {
- if <def[list].contains[name].not> {
- define message "<def[path]> as <def[type]> type does not have the name key"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
- if <def[list].contains[script].not> {
- define message "<def[path]> as <def[type]> type does not have the script key"
- run ScriptErrorHelper_Found instantly context:<def[message]>
- queue clear
}
}
ScriptErrorHelper_CheckPath:
type: task
# definitions: check_path
script:
- define list <yaml[<def[id]>].list_keys[<def[check_path]>]||null>
- if <def[list]> == null {
- define result end_path
}
else {
- define result continues
}