投币任务. @author @JunzhouLiu @Kurenai @since 2020-11-22 5:28
| 23 | * @since 2020-11-22 5:28 |
| 24 | */ |
| 25 | @SuppressWarnings("StringConcatenationArgumentToLogCall") |
| 26 | @Slf4j |
| 27 | public class CoinAdd implements Task { |
| 28 | |
| 29 | /** |
| 30 | * 检查是否投币. |
| 31 | * |
| 32 | * @param bvid av号 |
| 33 | * @return 返回是否投过硬币了. true没有投币,false投过了。 |
| 34 | */ |
| 35 | static boolean isCoinAdded(String bvid) { |
| 36 | String urlParam = "?bvid=" + bvid; |
| 37 | JsonObject result = HttpUtils.doGet(ApiList.IS_COIN + urlParam); |
| 38 | |
| 39 | int multiply = result.getAsJsonObject("data").get("multiply").getAsInt(); |
| 40 | return multiply <= 0; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void run() { |
| 45 | //投币最多操作数 解决csrf校验失败时死循环的问题 |
| 46 | int addCoinOperateCount = 0; |
| 47 | //安全检查,最多投币数 |
| 48 | final int maxNumberOfCoins = 5; |
| 49 | //获取自定义配置投币数 配置写在src/main/resources/taskConfig.json中 |
| 50 | int setCoin = ConfigLoader.helperConfig.getTaskConfig().getNumberOfCoins(); |
| 51 | // 预留硬币数 |
| 52 | int reserveCoins = ConfigLoader.helperConfig.getTaskConfig().getReserveCoins(); |
| 53 | |
| 54 | //已投的硬币 |
| 55 | int useCoin = TaskInfoHolder.expConfirm(); |
| 56 | //投币策略 |
| 57 | int coinAddPriority = ConfigLoader.helperConfig.getTaskConfig().getCoinAddPriority(); |
| 58 | |
| 59 | if (setCoin > maxNumberOfCoins) { |
| 60 | log.info("自定义投币数为: {}枚,为保护你的资产,自定义投币数重置为: " + maxNumberOfCoins + "枚", setCoin); |
| 61 | setCoin = maxNumberOfCoins; |
| 62 | } |
| 63 | |
| 64 | log.info("自定义投币数为: {}枚,程序执行前已投: {}枚", setCoin, useCoin); |
| 65 | |
| 66 | //调整投币数 设置投币数-已经投过的硬币数 |
| 67 | int needCoins = setCoin - useCoin; |
| 68 | |
| 69 | //投币前硬币余额 |
| 70 | Double beforeAddCoinBalance = OftenApi.getCoinBalance(); |
| 71 | int coinBalance = (int) Math.floor(beforeAddCoinBalance); |
| 72 | |
| 73 | |
| 74 | if (needCoins <= 0) { |
| 75 | log.info("已完成设定的投币任务,今日无需再投币了"); |
| 76 | return; |
| 77 | } else { |
| 78 | log.info("投币数调整为: {}枚", needCoins); |
| 79 | //投币数大于余额时,按余额投 |
| 80 | if (needCoins > coinBalance) { |
| 81 | log.info("完成今日设定投币任务还需要投: {}枚硬币,但是余额只有: {}", needCoins, beforeAddCoinBalance); |
| 82 | log.info("投币数调整为: {}", coinBalance); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…