-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Federico Morreale <frc.morreale@gmail.com>
- Loading branch information
Showing
10 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.bot.commands; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.bot.commands.base.Command; | ||
import org.bot.operations.Operations; | ||
import org.bot.operations.OperationsDispatcher; | ||
import org.bot.utils.formatters.DepositDecorator; | ||
import org.bot.utils.formatters.ToBoldDecorator; | ||
import org.bot.visitor.CommandVisitor; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; | ||
|
||
import java.util.Map; | ||
|
||
|
||
@Slf4j | ||
public class DepositCommand implements Command { | ||
|
||
public DepositCommand() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public void execute(Update update) throws TelegramApiException { | ||
String[] parts = update.getMessage().getText().split(" "); | ||
String platform = parts[1].toLowerCase().trim(); | ||
String ticker = parts[2].toUpperCase().trim(); | ||
String chain = parts.length == 4 ? parts[3].toUpperCase().trim() : null; | ||
|
||
Operations operations = OperationsDispatcher.getInstance().getOperations(platform); | ||
Map<String, String> depositAddresses = operations.deposit(ticker, chain); | ||
|
||
sendText(update.getMessage().getChatId(), "Deposit addresses for " + new ToBoldDecorator(ticker) + ":\n" + new DepositDecorator(depositAddresses)); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "/deposit"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "<platform> <ticker> <chain?> to get a list of deposit addresses. Specify the chain to create the specific address for that chain, if not present in the list"; | ||
} | ||
|
||
@Override | ||
public void accept(CommandVisitor visitor) { | ||
visitor.visitDepositCommand(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/org/bot/utils/formatters/DepositDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.bot.utils.formatters; | ||
|
||
import java.util.Map; | ||
|
||
public class DepositDecorator extends MapDecorator<String, String> { | ||
|
||
public DepositDecorator(Map<String, String> decoratedMap) { | ||
super(decoratedMap); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
for (Map.Entry<String, String> entry : decoratedMap.entrySet()) { | ||
sb.append(new ToBoldDecorator(entry.getKey())); | ||
sb.append(": "); | ||
sb.append(new ToCodeDecorator(entry.getValue())); | ||
sb.append("\n"); | ||
} | ||
sb.deleteCharAt(sb.length() - 1); | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters