diff --git a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java index fd4d4aae..44e99b0a 100644 --- a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java +++ b/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/AbilityBot.java @@ -102,11 +102,6 @@ public abstract class AbilityBot extends TelegramLongPollingBot { protected static final String RECOVER = "recover"; protected static final String COMMANDS = "commands"; - // Messages - // TODO replace hardcoded messages... - protected static final String RECOVERY_MESSAGE = "I am ready to receive the backup file. Please reply to this message with the backup file attached."; - protected static final String RECOVER_SUCCESS = "I have successfully recovered."; - // DB and sender protected final DBContext db; protected MessageSender sender; @@ -270,7 +265,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot { try { return getUser(username).id(); } catch (IllegalStateException ex) { - silent.send(format("Sorry, I could not find the user [%s].", username), chatId); + silent.send(getLocalizedMessage("userNotFound","", username), chatId); // TODO how to retrieve language? throw propagate(ex); } } @@ -362,7 +357,8 @@ public abstract class AbilityBot extends TelegramLongPollingBot { .locality(USER) .privacy(CREATOR) .input(0) - .action(ctx -> silent.forceReply(RECOVERY_MESSAGE, ctx.chatId())) + .action(ctx -> silent.forceReply( + getLocalizedMessage("ability.recover.message", ctx.user().locale()), ctx.chatId())) .reply(update -> { Long chatId = update.getMessage().getChatId(); String fileId = update.getMessage().getDocument().getFileId(); @@ -370,7 +366,8 @@ public abstract class AbilityBot extends TelegramLongPollingBot { try (FileReader reader = new FileReader(downloadFileWithId(fileId))) { String backupData = IOUtils.toString(reader); if (db.recover(backupData)) { - silent.send(RECOVER_SUCCESS, chatId); + silent.send(getLocalizedMessage("ability.recover.success", + AbilityUtils.getUser(update).getLanguageCode()), chatId); // TODO how to retrieve language? } else { silent.send(getLocalizedMessage("ability.recover.fail", AbilityUtils.getUser(update).getLanguageCode()), chatId); @@ -380,7 +377,7 @@ public abstract class AbilityBot extends TelegramLongPollingBot { silent.send(getLocalizedMessage("ability.recover.error", AbilityUtils.getUser(update).getLanguageCode()), chatId); } - }, MESSAGE, DOCUMENT, REPLY, isReplyTo(RECOVERY_MESSAGE)) + }, MESSAGE, DOCUMENT, REPLY, isReplyTo(getLocalizedMessage("ability.recover.success", ""))) // TODO how to retrieve language? .build(); } diff --git a/telegrambots-abilities/src/main/resources/messages.properties b/telegrambots-abilities/src/main/resources/messages.properties index 03ae86fc..efd03c44 100644 --- a/telegrambots-abilities/src/main/resources/messages.properties +++ b/telegrambots-abilities/src/main/resources/messages.properties @@ -23,3 +23,5 @@ ability.claim.claimed=You''re now my master. checkInput.fail=Sorry, this feature requires {0,number,integer} additional {1}. checkLocality.fail=Sorry, {0}-only feature. checkPrivacy.fail=Sorry, you don''t have the required access level to do that. + +userNotFound=Sorry, I could not find the user [{0}]. \ No newline at end of file diff --git a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java index b66f28ef..5dda6847 100644 --- a/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java +++ b/telegrambots-abilities/src/test/java/org/telegram/abilitybots/api/bot/AbilityBotTest.java @@ -36,8 +36,6 @@ import static org.junit.Assert.*; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; import static org.mockito.internal.verification.VerificationModeFactory.times; -import static org.telegram.abilitybots.api.bot.AbilityBot.RECOVERY_MESSAGE; -import static org.telegram.abilitybots.api.bot.AbilityBot.RECOVER_SUCCESS; import static org.telegram.abilitybots.api.bot.DefaultBot.getDefaultBuilder; import static org.telegram.abilitybots.api.db.MapDBContext.offlineInstance; import static org.telegram.abilitybots.api.objects.EndUser.endUser; @@ -49,6 +47,10 @@ import static org.telegram.abilitybots.api.objects.MessageContext.newContext; import static org.telegram.abilitybots.api.objects.Privacy.*; public class AbilityBotTest { + // Messages + protected static final String RECOVERY_MESSAGE = "I am ready to receive the backup file. Please reply to this message with the backup file attached."; + protected static final String RECOVER_SUCCESS = "I have successfully recovered."; + private static final String[] EMPTY_ARRAY = {}; private static final long GROUP_ID = 10L; private static final String TEST = "test";