ofekmiz / Habitica-Pomodoro-SiteKeeper

Chrome Extension for Habitica that charges you gp for visiting sites, including a Pomodoro Timer
MIT License
73 stars 9 forks source link

Tasks are inconsistent, here's pseudocode for a workaround involving todos. (Drawback: takes 60 seconds) #110

Open IanNeer opened 2 years ago

IanNeer commented 2 years ago

Hey, thanks for making this web extension, it's great. I've been getting a lot of amusement out of it.

Habitica tasks offer declining rewards. Each tomato rewards less. There are also penalties for many tomatoes. I do not know why the Habitica people did this, but here's a fix, pseudocode is from google scripts (script.google.com). I'm sure that you have already considered this solution, but I appreciate that you took the time to read this anyway.

function doGet(e) { const Habitica_API_Token = "api-token-here"; const Habitica_User_ID = "user-id-here"; const Habitica_Author_Script = Habitica_User_ID + "-" + "Gold_Rewards_Points_Todo";

const HEADERS = { "x-client": Habitica_Author_Script, "x-api-user": Habitica_User_ID, "x-api-key": Habitica_API_Token } //Create the gold task Make an aliased gold todo var payload = { "text": "Automated Gold Reward", "type": "todo", "alias": "goldrewards", //alias "priority": 2 } var params = { "method": "post", "headers": HEADERS, "payload": payload } var url = "https://habitica.com/api/v3/tasks/user"; UrlFetchApp.fetch(url, params);

//Sleep 30 seconds to comply with API guidance Wait for API Utilities.sleep(30*1000);

//Score the gold task Score the aliased Todo. var params = { "method": "post", "headers": HEADERS, } var url = "https://habitica.com/api/v3/tasks/goldrewards/score/up"; //alias used earlier UrlFetchApp.fetch(url, params);

//Sleep 30 seconds to comply with API guidance Wait for API Utilities.sleep(30*1000);

//Delete the gold task Clear the todos so we can use the alias again next time var params = { "method": "post", "headers": HEADERS, } var url = "https://habitica.com/api/v3/tasks/ClearCompletedTodos"; UrlFetchApp.fetch(url, params);

textOutput = ContentService.createTextOutput("Alright, I created the task, scored it, and deleted it."); return textOutput; }

You can then subtract the fractional part of the todo reward using a reward task, but the fractional part appears to be level-dependent so I have not tried. If you want to run this, paste into google scripts, add your tokens, deploy as a web app, and go to the /exec link.