|
| 1 | +package assistant |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/agnath18K/lumo/internal/core" |
| 7 | +) |
| 8 | + |
| 9 | +// handleListNetworkDevices handles the "list network devices" command |
| 10 | +func (p *Processor) handleListNetworkDevices(input string) (*core.Command, error) { |
| 11 | + return &core.Command{ |
| 12 | + Type: core.CommandTypeConnectivity, |
| 13 | + Action: "list-devices", |
| 14 | + Target: "", |
| 15 | + RawInput: input, |
| 16 | + }, nil |
| 17 | +} |
| 18 | + |
| 19 | +// handleEnableWifi handles the "enable wifi" command |
| 20 | +func (p *Processor) handleEnableWifi(input string) (*core.Command, error) { |
| 21 | + return &core.Command{ |
| 22 | + Type: core.CommandTypeConnectivity, |
| 23 | + Action: "enable-wifi", |
| 24 | + Target: "", |
| 25 | + RawInput: input, |
| 26 | + }, nil |
| 27 | +} |
| 28 | + |
| 29 | +// handleDisableWifi handles the "disable wifi" command |
| 30 | +func (p *Processor) handleDisableWifi(input string) (*core.Command, error) { |
| 31 | + return &core.Command{ |
| 32 | + Type: core.CommandTypeConnectivity, |
| 33 | + Action: "disable-wifi", |
| 34 | + Target: "", |
| 35 | + RawInput: input, |
| 36 | + }, nil |
| 37 | +} |
| 38 | + |
| 39 | +// handleWifiStatus handles the "wifi status" command |
| 40 | +func (p *Processor) handleWifiStatus(input string) (*core.Command, error) { |
| 41 | + return &core.Command{ |
| 42 | + Type: core.CommandTypeConnectivity, |
| 43 | + Action: "wifi-status", |
| 44 | + Target: "", |
| 45 | + RawInput: input, |
| 46 | + }, nil |
| 47 | +} |
| 48 | + |
| 49 | +// handleEnableBluetooth handles the "enable bluetooth" command |
| 50 | +func (p *Processor) handleEnableBluetooth(input string) (*core.Command, error) { |
| 51 | + return &core.Command{ |
| 52 | + Type: core.CommandTypeConnectivity, |
| 53 | + Action: "enable-bluetooth", |
| 54 | + Target: "", |
| 55 | + RawInput: input, |
| 56 | + }, nil |
| 57 | +} |
| 58 | + |
| 59 | +// handleDisableBluetooth handles the "disable bluetooth" command |
| 60 | +func (p *Processor) handleDisableBluetooth(input string) (*core.Command, error) { |
| 61 | + return &core.Command{ |
| 62 | + Type: core.CommandTypeConnectivity, |
| 63 | + Action: "disable-bluetooth", |
| 64 | + Target: "", |
| 65 | + RawInput: input, |
| 66 | + }, nil |
| 67 | +} |
| 68 | + |
| 69 | +// handleBluetoothStatus handles the "bluetooth status" command |
| 70 | +func (p *Processor) handleBluetoothStatus(input string) (*core.Command, error) { |
| 71 | + return &core.Command{ |
| 72 | + Type: core.CommandTypeConnectivity, |
| 73 | + Action: "bluetooth-status", |
| 74 | + Target: "", |
| 75 | + RawInput: input, |
| 76 | + }, nil |
| 77 | +} |
| 78 | + |
| 79 | +// handleEnableAirplaneMode handles the "enable airplane mode" command |
| 80 | +func (p *Processor) handleEnableAirplaneMode(input string) (*core.Command, error) { |
| 81 | + return &core.Command{ |
| 82 | + Type: core.CommandTypeConnectivity, |
| 83 | + Action: "enable-airplane-mode", |
| 84 | + Target: "", |
| 85 | + RawInput: input, |
| 86 | + }, nil |
| 87 | +} |
| 88 | + |
| 89 | +// handleDisableAirplaneMode handles the "disable airplane mode" command |
| 90 | +func (p *Processor) handleDisableAirplaneMode(input string) (*core.Command, error) { |
| 91 | + return &core.Command{ |
| 92 | + Type: core.CommandTypeConnectivity, |
| 93 | + Action: "disable-airplane-mode", |
| 94 | + Target: "", |
| 95 | + RawInput: input, |
| 96 | + }, nil |
| 97 | +} |
| 98 | + |
| 99 | +// handleAirplaneModeStatus handles the "airplane mode status" command |
| 100 | +func (p *Processor) handleAirplaneModeStatus(input string) (*core.Command, error) { |
| 101 | + return &core.Command{ |
| 102 | + Type: core.CommandTypeConnectivity, |
| 103 | + Action: "airplane-mode-status", |
| 104 | + Target: "", |
| 105 | + RawInput: input, |
| 106 | + }, nil |
| 107 | +} |
| 108 | + |
| 109 | +// handleEnableHotspot handles the "enable hotspot" command |
| 110 | +func (p *Processor) handleEnableHotspot(input string) (*core.Command, error) { |
| 111 | + // Extract SSID and password from the input |
| 112 | + ssid := "" |
| 113 | + password := "" |
| 114 | + |
| 115 | + // Look for SSID in the input |
| 116 | + if strings.Contains(input, "ssid") || strings.Contains(input, "name") { |
| 117 | + parts := strings.Split(input, "ssid") |
| 118 | + if len(parts) > 1 { |
| 119 | + ssidPart := parts[1] |
| 120 | + ssidPart = strings.TrimSpace(ssidPart) |
| 121 | + if strings.HasPrefix(ssidPart, ":") || strings.HasPrefix(ssidPart, "=") { |
| 122 | + ssidPart = strings.TrimSpace(strings.TrimPrefix(strings.TrimPrefix(ssidPart, ":"), "=")) |
| 123 | + } |
| 124 | + // Extract the SSID (may be in quotes) |
| 125 | + if strings.Contains(ssidPart, "'") { |
| 126 | + ssidParts := strings.Split(ssidPart, "'") |
| 127 | + if len(ssidParts) > 1 { |
| 128 | + ssid = ssidParts[1] |
| 129 | + } |
| 130 | + } else if strings.Contains(ssidPart, "\"") { |
| 131 | + ssidParts := strings.Split(ssidPart, "\"") |
| 132 | + if len(ssidParts) > 1 { |
| 133 | + ssid = ssidParts[1] |
| 134 | + } |
| 135 | + } else { |
| 136 | + // Take the first word as the SSID |
| 137 | + words := strings.Fields(ssidPart) |
| 138 | + if len(words) > 0 { |
| 139 | + ssid = words[0] |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + } else if strings.Contains(input, "name") { |
| 144 | + parts := strings.Split(input, "name") |
| 145 | + if len(parts) > 1 { |
| 146 | + namePart := parts[1] |
| 147 | + namePart = strings.TrimSpace(namePart) |
| 148 | + if strings.HasPrefix(namePart, ":") || strings.HasPrefix(namePart, "=") { |
| 149 | + namePart = strings.TrimSpace(strings.TrimPrefix(strings.TrimPrefix(namePart, ":"), "=")) |
| 150 | + } |
| 151 | + // Extract the name (may be in quotes) |
| 152 | + if strings.Contains(namePart, "'") { |
| 153 | + nameParts := strings.Split(namePart, "'") |
| 154 | + if len(nameParts) > 1 { |
| 155 | + ssid = nameParts[1] |
| 156 | + } |
| 157 | + } else if strings.Contains(namePart, "\"") { |
| 158 | + nameParts := strings.Split(namePart, "\"") |
| 159 | + if len(nameParts) > 1 { |
| 160 | + ssid = nameParts[1] |
| 161 | + } |
| 162 | + } else { |
| 163 | + // Take the first word as the name |
| 164 | + words := strings.Fields(namePart) |
| 165 | + if len(words) > 0 { |
| 166 | + ssid = words[0] |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + // Look for password in the input |
| 173 | + if strings.Contains(input, "password") { |
| 174 | + parts := strings.Split(input, "password") |
| 175 | + if len(parts) > 1 { |
| 176 | + passwordPart := parts[1] |
| 177 | + passwordPart = strings.TrimSpace(passwordPart) |
| 178 | + if strings.HasPrefix(passwordPart, ":") || strings.HasPrefix(passwordPart, "=") { |
| 179 | + passwordPart = strings.TrimSpace(strings.TrimPrefix(strings.TrimPrefix(passwordPart, ":"), "=")) |
| 180 | + } |
| 181 | + // Extract the password (may be in quotes) |
| 182 | + if strings.Contains(passwordPart, "'") { |
| 183 | + passwordParts := strings.Split(passwordPart, "'") |
| 184 | + if len(passwordParts) > 1 { |
| 185 | + password = passwordParts[1] |
| 186 | + } |
| 187 | + } else if strings.Contains(passwordPart, "\"") { |
| 188 | + passwordParts := strings.Split(passwordPart, "\"") |
| 189 | + if len(passwordParts) > 1 { |
| 190 | + password = passwordParts[1] |
| 191 | + } |
| 192 | + } else { |
| 193 | + // Take the first word as the password |
| 194 | + words := strings.Fields(passwordPart) |
| 195 | + if len(words) > 0 { |
| 196 | + password = words[0] |
| 197 | + } |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + // If no SSID was found, use a default one |
| 203 | + if ssid == "" { |
| 204 | + ssid = "LumoHotspot" |
| 205 | + } |
| 206 | + |
| 207 | + // Create the command |
| 208 | + cmd := &core.Command{ |
| 209 | + Type: core.CommandTypeConnectivity, |
| 210 | + Action: "enable-hotspot", |
| 211 | + Target: ssid, |
| 212 | + Arguments: make(map[string]interface{}), |
| 213 | + RawInput: input, |
| 214 | + } |
| 215 | + |
| 216 | + // Add password if provided |
| 217 | + if password != "" { |
| 218 | + cmd.Arguments["password"] = password |
| 219 | + } |
| 220 | + |
| 221 | + return cmd, nil |
| 222 | +} |
| 223 | + |
| 224 | +// handleDisableHotspot handles the "disable hotspot" command |
| 225 | +func (p *Processor) handleDisableHotspot(input string) (*core.Command, error) { |
| 226 | + return &core.Command{ |
| 227 | + Type: core.CommandTypeConnectivity, |
| 228 | + Action: "disable-hotspot", |
| 229 | + Target: "", |
| 230 | + RawInput: input, |
| 231 | + }, nil |
| 232 | +} |
| 233 | + |
| 234 | +// handleHotspotStatus handles the "hotspot status" command |
| 235 | +func (p *Processor) handleHotspotStatus(input string) (*core.Command, error) { |
| 236 | + return &core.Command{ |
| 237 | + Type: core.CommandTypeConnectivity, |
| 238 | + Action: "hotspot-status", |
| 239 | + Target: "", |
| 240 | + RawInput: input, |
| 241 | + }, nil |
| 242 | +} |
0 commit comments