thirdy / durian

Path of Exile Items watcher
http://thirdy.github.io/durian/
GNU General Public License v2.0
35 stars 10 forks source link

Further improvements to the WTB message #80

Closed kyri0 closed 8 years ago

kyri0 commented 8 years ago

I don't know yet how to do this on my own, so i'm asking your guys help.

I'd like to the WTB message to have more 'ifs'. For example, it would only show the 'listed for x' if it had an actual buyout. Another thing I wanted it to show as an 'if' would be the quality and the lvl, in case it was a gem.

My current WTB message is the following:

function setupWtbMessage(item) {
    // Look at class SearchResultItem in file SearchPageScraper.java
    // for more variable to use
    // vanilla js doesn't have format function :(
    var wtbTemplate = '@%s Heyo! I\'d like to buy your %s, quality %s, level %s listed for %s in %s'
    var buyout = item.buyout
    if (item.guildItem()) {
        buyout = java.lang.String.format(
            "%s (less %s guildmate discount)",
            item.buyout,
            item.guildDiscount()) 
    }
    var wtb = java.lang.String.format(
        wtbTemplate,
        item.ign, 
        item.name,  
        item.quality,
        item.level,
        buyout,
        item.league
    )
    item.wtb(wtb)
zocke1r commented 8 years ago

Sadly there is no way, at least not one i could find, to easily determine the type of an item, and for the buyout the only solution i can come up with is

function setupWtbMessage(item) {
    // Look at class SearchResultItem in file SearchPageScraper.java
    // for more variable to use
    // vanilla js doesn't have format function :(
    if(item.buyout ==  ""){
        var wtbTemplate = '@%s Heyo! I\'d like to buy your %s, quality %s, level %s listed in %s'
        var wtb = java.lang.String.format(
            wtbTemplate,
            item.ign, 
            item.name,  
            item.quality,
            item.level,
            item.league
        )
    }else{
        var wtbTemplate = '@%s Heyo! I\'d like to buy your %s, quality %s, level %s listed for %s in %s'
        var buyout = item.buyout
        if (item.guildItem()) {
            buyout = java.lang.String.format(
                "%s (less %s guildmate discount)",
                item.buyout,
                item.guildDiscount()) 
        }
        var wtb = java.lang.String.format(
            wtbTemplate,
            item.ign, 
            item.name,  
            item.quality,
            item.level,
            buyout,
            item.league
        )
    }
    item.wtb(wtb)
}

unless there is away to use conditions inside a function parameters this the only way to do the optional buyout part

kyri0 commented 8 years ago

Thanks, man!

zocke1r commented 8 years ago

not a problem and if you can come up with a creative way of identifying gems , please share

zocke1r commented 8 years ago

i think i found a way

kyri0 commented 8 years ago

The only way I can think of is by item type, or simply making it in a way that it would always show the quality and lvl of any item.

zocke1r commented 8 years ago

the way i found uses a unique property of gems and maps alike, they have a level listed on poe.trade, where as every other item does not

kyri0 commented 8 years ago

Okay, as soon as you figure this out, i'll merge it to the master branch.

zocke1r commented 8 years ago

is there any map that does not include the name map in it?

zocke1r commented 8 years ago

so after first believing i was going mad, because the function behaved in no way like it should, and i figured out that i somehow managed to duplicate the function, confirming that every map includes the Term "Map" in its name and that only maps and gems have a lvl listed on poe.trade.

I can now proudly present the function you asked for with no exceptions:

``` function setupWtbMessage(item) { // Look at class SearchResultItem in file SearchPageScraper.java // for more variable to use // vanilla js doesn't have format function :( if(item.buyout == ""){ var wtbTemplate = '@%s Heyo! I\'d like to buy your %s, quality %s, level %s listed in %s' var name = item.name; if(item.level != "" && (item.name.indexOf("Map") == -1)){ name = java.lang.String.format( "%s, quality %s, level %s", item.name, item.quality, item.level) } var wtb = java.lang.String.format( wtbTemplate, item.ign, name, item.league ) }else{ var wtbTemplate = '@%s Heyo! I\'d like to buy your %s listed for %s in %s' var buyout = item.buyout if (item.guildItem()) { buyout = java.lang.String.format( "%s (less %s guildmate discount)", item.buyout, item.guildDiscount()) } var name = item.name; if(item.level != "" && (item.name.indexOf("Map") == -1)){ name = java.lang.String.format( "%s, quality %s, level %s", item.name, item.quality, item.level) } var wtb = java.lang.String.format( wtbTemplate, item.ign, name, buyout, item.league ) } item.wtb(wtb) } ``` and now it is also a pull request #83
kyri0 commented 8 years ago

Yes, every map has 'map' in its name.

So, I tried it out here, but when I look for a gem, it gives me this error: EDIT:Actually it only occurs if I try to search for glvl and quality along with the name of gem. Ex.: bladevortex q20 glvl20

An error has occurred in thread #32: SwingWorker-pool-3-thread-7; please find details below:

java.util.MissingFormatArgumentException: Format specifier '%s'
    at java.util.Formatter.format(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at java.lang.String.format(Unknown Source)
    at jdk.nashorn.internal.scripts.Script$Recompilation$51$592A$\^eval\_.setupWtbMessage(<eval>:43)
    at jdk.nashorn.internal.scripts.Script$Recompilation$50$276AA$\^eval\_.process(<eval>:24)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:644)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
    at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383)
    at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
    at qic.util.FmJS.process(FmJS.java:58)
    at qic.Main.processLine(Main.java:172)
    at qic.ui.ManualPanel.runQuery(ManualPanel.java:228)
    at qic.ui.ManualPanel.lambda$null$53(ManualPanel.java:149)
    at qic.ui.extra.Worker.doInBackground(Worker.java:21)
    at javax.swing.SwingWorker$1.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at javax.swing.SwingWorker.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
zocke1r commented 8 years ago

okay, just tried your example and i do not get any errors with the version i posted here, mind posting your function maybe there is a problem with your version

kyri0 commented 8 years ago

I used the one you posted on this thread

zocke1r commented 8 years ago

found the problem, and also why you could find it and i could not first, the problem i forgot to update the WTB template for items with no buyout. Second because I always exclude items without buyout it did not happen for me updated the version the the pull request

kyri0 commented 8 years ago

Oh, ok, so, what's the correct one?

zocke1r commented 8 years ago

var wtbTemplate = '@%s Heyo! I\'d like to buy your %s listed in %s' is the correct version

kyri0 commented 8 years ago

Perfect, works now.

kyri0 commented 8 years ago

I'll just change the default message back to the one used by poe.trade, thanks a lot!