(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)
| 188 | } |
| 189 | |
| 190 | func (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 | |
| 237 | func (m *CLIBridgeModule) onCLIRequest(e events.Event) events.ListenerReturn { |
| 238 | evt, ok := e.(events.CLIRequest) |
nothing calls this directly
no test coverage detected