test: complete first test for help message
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
c4db3be4cb
commit
53cdd4aa22
|
@ -1,10 +1,10 @@
|
||||||
package com.github.polpetta.mezzotre;
|
package com.github.polpetta.mezzotre;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.orm.di.Db;
|
import com.github.polpetta.mezzotre.orm.OrmDI;
|
||||||
|
import com.github.polpetta.mezzotre.route.RouteDI;
|
||||||
import com.github.polpetta.mezzotre.route.Telegram;
|
import com.github.polpetta.mezzotre.route.Telegram;
|
||||||
import com.github.polpetta.mezzotre.route.di.Route;
|
import com.github.polpetta.mezzotre.telegram.callbackquery.CallbackQueryDI;
|
||||||
import com.github.polpetta.mezzotre.telegram.callbackquery.di.CallbackQuery;
|
import com.github.polpetta.mezzotre.telegram.command.CommandDI;
|
||||||
import com.github.polpetta.mezzotre.telegram.command.di.Command;
|
|
||||||
import com.github.polpetta.mezzotre.util.di.ThreadPool;
|
import com.github.polpetta.mezzotre.util.di.ThreadPool;
|
||||||
import com.google.inject.*;
|
import com.google.inject.*;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -23,11 +23,11 @@ public class App extends Jooby {
|
||||||
public static final Function<Jooby, Collection<Module>> DEFAULT_DI_MODULES =
|
public static final Function<Jooby, Collection<Module>> DEFAULT_DI_MODULES =
|
||||||
(jooby) -> {
|
(jooby) -> {
|
||||||
final HashSet<Module> modules = new HashSet<>();
|
final HashSet<Module> modules = new HashSet<>();
|
||||||
modules.add(new Db());
|
modules.add(new OrmDI());
|
||||||
modules.add(new ThreadPool());
|
modules.add(new ThreadPool());
|
||||||
modules.add(new Route());
|
modules.add(new RouteDI());
|
||||||
modules.add(new Command());
|
modules.add(new CommandDI());
|
||||||
modules.add(new CallbackQuery());
|
modules.add(new CallbackQueryDI());
|
||||||
return modules;
|
return modules;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class App extends Jooby {
|
||||||
if (modules == null || modules.size() == 0) {
|
if (modules == null || modules.size() == 0) {
|
||||||
toInject = DEFAULT_DI_MODULES.apply(this);
|
toInject = DEFAULT_DI_MODULES.apply(this);
|
||||||
}
|
}
|
||||||
toInject.add(new InjectionModule(this));
|
toInject.add(new AppDI(this));
|
||||||
toInject.add(new JoobyModule(this));
|
toInject.add(new JoobyModule(this));
|
||||||
|
|
||||||
final Injector injector = Guice.createInjector(runningEnv, toInject);
|
final Injector injector = Guice.createInjector(runningEnv, toInject);
|
||||||
|
|
|
@ -7,13 +7,13 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
public class InjectionModule extends AbstractModule {
|
public class AppDI extends AbstractModule {
|
||||||
|
|
||||||
// In the future we can get this name from mvn, by now it is good as it is
|
// In the future we can get this name from mvn, by now it is good as it is
|
||||||
public static final String APPLICATION_NAME = "Mezzotre";
|
public static final String APPLICATION_NAME = "Mezzotre";
|
||||||
private final Jooby jooby;
|
private final Jooby jooby;
|
||||||
|
|
||||||
public InjectionModule(Jooby jooby) {
|
public AppDI(Jooby jooby) {
|
||||||
this.jooby = jooby;
|
this.jooby = jooby;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.github.polpetta.mezzotre.orm.di;
|
package com.github.polpetta.mezzotre.orm;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -10,7 +10,7 @@ import io.jooby.flyway.FlywayModule;
|
||||||
import io.jooby.hikari.HikariModule;
|
import io.jooby.hikari.HikariModule;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
public class Db extends AbstractModule {
|
public class OrmDI extends AbstractModule {
|
||||||
/**
|
/**
|
||||||
* Returns null. This allows to fetch the configuration from file rather than fetch from other
|
* Returns null. This allows to fetch the configuration from file rather than fetch from other
|
||||||
* environment
|
* environment
|
|
@ -1,4 +1,4 @@
|
||||||
package com.github.polpetta.mezzotre.route.di;
|
package com.github.polpetta.mezzotre.route;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -7,7 +7,7 @@ import io.jooby.Jooby;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
public class Route extends AbstractModule {
|
public class RouteDI extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public TelegramBot getTelegramBot(Jooby jooby) {
|
public TelegramBot getTelegramBot(Jooby jooby) {
|
|
@ -1,8 +1,5 @@
|
||||||
package com.github.polpetta.mezzotre.telegram.callbackquery.di;
|
package com.github.polpetta.mezzotre.telegram.callbackquery;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.telegram.callbackquery.Processor;
|
|
||||||
import com.github.polpetta.mezzotre.telegram.callbackquery.SelectLanguageTutorial;
|
|
||||||
import com.github.polpetta.mezzotre.telegram.callbackquery.ShowHelp;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -10,7 +7,7 @@ import java.util.Map;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
public class CallbackQuery extends AbstractModule {
|
public class CallbackQueryDI extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.github.polpetta.mezzotre.telegram.callbackquery;
|
||||||
|
|
||||||
|
public interface Field {
|
||||||
|
/**
|
||||||
|
* Additional fields that are related to {@code changeLanguage} event
|
||||||
|
*
|
||||||
|
* @author Davide Polonio
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
enum SelectLanguageTutorial {
|
||||||
|
NewLanguage("newLanguage");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
SelectLanguageTutorial(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ShowHelp {
|
||||||
|
InvokedFromHelpMessage("invokedFromHelpMessage");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
ShowHelp(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,12 +17,20 @@ import java.util.concurrent.CompletableFuture;
|
||||||
public interface Processor {
|
public interface Processor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The even name this processor is able to process
|
* The event name this processor is able to process
|
||||||
*
|
*
|
||||||
* @return a {@link String} containig the name of the event supported
|
* @return a {@link String} containing the name of the event supported
|
||||||
*/
|
*/
|
||||||
String getEventName();
|
String getEventName();
|
||||||
|
|
||||||
|
default boolean canBeDirectlyInvokedByTheUser() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
default Optional<String> getPrettyPrintLocaleKeyName() {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the current event
|
* Process the current event
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,47 +39,6 @@ public class SelectLanguageTutorial implements Processor {
|
||||||
private final Logger log;
|
private final Logger log;
|
||||||
private final UUIDGenerator uuidGenerator;
|
private final UUIDGenerator uuidGenerator;
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional fields that are related to {@code changeLanguage} event
|
|
||||||
*
|
|
||||||
* @author Davide Polonio
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public enum Field {
|
|
||||||
NewLanguage("newLanguage");
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
Field(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Possible values for the additional {@link Field} of {@code changeLanguage} event
|
|
||||||
*
|
|
||||||
* @author Davide Polonio
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
public enum Language {
|
|
||||||
English("en-US"),
|
|
||||||
Italian("it-IT");
|
|
||||||
|
|
||||||
private final String locale;
|
|
||||||
|
|
||||||
Language(String locale) {
|
|
||||||
this.locale = locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocale() {
|
|
||||||
return locale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SelectLanguageTutorial(
|
public SelectLanguageTutorial(
|
||||||
@Named("eventThreadPool") Executor threadPool,
|
@Named("eventThreadPool") Executor threadPool,
|
||||||
|
@ -120,7 +79,8 @@ public class SelectLanguageTutorial implements Processor {
|
||||||
.getFields()
|
.getFields()
|
||||||
.getAdditionalProperties()
|
.getAdditionalProperties()
|
||||||
.getOrDefault(
|
.getOrDefault(
|
||||||
Field.NewLanguage.getName(), tgChat.getLocale()));
|
Field.SelectLanguageTutorial.NewLanguage.getName(),
|
||||||
|
tgChat.getLocale()));
|
||||||
tgChat.save();
|
tgChat.save();
|
||||||
log.trace(
|
log.trace(
|
||||||
"Locale for chat "
|
"Locale for chat "
|
||||||
|
@ -166,7 +126,9 @@ public class SelectLanguageTutorial implements Processor {
|
||||||
if (!tgChat.getHasHelpBeenShown()) {
|
if (!tgChat.getHasHelpBeenShown()) {
|
||||||
// Add a button to show all the possible commands
|
// Add a button to show all the possible commands
|
||||||
final String showMeTutorialString =
|
final String showMeTutorialString =
|
||||||
templateContentGenerator.getString(tgChat.getLocale(), "button.showMeTutorial");
|
templateContentGenerator.getString(
|
||||||
|
tgChat.getLocale(),
|
||||||
|
"selectLanguageTutorial.showMeTutorialInlineKeyboardButtonName");
|
||||||
|
|
||||||
final CallbackQueryMetadata callbackQueryMetadata =
|
final CallbackQueryMetadata callbackQueryMetadata =
|
||||||
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
||||||
|
|
|
@ -7,7 +7,7 @@ import com.pengrad.telegrambot.request.SendMessage;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ShowHelp implements Processor {
|
class ShowHelp implements Processor {
|
||||||
|
|
||||||
public static String EVENT_NAME = "showHelp";
|
public static String EVENT_NAME = "showHelp";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.github.polpetta.mezzotre.telegram.callbackquery;
|
||||||
|
|
||||||
|
public interface Value {
|
||||||
|
/**
|
||||||
|
* Possible values for the additional {@link Field.SelectLanguageTutorial} of {@code
|
||||||
|
* changeLanguage} event
|
||||||
|
*
|
||||||
|
* @author Davide Polonio
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
enum SelectLanguageTutorial {
|
||||||
|
English("en-US"),
|
||||||
|
Italian("it-IT");
|
||||||
|
|
||||||
|
private final String locale;
|
||||||
|
|
||||||
|
SelectLanguageTutorial(String locale) {
|
||||||
|
this.locale = locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocale() {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package com.github.polpetta.mezzotre.telegram.command.di;
|
package com.github.polpetta.mezzotre.telegram.command;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.telegram.command.*;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||||
|
@ -12,7 +11,7 @@ import org.apache.velocity.app.VelocityEngine;
|
||||||
import org.apache.velocity.runtime.RuntimeConstants;
|
import org.apache.velocity.runtime.RuntimeConstants;
|
||||||
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
|
||||||
|
|
||||||
public class Command extends AbstractModule {
|
public class CommandDI extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
|
@ -1,10 +1,17 @@
|
||||||
package com.github.polpetta.mezzotre.telegram.command;
|
package com.github.polpetta.mezzotre.telegram.command;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
||||||
|
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
|
||||||
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
||||||
|
import com.github.polpetta.mezzotre.telegram.callbackquery.Field;
|
||||||
import com.github.polpetta.mezzotre.util.Clock;
|
import com.github.polpetta.mezzotre.util.Clock;
|
||||||
|
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
||||||
|
import com.github.polpetta.types.json.CallbackQueryMetadata;
|
||||||
import com.github.polpetta.types.json.ChatContext;
|
import com.github.polpetta.types.json.ChatContext;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
|
||||||
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
import com.pengrad.telegrambot.request.BaseRequest;
|
import com.pengrad.telegrambot.request.BaseRequest;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -25,17 +32,25 @@ public class Help implements Processor {
|
||||||
private final Executor threadPool;
|
private final Executor threadPool;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final Map<String, Processor> tgCommandProcessors;
|
private final Map<String, Processor> tgCommandProcessors;
|
||||||
|
private final Map<String, com.github.polpetta.mezzotre.telegram.callbackquery.Processor>
|
||||||
|
eventProcessor;
|
||||||
|
private final UUIDGenerator uuidGenerator;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Help(
|
public Help(
|
||||||
TemplateContentGenerator templateContentGenerator,
|
TemplateContentGenerator templateContentGenerator,
|
||||||
@Named("eventThreadPool") Executor threadPool,
|
@Named("eventThreadPool") Executor threadPool,
|
||||||
Clock clock,
|
Clock clock,
|
||||||
@Named("commandProcessor") Map<String, Processor> tgCommandProcessors) {
|
@Named("commandProcessor") Map<String, Processor> tgCommandProcessors,
|
||||||
|
@Named("eventProcessors")
|
||||||
|
Map<String, com.github.polpetta.mezzotre.telegram.callbackquery.Processor> eventProcessor,
|
||||||
|
UUIDGenerator uuidGenerator) {
|
||||||
this.templateContentGenerator = templateContentGenerator;
|
this.templateContentGenerator = templateContentGenerator;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
this.tgCommandProcessors = tgCommandProcessors;
|
this.tgCommandProcessors = tgCommandProcessors;
|
||||||
|
this.eventProcessor = eventProcessor;
|
||||||
|
this.uuidGenerator = uuidGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,9 +89,41 @@ public class Help implements Processor {
|
||||||
chat.setHasHelpBeenShown(true);
|
chat.setHasHelpBeenShown(true);
|
||||||
chat.save();
|
chat.save();
|
||||||
|
|
||||||
// FIXME put all the buttons here
|
final SendMessage sendMessage =
|
||||||
|
new SendMessage(chat.getId(), message).parseMode(ParseMode.Markdown);
|
||||||
|
|
||||||
return Optional.of(new SendMessage(chat.getId(), message));
|
final String callBackGroupId = uuidGenerator.generateAsString();
|
||||||
|
final InlineKeyboardButton[] collect =
|
||||||
|
eventProcessor.values().stream()
|
||||||
|
.filter(
|
||||||
|
com.github.polpetta.mezzotre.telegram.callbackquery.Processor
|
||||||
|
::canBeDirectlyInvokedByTheUser)
|
||||||
|
.filter(e -> e.getPrettyPrintLocaleKeyName().isPresent())
|
||||||
|
.map(
|
||||||
|
eventProcessor -> {
|
||||||
|
final CallbackQueryContext callbackQueryContext =
|
||||||
|
new CallbackQueryContext(
|
||||||
|
uuidGenerator.generateAsString(),
|
||||||
|
callBackGroupId,
|
||||||
|
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
||||||
|
.withEvent(eventProcessor.getEventName())
|
||||||
|
.withTelegramChatId(chat.getId())
|
||||||
|
.withAdditionalProperty(
|
||||||
|
Field.ShowHelp.InvokedFromHelpMessage.getName(), true)
|
||||||
|
.build());
|
||||||
|
callbackQueryContext.save();
|
||||||
|
|
||||||
|
return new InlineKeyboardButton(
|
||||||
|
templateContentGenerator.getString(
|
||||||
|
chat.getLocale(),
|
||||||
|
eventProcessor.getPrettyPrintLocaleKeyName().get()))
|
||||||
|
.callbackData(callbackQueryContext.getId());
|
||||||
|
})
|
||||||
|
.toArray(InlineKeyboardButton[]::new);
|
||||||
|
|
||||||
|
sendMessage.replyMarkup(new InlineKeyboardMarkup(collect));
|
||||||
|
|
||||||
|
return Optional.of(sendMessage);
|
||||||
},
|
},
|
||||||
threadPool);
|
threadPool);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ package com.github.polpetta.mezzotre.telegram.command;
|
||||||
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
||||||
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
|
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
|
||||||
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
||||||
import com.github.polpetta.mezzotre.telegram.callbackquery.SelectLanguageTutorial;
|
import com.github.polpetta.mezzotre.telegram.callbackquery.Field;
|
||||||
|
import com.github.polpetta.mezzotre.telegram.callbackquery.Value;
|
||||||
import com.github.polpetta.mezzotre.util.Clock;
|
import com.github.polpetta.mezzotre.util.Clock;
|
||||||
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
||||||
import com.github.polpetta.types.json.CallbackQueryMetadata;
|
import com.github.polpetta.types.json.CallbackQueryMetadata;
|
||||||
|
@ -100,11 +101,13 @@ public class Start implements Processor {
|
||||||
uuidGenerator.generateAsString(),
|
uuidGenerator.generateAsString(),
|
||||||
groupId,
|
groupId,
|
||||||
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
||||||
.withEvent(SelectLanguageTutorial.EVENT_NAME)
|
.withEvent(
|
||||||
|
com.github.polpetta.mezzotre.telegram.callbackquery.SelectLanguageTutorial
|
||||||
|
.EVENT_NAME)
|
||||||
.withTelegramChatId(update.message().chat().id())
|
.withTelegramChatId(update.message().chat().id())
|
||||||
.withAdditionalProperty(
|
.withAdditionalProperty(
|
||||||
SelectLanguageTutorial.Field.NewLanguage.getName(),
|
Field.SelectLanguageTutorial.NewLanguage.getName(),
|
||||||
SelectLanguageTutorial.Language.English.getLocale())
|
Value.SelectLanguageTutorial.English.getLocale())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
final CallbackQueryContext switchToItalian =
|
final CallbackQueryContext switchToItalian =
|
||||||
|
@ -112,11 +115,13 @@ public class Start implements Processor {
|
||||||
uuidGenerator.generateAsString(),
|
uuidGenerator.generateAsString(),
|
||||||
groupId,
|
groupId,
|
||||||
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
new CallbackQueryMetadata.CallbackQueryMetadataBuilder()
|
||||||
.withEvent(SelectLanguageTutorial.EVENT_NAME)
|
.withEvent(
|
||||||
|
com.github.polpetta.mezzotre.telegram.callbackquery.SelectLanguageTutorial
|
||||||
|
.EVENT_NAME)
|
||||||
.withTelegramChatId(update.message().chat().id())
|
.withTelegramChatId(update.message().chat().id())
|
||||||
.withAdditionalProperty(
|
.withAdditionalProperty(
|
||||||
SelectLanguageTutorial.Field.NewLanguage.getName(),
|
Field.SelectLanguageTutorial.NewLanguage.getName(),
|
||||||
SelectLanguageTutorial.Language.Italian.getLocale())
|
Value.SelectLanguageTutorial.Italian.getLocale())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
final String englishButton =
|
final String englishButton =
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
start.helloFirstName=Hello {0}! \ud83d\udc4b
|
start.helloFirstName=Hello {0}! \ud83d\udc4b
|
||||||
start.description=This is {0}, a simple bot focused on DnD content management! Please start by choosing a language down below \ud83d\udc47
|
start.description=This is {0}, a simple bot focused on DnD content management! Please start by choosing a selectLanguageTutorial down below \ud83d\udc47
|
||||||
start.cmdDescription=Trigger this very bot
|
start.cmdDescription=Trigger this very bot
|
||||||
|
start.inlineKeyboardButtonName=Let''s begin!
|
||||||
|
selectLanguageTutorial.inlineKeyboardButtonName=Select language
|
||||||
selectLanguageTutorial.drinkAction=*Proceeds to drink a potion with a strange, multicolor liquid*
|
selectLanguageTutorial.drinkAction=*Proceeds to drink a potion with a strange, multicolor liquid*
|
||||||
selectLanguageTutorial.setLanguage=Thanks! Now that I drank this modified potion of {0} that I''ve found at the "Crystal Fermentary" magic potion shop yesterday I can speak with you in the language that you prefer!
|
selectLanguageTutorial.setLanguage=Thanks! Now that I drank this modified potion of {0} that I''ve found at the "Crystal Fermentary" magic potion shop yesterday I can speak with you in the selectLanguageTutorial that you prefer!
|
||||||
selectLanguageTutorial.instructions=You can always change your language settings by typing /selectLanguageTutorial in the chat.
|
selectLanguageTutorial.instructions=You can always change your selectLanguageTutorial settings by typing /selectLanguageTutorial in the chat.
|
||||||
changeLanguage.english=English
|
changeLanguage.english=English
|
||||||
changeLanguage.italian=Italian
|
changeLanguage.italian=Italian
|
||||||
changeLanguage.cmdDescription=Select the new language I will use to speak to you
|
changeLanguage.cmdDescription=Select the new language I will use to speak to you
|
||||||
|
changeLanguage.inlineKeyboardButtonName=Change language
|
||||||
spell.speakWithAnimals=Speak with animals
|
spell.speakWithAnimals=Speak with animals
|
||||||
button.showMeTutorial=Show me what you can do!
|
selectLanguageTutorial.showMeTutorialInlineKeyboardButtonName=Show me what you can do!
|
||||||
help.notShownYet=It seems you haven''t checked out what I can do yet! To have a complete list of my abilities, type /help in chat at any time!
|
help.notShownYet=It seems you haven''t checked out what I can do yet! To have a complete list of my abilities, type /help in chat at any time!
|
||||||
help.buttonBelow=Alternatively, you can click the button down below.
|
help.buttonBelow=Alternatively, you can click the button down below.
|
||||||
help.description=Here is a list of what I can do
|
help.description=Here is a list of what I can do
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
start.helloFirstName=Hello {0}! \ud83d\udc4b
|
start.helloFirstName=Hello {0}! \ud83d\udc4b
|
||||||
start.description=This is {0}, a simple bot focused on DnD content management! Please start by choosing a language down below \ud83d\udc47
|
start.description=This is {0}, a simple bot focused on DnD content management! Please start by choosing a selectLanguageTutorial down below \ud83d\udc47
|
||||||
selectLanguageTutorial.drinkAction=*Proceeds to drink a potion with a strange, multicolor liquid*
|
selectLanguageTutorial.drinkAction=*Proceeds to drink a potion with a strange, multicolor liquid*
|
||||||
selectLanguageTutorial.setLanguage=Thanks! Now that I drank this modified potion of {0} that I''ve found at the "Crystal Fermentary" magic potion shop yesterday I can speak with you in the language that you prefer!
|
selectLanguageTutorial.setLanguage=Thanks! Now that I drank this modified potion of {0} that I''ve found at the "Crystal Fermentary" magic potion shop yesterday I can speak with you in the selectLanguageTutorial that you prefer!
|
||||||
selectLanguageTutorial.instructions=You can always change your language settings by typing /selectLanguageTutorial in the chat.
|
selectLanguageTutorial.instructions=You can always change your selectLanguageTutorial settings by typing /selectLanguageTutorial in the chat.
|
||||||
selectLanguageTutorial.english=English
|
selectLanguageTutorial.english=English
|
||||||
selectLanguageTutorial.italian=Italian
|
selectLanguageTutorial.italian=Italian
|
||||||
spell.speakWithAnimals=Speak with animals
|
spell.speakWithAnimals=Speak with animals
|
||||||
button.showMeTutorial=Show me what you can do!
|
selectLanguageTutorial.showMeTutorialInlineKeyboardButtonName=Show me what you can do!
|
||||||
help.notShownYet=It seems you haven''t checked out what I can do yet! To have a complete list of my abilities, type /help in chat at any time!
|
help.notShownYet=It seems you haven''t checked out what I can do yet! To have a complete list of my abilities, type /help in chat at any time!
|
||||||
help.buttonBelow=Alternatively, you can click the button down below.
|
help.buttonBelow=Alternatively, you can click the button down below.
|
||||||
|
|
|
@ -6,6 +6,6 @@ selectLanguageTutorial.instructions=Puoi sempre cambiare le preferenze della tua
|
||||||
selectLanguageTutorial.english=Inglese
|
selectLanguageTutorial.english=Inglese
|
||||||
selectLanguageTutorial.italian=Italiano
|
selectLanguageTutorial.italian=Italiano
|
||||||
spell.speakWithAnimals=Parlare con animali
|
spell.speakWithAnimals=Parlare con animali
|
||||||
button.showMeTutorial=Mostrami cosa puoi fare!
|
selectLanguageTutorial.showMeTutorialInlineKeyboardButtonName=Mostrami cosa puoi fare!
|
||||||
help.notShownYet=Sembra tu non abbia ancora visto cosa posso fare! Per avere una lista completa delle mie abilità, scrivi /help nella chat in qualsiasi momento!
|
help.notShownYet=Sembra tu non abbia ancora visto cosa posso fare! Per avere una lista completa delle mie abilità, scrivi /help nella chat in qualsiasi momento!
|
||||||
help.buttonBelow=Alternativamente, puoi premere il bottone qui sotto.
|
help.buttonBelow=Alternativamente, puoi premere il bottone qui sotto.
|
||||||
|
|
|
@ -6,6 +6,6 @@ selectLanguageTutorial.instructions=Puoi sempre cambiare le preferenze della tua
|
||||||
selectLanguageTutorial.english=Inglese
|
selectLanguageTutorial.english=Inglese
|
||||||
selectLanguageTutorial.italian=Italiano
|
selectLanguageTutorial.italian=Italiano
|
||||||
spell.speakWithAnimals=Parlare con animali
|
spell.speakWithAnimals=Parlare con animali
|
||||||
button.showMeTutorial=Mostrami cosa puoi fare!
|
selectLanguageTutorial.showMeTutorialInlineKeyboardButtonName=Mostrami cosa puoi fare!
|
||||||
help.notShownYet=Sembra tu non abbia ancora visto cosa posso fare! Per avere una lista completa delle mie abilità, scrivi /help nella chat in qualsiasi momento!
|
help.notShownYet=Sembra tu non abbia ancora visto cosa posso fare! Per avere una lista completa delle mie abilità, scrivi /help nella chat in qualsiasi momento!
|
||||||
help.buttonBelow=Alternativamente, puoi premere il bottone qui sotto.
|
help.buttonBelow=Alternativamente, puoi premere il bottone qui sotto.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.github.polpetta.mezzotre.helper;
|
package com.github.polpetta.mezzotre.helper;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.App;
|
import com.github.polpetta.mezzotre.App;
|
||||||
import com.github.polpetta.mezzotre.route.di.Route;
|
import com.github.polpetta.mezzotre.route.RouteDI;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
@ -56,7 +56,7 @@ public class IntegrationAppFactory {
|
||||||
final PostgreSQLContainer<?> container =
|
final PostgreSQLContainer<?> container =
|
||||||
new PostgreSQLContainer<>(TestConfig.POSTGRES_DOCKER_IMAGE);
|
new PostgreSQLContainer<>(TestConfig.POSTGRES_DOCKER_IMAGE);
|
||||||
container.start();
|
container.start();
|
||||||
final Route routeModule = new Route();
|
final RouteDI routeModule = new RouteDI();
|
||||||
final DatabaseDI databaseDI = new DatabaseDI(container);
|
final DatabaseDI databaseDI = new DatabaseDI(container);
|
||||||
return new App(Stage.DEVELOPMENT, Set.of(databaseDI, routeModule));
|
return new App(Stage.DEVELOPMENT, Set.of(databaseDI, routeModule));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
@Tag("slow")
|
@Tag("slow")
|
||||||
@Tag("database")
|
@Tag("database")
|
||||||
@Testcontainers
|
@Testcontainers
|
||||||
class CallbackQueryContextIntegrationTest {
|
class CallbackQueryDIContextIntegrationTest {
|
||||||
|
|
||||||
private static ObjectMapper objectMapper;
|
private static ObjectMapper objectMapper;
|
||||||
private static UUIDGenerator uuidGenerator;
|
private static UUIDGenerator uuidGenerator;
|
|
@ -77,7 +77,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
private static Stream<Arguments> getTestLocales() {
|
private static Stream<Arguments> getTestLocales() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
SelectLanguageTutorial.Language.Italian,
|
Value.SelectLanguageTutorial.Italian,
|
||||||
"_*Procede a bere una pozione al cui suo interno si trova uno strano liquido"
|
"_*Procede a bere una pozione al cui suo interno si trova uno strano liquido"
|
||||||
+ " multicolore*_\n"
|
+ " multicolore*_\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
|
@ -95,7 +95,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
"Mostrami cosa puoi fare!",
|
"Mostrami cosa puoi fare!",
|
||||||
false),
|
false),
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
SelectLanguageTutorial.Language.English,
|
Value.SelectLanguageTutorial.English,
|
||||||
"_*Proceeds to drink a potion with a strange, multicolor liquid*_\n"
|
"_*Proceeds to drink a potion with a strange, multicolor liquid*_\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "Thanks! Now that I drank this modified potion of Speak with animals that I've"
|
+ "Thanks! Now that I drank this modified potion of Speak with animals that I've"
|
||||||
|
@ -112,7 +112,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
"Show me what you can do!",
|
"Show me what you can do!",
|
||||||
false),
|
false),
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
SelectLanguageTutorial.Language.Italian,
|
Value.SelectLanguageTutorial.Italian,
|
||||||
"_*Procede a bere una pozione al cui suo interno si trova uno strano liquido"
|
"_*Procede a bere una pozione al cui suo interno si trova uno strano liquido"
|
||||||
+ " multicolore*_\n"
|
+ " multicolore*_\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
|
@ -126,7 +126,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
"Mostrami cosa puoi fare!",
|
"Mostrami cosa puoi fare!",
|
||||||
true),
|
true),
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
SelectLanguageTutorial.Language.English,
|
Value.SelectLanguageTutorial.English,
|
||||||
"_*Proceeds to drink a potion with a strange, multicolor liquid*_\n"
|
"_*Proceeds to drink a potion with a strange, multicolor liquid*_\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "Thanks! Now that I drank this modified potion of Speak with animals that I've"
|
+ "Thanks! Now that I drank this modified potion of Speak with animals that I've"
|
||||||
|
@ -144,7 +144,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
@Timeout(value = 1, unit = TimeUnit.MINUTES)
|
@Timeout(value = 1, unit = TimeUnit.MINUTES)
|
||||||
@MethodSource("getTestLocales")
|
@MethodSource("getTestLocales")
|
||||||
void shouldProcessChangeLanguageToDesiredOneSendMessage(
|
void shouldProcessChangeLanguageToDesiredOneSendMessage(
|
||||||
SelectLanguageTutorial.Language language,
|
Value.SelectLanguageTutorial selectLanguageTutorial,
|
||||||
String expectedResult,
|
String expectedResult,
|
||||||
String startingLocale,
|
String startingLocale,
|
||||||
String buttonLocale,
|
String buttonLocale,
|
||||||
|
@ -184,7 +184,8 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
.withEvent("selectLanguageTutorial")
|
.withEvent("selectLanguageTutorial")
|
||||||
.withTelegramChatId(tgChatId)
|
.withTelegramChatId(tgChatId)
|
||||||
.withAdditionalProperty(
|
.withAdditionalProperty(
|
||||||
SelectLanguageTutorial.Field.NewLanguage.getName(), language.getLocale())
|
Field.SelectLanguageTutorial.NewLanguage.getName(),
|
||||||
|
selectLanguageTutorial.getLocale())
|
||||||
.build();
|
.build();
|
||||||
final String entryGroupId = "2e67774a-e4e4-4369-a414-a7f8bfe74b80";
|
final String entryGroupId = "2e67774a-e4e4-4369-a414-a7f8bfe74b80";
|
||||||
final CallbackQueryContext changeLanguageCallbackQueryContext =
|
final CallbackQueryContext changeLanguageCallbackQueryContext =
|
||||||
|
@ -193,7 +194,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
changeLanguageCallbackQueryContext.save();
|
changeLanguageCallbackQueryContext.save();
|
||||||
|
|
||||||
final CompletableFuture<Optional<BaseRequest<?, ?>>> processFuture =
|
final CompletableFuture<Optional<BaseRequest<?, ?>>> processFuture =
|
||||||
selectLanguageTutorial.process(changeLanguageCallbackQueryContext, update);
|
this.selectLanguageTutorial.process(changeLanguageCallbackQueryContext, update);
|
||||||
final Optional<BaseRequest<?, ?>> gotResponseOpt = processFuture.get();
|
final Optional<BaseRequest<?, ?>> gotResponseOpt = processFuture.get();
|
||||||
final SendMessage gotMessage = (SendMessage) gotResponseOpt.get();
|
final SendMessage gotMessage = (SendMessage) gotResponseOpt.get();
|
||||||
assertEquals(expectedResult, gotMessage.getParameters().get("text"));
|
assertEquals(expectedResult, gotMessage.getParameters().get("text"));
|
||||||
|
@ -218,7 +219,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
|
|
||||||
final TgChat retrievedTgChat = new QTgChat().id.eq(tgChatId).findOne();
|
final TgChat retrievedTgChat = new QTgChat().id.eq(tgChatId).findOne();
|
||||||
assertNotNull(retrievedTgChat);
|
assertNotNull(retrievedTgChat);
|
||||||
assertEquals(language.getLocale(), retrievedTgChat.getLocale());
|
assertEquals(selectLanguageTutorial.getLocale(), retrievedTgChat.getLocale());
|
||||||
|
|
||||||
assertEquals(0, new QCallbackQueryContext().entryGroup.eq(entryGroupId).findCount());
|
assertEquals(0, new QCallbackQueryContext().entryGroup.eq(entryGroupId).findCount());
|
||||||
}
|
}
|
||||||
|
@ -227,7 +228,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
@Timeout(value = 1, unit = TimeUnit.MINUTES)
|
@Timeout(value = 1, unit = TimeUnit.MINUTES)
|
||||||
@MethodSource("getTestLocales")
|
@MethodSource("getTestLocales")
|
||||||
void shouldProcessChangeLanguageToDesiredOneEditMessage(
|
void shouldProcessChangeLanguageToDesiredOneEditMessage(
|
||||||
SelectLanguageTutorial.Language language,
|
Value.SelectLanguageTutorial selectLanguageTutorial,
|
||||||
String expectedResult,
|
String expectedResult,
|
||||||
String startingLocale,
|
String startingLocale,
|
||||||
String buttonLocale,
|
String buttonLocale,
|
||||||
|
@ -299,7 +300,8 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
.withEvent("selectLanguageTutorial")
|
.withEvent("selectLanguageTutorial")
|
||||||
.withTelegramChatId(tgChatId)
|
.withTelegramChatId(tgChatId)
|
||||||
.withAdditionalProperty(
|
.withAdditionalProperty(
|
||||||
SelectLanguageTutorial.Field.NewLanguage.getName(), language.getLocale())
|
Field.SelectLanguageTutorial.NewLanguage.getName(),
|
||||||
|
selectLanguageTutorial.getLocale())
|
||||||
.build();
|
.build();
|
||||||
final String entryGroupId = "2e67774a-e4e4-4369-a414-a7f8bfe74b80";
|
final String entryGroupId = "2e67774a-e4e4-4369-a414-a7f8bfe74b80";
|
||||||
final CallbackQueryContext changeLanguageCallbackQueryContext =
|
final CallbackQueryContext changeLanguageCallbackQueryContext =
|
||||||
|
@ -308,7 +310,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
changeLanguageCallbackQueryContext.save();
|
changeLanguageCallbackQueryContext.save();
|
||||||
|
|
||||||
final CompletableFuture<Optional<BaseRequest<?, ?>>> processFuture =
|
final CompletableFuture<Optional<BaseRequest<?, ?>>> processFuture =
|
||||||
selectLanguageTutorial.process(changeLanguageCallbackQueryContext, update);
|
this.selectLanguageTutorial.process(changeLanguageCallbackQueryContext, update);
|
||||||
final Optional<BaseRequest<?, ?>> gotResponseOpt = processFuture.get();
|
final Optional<BaseRequest<?, ?>> gotResponseOpt = processFuture.get();
|
||||||
final EditMessageText gotMessage = (EditMessageText) gotResponseOpt.get();
|
final EditMessageText gotMessage = (EditMessageText) gotResponseOpt.get();
|
||||||
assertEquals(expectedResult, gotMessage.getParameters().get("text"));
|
assertEquals(expectedResult, gotMessage.getParameters().get("text"));
|
||||||
|
@ -333,7 +335,7 @@ class SelectLanguageTutorialIntegrationTest {
|
||||||
|
|
||||||
final TgChat retrievedTgChat = new QTgChat().id.eq(tgChatId).findOne();
|
final TgChat retrievedTgChat = new QTgChat().id.eq(tgChatId).findOne();
|
||||||
assertNotNull(retrievedTgChat);
|
assertNotNull(retrievedTgChat);
|
||||||
assertEquals(language.getLocale(), retrievedTgChat.getLocale());
|
assertEquals(selectLanguageTutorial.getLocale(), retrievedTgChat.getLocale());
|
||||||
|
|
||||||
assertEquals(0, new QCallbackQueryContext().entryGroup.eq(entryGroupId).findCount());
|
assertEquals(0, new QCallbackQueryContext().entryGroup.eq(entryGroupId).findCount());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,20 +8,23 @@ import com.github.polpetta.mezzotre.helper.Loader;
|
||||||
import com.github.polpetta.mezzotre.helper.TestConfig;
|
import com.github.polpetta.mezzotre.helper.TestConfig;
|
||||||
import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
|
import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
|
||||||
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
import com.github.polpetta.mezzotre.i18n.TemplateContentGenerator;
|
||||||
|
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
|
||||||
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
||||||
import com.github.polpetta.mezzotre.orm.model.query.QTgChat;
|
import com.github.polpetta.mezzotre.orm.model.query.QTgChat;
|
||||||
import com.github.polpetta.mezzotre.util.Clock;
|
import com.github.polpetta.mezzotre.util.Clock;
|
||||||
|
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
||||||
import com.github.polpetta.types.json.ChatContext;
|
import com.github.polpetta.types.json.ChatContext;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
||||||
|
import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
|
||||||
import com.pengrad.telegrambot.request.BaseRequest;
|
import com.pengrad.telegrambot.request.BaseRequest;
|
||||||
import com.pengrad.telegrambot.request.SendMessage;
|
import com.pengrad.telegrambot.request.SendMessage;
|
||||||
import io.ebean.Database;
|
import io.ebean.Database;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.apache.velocity.app.VelocityEngine;
|
import org.apache.velocity.app.VelocityEngine;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -112,12 +115,68 @@ class HelpIntegrationTest {
|
||||||
commands.put("/b", dummy1);
|
commands.put("/b", dummy1);
|
||||||
commands.put("/different", dummy2);
|
commands.put("/different", dummy2);
|
||||||
|
|
||||||
|
final Map<String, com.github.polpetta.mezzotre.telegram.callbackquery.Processor> events =
|
||||||
|
new HashMap<>();
|
||||||
|
|
||||||
|
final com.github.polpetta.mezzotre.telegram.callbackquery.Processor dummyEvent1 =
|
||||||
|
new com.github.polpetta.mezzotre.telegram.callbackquery.Processor() {
|
||||||
|
@Override
|
||||||
|
public String getEventName() {
|
||||||
|
return "exampleEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeDirectlyInvokedByTheUser() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getPrettyPrintLocaleKeyName() {
|
||||||
|
return Optional.of("changeLanguage.inlineKeyboardButtonName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<BaseRequest<?, ?>>> process(
|
||||||
|
CallbackQueryContext callbackQueryContext, Update update) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final com.github.polpetta.mezzotre.telegram.callbackquery.Processor dummyEvent2 =
|
||||||
|
new com.github.polpetta.mezzotre.telegram.callbackquery.Processor() {
|
||||||
|
@Override
|
||||||
|
public String getEventName() {
|
||||||
|
return "secondExampleEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeDirectlyInvokedByTheUser() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getPrettyPrintLocaleKeyName() {
|
||||||
|
return Optional.of("selectLanguageTutorial.inlineKeyboardButtonName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<BaseRequest<?, ?>>> process(
|
||||||
|
CallbackQueryContext callbackQueryContext, Update update) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
events.put(dummyEvent1.getEventName(), dummyEvent1);
|
||||||
|
events.put(dummyEvent2.getEventName(), dummyEvent2);
|
||||||
|
|
||||||
help =
|
help =
|
||||||
new Help(
|
new Help(
|
||||||
new TemplateContentGenerator(new LocalizedMessageFactory(velocityEngine)),
|
new TemplateContentGenerator(new LocalizedMessageFactory(velocityEngine)),
|
||||||
Executors.newSingleThreadExecutor(),
|
Executors.newSingleThreadExecutor(),
|
||||||
fakeClock,
|
fakeClock,
|
||||||
commands);
|
commands,
|
||||||
|
events,
|
||||||
|
new UUIDGenerator());
|
||||||
|
|
||||||
final Update update =
|
final Update update =
|
||||||
gson.fromJson(
|
gson.fromJson(
|
||||||
|
@ -159,8 +218,30 @@ class HelpIntegrationTest {
|
||||||
+ " selecting the corresponding button below \uD83D\uDC47",
|
+ " selecting the corresponding button below \uD83D\uDC47",
|
||||||
message);
|
message);
|
||||||
|
|
||||||
// TODO InputKeyboard assertions
|
final InlineKeyboardButton[][] keyboard =
|
||||||
fail("Add inputkeyboard assertions too");
|
((InlineKeyboardMarkup)
|
||||||
|
gotResponse
|
||||||
|
.getParameters()
|
||||||
|
.getOrDefault("reply_markup", new InlineKeyboardMarkup()))
|
||||||
|
.inlineKeyboard();
|
||||||
|
|
||||||
|
final List<InlineKeyboardButton> keyboardButtons =
|
||||||
|
Stream.of(keyboard).flatMap(Stream::of).toList();
|
||||||
|
|
||||||
|
assertEquals(2, keyboardButtons.size());
|
||||||
|
|
||||||
|
assertFalse(keyboardButtons.get(0).callbackData().isBlank());
|
||||||
|
assertFalse(keyboardButtons.get(1).callbackData().isBlank());
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
keyboardButtons.stream()
|
||||||
|
.map(InlineKeyboardButton::text)
|
||||||
|
.anyMatch("Select language"::equals));
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
keyboardButtons.stream()
|
||||||
|
.map(InlineKeyboardButton::text)
|
||||||
|
.anyMatch("Change language"::equals));
|
||||||
|
|
||||||
final TgChat gotChat = new QTgChat().id.eq(1111111L).findOne();
|
final TgChat gotChat = new QTgChat().id.eq(1111111L).findOne();
|
||||||
assertNotNull(gotChat);
|
assertNotNull(gotChat);
|
||||||
|
|
Loading…
Reference in New Issue