randomWeek2.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { forEachAsync } from '../../utils'
  2. import { DBClient } from '../../singletons'
  3. import { InitiaClient } from '../../InitiaClient'
  4. async function startCheck(concurrency) {
  5. const accountsRaw = await DBClient.instance.randomTask2.findMany({
  6. where: {
  7. finish: 0,
  8. },
  9. take: 10000,
  10. })
  11. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  12. console.log(`${index}/${accountsRaw.length}: processing ${account.address}`)
  13. console.log(account.id)
  14. try {
  15. // await faucetAccount(account.address)
  16. const notDone = []
  17. if (account.task1 === 0) {
  18. notDone.push(1)
  19. }
  20. if (account.task2 === 0) {
  21. notDone.push(2)
  22. }
  23. if (account.task3 === 0) {
  24. notDone.push(3)
  25. }
  26. if (account.task4 === 0) {
  27. notDone.push(4)
  28. }
  29. if (account.task5 === 0) {
  30. notDone.push(5)
  31. }
  32. if (account.task6 === 0) {
  33. notDone.push(6)
  34. }
  35. console.log(`notDone`, notDone)
  36. if (notDone.length === 0) {
  37. await DBClient.instance.randomTask2.update({
  38. where: { id: account.id },
  39. data: { finish: 1 },
  40. })
  41. }
  42. const randomPick = notDone[Math.floor(Math.random() * notDone.length)]
  43. const client = new InitiaClient(account.mnemonic, true)
  44. if (randomPick === 2) {
  45. console.log(`task2`)
  46. const bool = await client.week2Task2(account.toAddress)
  47. console.log(bool)
  48. if (bool == `done`) {
  49. await DBClient.instance.randomTask2.update({
  50. where: { id: account.id },
  51. data: { task2: 1 },
  52. })
  53. }
  54. } else if (randomPick === 3) {
  55. console.log(`task3`)
  56. await client.drawFood()
  57. const bool = await client.feedJennie()
  58. console.log(bool)
  59. if (bool == `done`) {
  60. await DBClient.instance.randomTask2.update({
  61. where: { id: account.id },
  62. data: { task3: 1 },
  63. })
  64. }
  65. } else if (randomPick === 4) {
  66. console.log(`task4`)
  67. const bool = await client.stakeSingle()
  68. if (bool == `done`) {
  69. await DBClient.instance.randomTask2.update({
  70. where: { id: account.id },
  71. data: { task4: 1 },
  72. })
  73. }
  74. } else if (randomPick === 5) {
  75. console.log(`task5`)
  76. const bool = await client.stakeTiaSingle()
  77. console.log(bool)
  78. if (bool == `done`) {
  79. await DBClient.instance.randomTask2.update({
  80. where: { id: account.id },
  81. data: { task5: 1 },
  82. })
  83. }
  84. } else if (randomPick === 6) {
  85. console.log(`task6`)
  86. const bool = await client.stakeEthSingle()
  87. if (bool == `done`) {
  88. await DBClient.instance.randomTask2.update({
  89. where: { id: account.id },
  90. data: { task6: 1 },
  91. })
  92. }
  93. } else if (randomPick === 1) {
  94. console.log(`task6`)
  95. const bool = await client.claimableXp()
  96. if (bool == `done`) {
  97. await DBClient.instance.randomTask2.update({
  98. where: { id: account.id },
  99. data: { task1: 1 },
  100. })
  101. }
  102. }
  103. } catch (e) {
  104. console.log(e.message)
  105. return
  106. // await DBClient.instance.account.update({
  107. // where: { id: account.id },
  108. // data: { status: Status.MayQueued, message: e.message },
  109. // })
  110. }
  111. })
  112. }
  113. startCheck(100)