Add useRandomMenuEntryWithTextContaining in AppFrameWork?

Here is my warpToMiningSite function using personal locations

warpToMiningSite : ReadingFromGameClient -> DecisionPathNode
warpToMiningSite readingFromGameClient =
    readingFromGameClient
        |> useContextMenuCascadeOnListSurroundingsButton
            (useMenuEntryWithTextContaining "locations"
                (useRandomMenuEntry
                        (useMenuEntryWithTextContaining "within 0 m" menuCascadeCompleted)
                )
            )

image

There is no way to useRandomEntryWithTextContaining so the bot sometimes try to click on Personal Locations or the folder. It’s not a problem at all but it made me think about trying to create something like this. This obviously does not work in this project but by itself it works well

useRandomMenuEntryWithTextContaining : String -> UseContextMenuCascadeNode -> UseContextMenuCascadeNode
useRandomMenuEntryWithTextContaining textToSearch =
    useMenuEntryInLastContextMenuInCascade
        { describeChoice = "with text containing '" ++ textToSearch ++ "'"
        , chooseEntry =
            (Random.initialSeed (getEntropyIntFromReadingFromGameClient readingFromGameClient))
                |> Random.step (Random.List.shuffle ((List.filter (.text >> String.toLower >> String.contains (textToSearch |> String.toLower))) |> List.filter (String.contains textToSearch )))
                |> Tuple.first
                |> List.head
        }

The current implementation of useEntryWithTextContaining does not allow for randomness. Always chooses the top of the list with List.head
https://github.com/Viir/bots/blob/main/implement/applications/eve-online/eve-online-mining-bot/EveOnline/AppFramework.elm#L1167-L1174

I’d love to be able to add this by myself but I couldn’t figure out how to make it compatible with all the different types. .text is really throwing a wrench in my method of doing it.

In the examples I found this useRandomMenuEntry function. It contains some pieces that we can reuse to build your function:

Looking closer, we can reuse almost the whole function, just need to add an additional filter to remove list items that do not match your constraint.
I added the List.filter copied from useMenuEntryWithTextContaining, which seems enough to complete your function:

useRandomMenuEntryWithTextContaining : String -> EveOnline.AppFramework.UseContextMenuCascadeNode -> EveOnline.AppFramework.UseContextMenuCascadeNode
useRandomMenuEntryWithTextContaining textToSearch =
    EveOnline.AppFramework.MenuEntryWithCustomChoice
        { describeChoice = "random entry with text containing '" ++ textToSearch ++ "'"
        , chooseEntry =
            \readingFromGameClient ->
                readingFromGameClient
                    |> EveOnline.AppFramework.pickEntryFromLastContextMenuInCascade
                        (List.filter (.text >> String.toLower >> String.contains (textToSearch |> String.toLower))
                            >> Common.Basics.listElementAtWrappedIndex (getEntropyIntFromReadingFromGameClient readingFromGameClient)
                        )
        }
1 Like

I tried recycling both of these functions but I could not figure out how to make them work together.

Thanks