Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. const DiscordRPC = require("discord-rpc");
  2. const fs = require('fs');
  3.  
  4. const ClientId = '513142289510694912';
  5.  
  6. DiscordRPC.register(ClientId);
  7.  
  8. const rpc = new DiscordRPC.Client({ transport: 'ipc' });
  9.  
  10. let currentMeters = 1700;
  11. let currentLevel = 2;
  12. let currentState = "Forest of Temptation"
  13.  
  14. function saveState() {
  15. fs.writeFile("state.dat", currentMeters.toString(), function(err) {
  16. if(err) {
  17. return console.log(err);
  18. }
  19. });
  20. }
  21.  
  22. function loadState() {
  23. try {
  24. loadState();
  25. console.log("loaded state")
  26. }
  27. catch (error) {
  28. console.log("no saved state, starting from beginning");
  29. }
  30. fs.readFile('state.dat', 'utf8', function(err, contents) {
  31. currentMeters = parseInt(contents);
  32. });
  33. }
  34.  
  35. function numberWithCommas(x) {
  36. return Math.round(x).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  37. }
  38.  
  39. function setStates() {
  40. if (1351 < currentMeters < 2600) {
  41. currentLevel = 2;
  42. currentState = "Forest of Temptation";
  43. }
  44. else if (2601 < currentMeters < 7000) {
  45. currentLevel = 3;
  46. currentState = "Great Fault";
  47. }
  48. else if (7001 < currentMeters < 12000) {
  49. currentLevel = 4;
  50. currentState = "The Goblets of Giants";
  51. }
  52. else if (12001 < currentMeters < 13000) {
  53. currentLevel = 5;
  54. currentState = "Sea of Corpses";
  55. }
  56. else if (13001 < currentMeters < 15500) {
  57. currentLevel = 6;
  58. currentState = "The Capital of the Unreturned";
  59. }
  60. else if (15501 < currentMeters < 20000) {
  61. currentLevel = 7;
  62. currentState = "The Final Maelstrom";
  63. }
  64. else {
  65. currentLevel = 8;
  66. currentState = "The Deepest Point";
  67. }
  68. }
  69.  
  70. function doRPC() {
  71. setStates();
  72. rpc.setActivity({
  73. details: "Level " + currentLevel + " | " + numberWithCommas(currentMeters) + " meters",
  74. state: currentState,
  75. largeImageKey: 'made-in-abyss-riko',
  76. largeImageText: 'Riko',
  77. smallImageKey: 'white-whitle-large',
  78. smallImageText: 'White Whistle',
  79. instance: true,
  80. });
  81. }
  82.  
  83. rpc.on('ready', () => {
  84. console.log("ready");
  85. try {
  86. loadState();
  87. }
  88. catch (error) {
  89. console.log("no saved state, starting from beginning");
  90. }
  91. doRPC();
  92. });
  93.  
  94. console.log("logging in");
  95. rpc.login(ClientId).catch(console.error);
  96. console.log("logged in");
  97.  
  98.  
  99. setInterval(() => {
  100. console.log("updating rpc...")
  101. currentMeters += (Math.random() * 101);
  102. doRPC();
  103. console.log("updated rpc! | Level " + currentLevel + " | " + numberWithCommas(currentMeters) + " meters");
  104. saveState();
  105. }, 300000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement