ge-ku / AutoJoin-for-SteamGifts

Automatically enters giveaways from Steamgifts.com
https://chrome.google.com/webstore/detail/autojoin-for-steamgifts/bchhlccjhoedhhegglilngpbnldfcidc
GNU General Public License v2.0
105 stars 22 forks source link

Auto redeem won keys on Steam #37

Closed PredatorIWD closed 4 years ago

PredatorIWD commented 5 years ago

As requested at #36, I've added a basic system to redeem won keys instantly on Steam in the background.

I assume it would be best for this to be optional at first, and have a simple option added to the main options page so users can set their preferences.

The function itself should be integrated into the chrome.alarms system since the extension is using that for most things it has to check instead of the current simple setInterval function. It would also be good to notify the user when the key is redeemed or show the reason why it failed if it did so.

I ported this from my own extension where I had such as system, but, like I wrote in the code itself, you should review the code below and adjust it and integrate it to fit the current style and workflow of the extension (I recommend you to use the messages I passed as arguments to the notifySteamCodeResponse function because they are displayed nicely and inform the user of all the possible errors that can occur which I also added in the code below).

This will work as expected in most cases, but I assume it would also be good to add support in the small cases when the won games are given as links to third party sites from which you get the keys instead of them being given directly to you, and the possible scenario that the key won't be given so it can be marked as not received after the one week period. Even the possibility that if the key is duplicate to auto inform the user that he should contact the giveaway owner about the said problem.

This is a very rough addition of the requested feature so if there are any questions or suggestions, feel free to leave a message or contact me personally about it.

ge-ku commented 5 years ago

Looks good! I'll try to win something to test it, I'm curious to see real response to https://www.steamgifts.com/ajax.php with do: "view_key". Or does it work for already viewed keys (can't test it right now)? Maybe we can grab a key from it without doing JSON.stringify?

And yes, we have to use alarms system so extension doesn't stay in memory all the time.

PredatorIWD commented 5 years ago

@ge-ku The request does works on already viewed keys as it seems. As for the JSON.stringify, I copied the long message parse method from an old userscript I had that I knew worked, but it can be made a bit simpler, of course.

PredatorIWD commented 5 years ago

@ge-ku Any news regarding the implementation of this? I've also just won a game on Steamgifts for which the user provided me with a duplicate key and the algorithm behaved correctly and didn't mark it as received like it did all the others that actually did get redeemed directly on Steam moments after a key was received.

So it's all working as intended and the only thing needed is to convert it to the necessary code style and then integrate it into the extensions alarm system instead of using a very simple setInterval.

Feel free to take your time, I just wanted to let you know that it has been working without any problems since I implemented it myself and I think everyone else using it here would benefit greatly with such a useful feature. Because at the end of the day, it all is about full background automation. Cheers.

ge-ku commented 4 years ago

I added it with almost no changes, instead of setInterval it will be called when extension detects a win, added option to enable/disable (disabled by default). Can't test on real case, hopefully works.