Skip to content

Commit 5c41393

Browse files
committed
Fix for issue #439
1 parent b9f81a4 commit 5c41393

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

_datafiles/world/default/rooms/tutorial/900.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function onCommand(cmd, rest, user, room) {
2525
ignoreCommand = true;
2626
}
2727

28-
fullCommand = cmd;
28+
fullCommand = ExpandCommand(cmd);
2929
if ( rest.length > 0 ) {
3030
fullCommand = cmd + ' ' + rest;
3131
}

_datafiles/world/default/rooms/tutorial/901.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function onCommand(cmd, rest, user, room) {
2626
ignoreCommand = true;
2727
}
2828

29-
fullCommand = cmd;
29+
fullCommand = ExpandCommand(cmd);
3030
if ( rest.length > 0 ) {
3131
fullCommand = cmd + ' ' + rest;
3232
}

_datafiles/world/default/rooms/tutorial/902.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function onCommand(cmd, rest, user, room) {
2424
ignoreCommand = true;
2525
}
2626

27-
fullCommand = cmd;
27+
fullCommand = ExpandCommand(cmd);
2828
if ( rest.length > 0 ) {
2929
fullCommand = cmd + ' ' + rest;
3030
}

_datafiles/world/default/rooms/tutorial/903.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function onCommand(cmd, rest, user, room) {
1616

1717
teacherMob = getTeacher(room);
1818

19-
fullCommand = cmd;
19+
fullCommand = ExpandCommand(cmd);
2020
if ( rest.length > 0 ) {
2121
fullCommand = cmd + ' ' + rest;
2222
}

internal/scripting/util_func.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/GoMudEngine/GoMud/internal/configs"
88
"github.com/GoMudEngine/GoMud/internal/events"
99
"github.com/GoMudEngine/GoMud/internal/gametime"
10+
"github.com/GoMudEngine/GoMud/internal/keywords"
1011
"github.com/GoMudEngine/GoMud/internal/users"
1112
"github.com/GoMudEngine/GoMud/internal/util"
1213
"github.com/dop251/goja"
@@ -45,6 +46,7 @@ func setUtilFunctions(vm *goja.Runtime) {
4546
vm.Set(`ColorWrap`, ColorWrap)
4647
vm.Set(`EventFlags`, EventFlags)
4748
vm.Set(`RaiseEvent`, RaiseEvent)
49+
vm.Set(`ExpandCommand`, ExpandCommand)
4850

4951
}
5052

@@ -181,3 +183,32 @@ func ColorWrap(txt string, colorClass ...string) string {
181183
func RaiseEvent(name string, data map[string]any) {
182184
events.AddToQueue(events.ScriptedEvent{Name: name, Data: data})
183185
}
186+
187+
func ExpandCommand(cmd string, limit ...int) string {
188+
189+
parts := util.SplitButRespectQuotes(cmd)
190+
191+
expansionsLeft := -1
192+
if len(limit) > 0 {
193+
expansionsLeft = limit[0]
194+
if expansionsLeft < -1 {
195+
expansionsLeft = -1
196+
}
197+
}
198+
199+
result := ""
200+
for _, abbr := range parts {
201+
if expansionsLeft != 0 {
202+
alias := keywords.TryCommandAlias(abbr)
203+
result += alias
204+
expansionsLeft--
205+
} else {
206+
result += abbr
207+
}
208+
result += " "
209+
}
210+
211+
result = strings.Trim(result, " ")
212+
213+
return result
214+
}

0 commit comments

Comments
 (0)