onAutoComplete contributes completions for the storage command.
(req suggestions.AutoCompleteRequest)
| 189 | |
| 190 | // onAutoComplete contributes completions for the storage command. |
| 191 | func (m *StorageModule) onAutoComplete(req suggestions.AutoCompleteRequest) suggestions.AutoCompleteRequest { |
| 192 | if req.Cmd != `storage` { |
| 193 | return req |
| 194 | } |
| 195 | |
| 196 | user := users.GetByUserId(req.UserId) |
| 197 | if user == nil { |
| 198 | return req |
| 199 | } |
| 200 | |
| 201 | parts := req.Parts |
| 202 | targetName := strings.ToLower(strings.Join(parts[1:], ` `)) |
| 203 | targetNameLen := len(targetName) |
| 204 | |
| 205 | for _, opt := range []string{`add`, `remove`} { |
| 206 | if strings.HasPrefix(opt, targetName) { |
| 207 | req.Results = append(req.Results, opt[targetNameLen:]) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if len(parts) >= 3 { |
| 212 | subCmd := strings.ToLower(parts[1]) |
| 213 | itemSearch := strings.ToLower(strings.Join(parts[2:], ` `)) |
| 214 | itemSearchLen := len(itemSearch) |
| 215 | if subCmd == `add` { |
| 216 | for _, item := range user.Character.GetAllBackpackItems() { |
| 217 | iSpec := item.GetSpec() |
| 218 | if strings.HasPrefix(strings.ToLower(iSpec.Name), itemSearch) { |
| 219 | req.Results = append(req.Results, iSpec.Name[itemSearchLen:]) |
| 220 | } |
| 221 | } |
| 222 | } else if subCmd == `remove` { |
| 223 | for _, item := range m.GetStorageItems(user.UserId) { |
| 224 | iSpec := item.GetSpec() |
| 225 | if strings.HasPrefix(strings.ToLower(iSpec.Name), itemSearch) { |
| 226 | req.Results = append(req.Results, iSpec.Name[itemSearchLen:]) |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return req |
| 233 | } |
| 234 | |
| 235 | // onRoomLook injects a storage alert when the room has the storage tag. |
| 236 | func (m *StorageModule) onRoomLook(d rooms.RoomTemplateDetails) rooms.RoomTemplateDetails { |
nothing calls this directly
no test coverage detected