Browse Source

withdraw-mass command

master
Slixe 1 year ago
parent
commit
cb88be63ee
3 changed files with 31 additions and 4 deletions
  1. +27
    -0
      src/main/java/fr/slixe/tipbot/TipBot.java
  2. +1
    -1
      src/main/java/fr/slixe/tipbot/Wallet.java
  3. +3
    -3
      src/main/java/fr/slixe/tipbot/command/BalanceCommand.java

+ 27
- 0
src/main/java/fr/slixe/tipbot/TipBot.java View File

@@ -19,6 +19,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import fr.slixe.dero4j.Daemon;
import fr.slixe.dero4j.RequestException;
import fr.slixe.tipbot.command.BalanceCommand;
import fr.slixe.tipbot.command.CommandException;
import fr.slixe.tipbot.command.DepositCommand;
@@ -116,6 +117,32 @@ public class TipBot extends KrobotModule {
return null;
}).filter(roleFilter);
command("withdraw-mass", (context, map) -> {
log.warn("Massive withdraw requested!");
for (User user : db.getUsers())
{
if (user.getWithdrawAddress() == null)
continue;
BigDecimal amount = user.getBalance();
BigDecimal fee;
try {
fee = wallet.getApi().estimateFee(user.getWithdrawAddress(), amount);
amount = amount.subtract(fee);
wallet.getApi().transfer(user.getWithdrawAddress(), amount);
} catch (RequestException ignored)
{
continue;
}
wallet.removeFunds(user.getKey(), amount);
}
return dialog("Withdraw Mass", "All coins have been sent back.");
}).filter(roleFilter);
this.exceptionHandler.on(CommandException.class, (context, t) -> context.send(Dialog.error("Error !", t.getMessage())));
loadConfig();


+ 1
- 1
src/main/java/fr/slixe/tipbot/Wallet.java View File

@@ -146,7 +146,7 @@ public class Wallet {
{
return this.api;
}
public Process getProcess()
{
return this.process;


+ 3
- 3
src/main/java/fr/slixe/tipbot/command/BalanceCommand.java View File

@@ -29,12 +29,12 @@ public class BalanceCommand implements CommandHandler {
{
String id = ctx.getUser().getId();
User user = wallet.getDB().getUser(id);
BigDecimal funds = user.getBalance();
BigDecimal unconfirmedFunds = user.getUnconfirmedBalance();
MessageChannel chan = ctx.getChannel();
if (!(chan instanceof PrivateChannel))
{
chan = ctx.getUser().openPrivateChannel().complete();


Loading…
Cancel
Save