MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / cliCommand

Method cliCommand

modules/clibridge/clibridge.go:190–235  ·  view source on GitHub ↗
(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)

Source from the content-addressed store, hash-verified

188}
189
190func (m *CLIBridgeModule) cliCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) {
191 if !m.isEnabled() {
192 user.SendText("CLI bridge is not enabled.")
193 return true, nil
194 }
195
196 connId := users.GetConnectionId(user.UserId)
197 connDetails := connections.Get(connId)
198 if connDetails == nil {
199 user.SendText("Connection not found.")
200 return true, nil
201 }
202
203 if connDetails.IsWebSocket() {
204 user.SendText("CLI tools are not supported over WebSocket connections.")
205 return true, nil
206 }
207
208 parts := strings.Fields(rest)
209 if len(parts) < 1 {
210 user.SendText("Usage: cli <tool> [args...]")
211 return true, nil
212 }
213
214 if m.getSession(connId) != nil {
215 user.SendText("A CLI session is already active on this connection.")
216 return true, nil
217 }
218
219 toolName := parts[0]
220 args := parts[1:]
221
222 if !m.isToolAllowed(toolName) {
223 user.SendText(fmt.Sprintf("Tool %q is not in the allowed tools list.", toolName))
224 return true, nil
225 }
226
227 events.AddToQueue(events.CLIRequest{
228 UserId: user.UserId,
229 ConnectionId: connId,
230 Command: toolName,
231 Args: args,
232 })
233
234 return true, nil
235}
236
237func (m *CLIBridgeModule) onCLIRequest(e events.Event) events.ListenerReturn {
238 evt, ok := e.(events.CLIRequest)

Callers

nothing calls this directly

Calls 8

isEnabledMethod · 0.95
getSessionMethod · 0.95
isToolAllowedMethod · 0.95
GetConnectionIdFunction · 0.92
GetFunction · 0.92
AddToQueueFunction · 0.92
IsWebSocketMethod · 0.65
SendTextMethod · 0.45

Tested by

no test coverage detected