コード例 #1
0
 public String getDisplayText(Interaction interaction)
     throws ContextDataRequired, GeneralInteractionError, AbortInteraction {
   // TOOD: Pagination support...
   // see if we have an active paginator
   PaginationAssistant paginator =
       interaction.getContextData(
           PaginationAssistant.class, interaction, getTranslationKey(interaction) + "_paginator");
   if (paginator != null) {
     return paginator.getDisplayText();
   } else {
     // generate page content, and if there's too much, then activate a paginator..
     if (hasChoices) {
       Choices choices = Choices.getChoices(this, interaction);
       if (choices == null) choices = generateChoices(interaction);
       String text = generateDisplayBody(interaction) + "\n";
       String choiceText =
           interaction.parseMessage(StringUtils.join(choices.generateChoiceList(), ""));
       if (text.split("\n").length + choiceText.split("\n").length + 1 > maxLines) {
         // we'll need a paginator
         paginator = new PaginationAssistant(choiceText, maxLines, text);
         interaction.context.put(getTranslationKey(interaction) + "_paginator", paginator);
         return paginator.getDisplayText();
       } else return text + "\n" + choiceText;
     } else {
       String text = generateDisplayBody(interaction);
       if (text.split("\n").length > maxLines) {
         paginator = new PaginationAssistant(text, maxLines, "");
         interaction.context.put(getTranslationKey(interaction) + "_paginator", paginator);
         return paginator.getDisplayText();
       } else return text;
     }
   }
 }
コード例 #2
0
 public String inputHandler(Interaction interaction, Object data)
     throws ContextDataRequired, GeneralInteractionError, AbortInteraction {
   // first, check for pagination...
   PaginationAssistant paginator =
       interaction.getContextData(
           PaginationAssistant.class, interaction, getTranslationKey(interaction) + "_paginator");
   if (paginator != null) {
     boolean paginationCommand = paginator.processPageCommand(data.toString());
     if (paginationCommand) {
       interaction.pageWaitingForInput = true;
       return null;
     } else {
       // it wasn't a pagination command, so we kill the paginator
       // so we don't end up with a cache of old data if the player
       // comes back to this interaction page
       interaction.context.remove(getTranslationKey(interaction) + "_paginator");
     }
   }
   // if we don't have pagination (or it wasn't a pagination command..)
   //  see if we are using a choice model, or straight to direct input
   if (hasChoices) {
     Choices choices = Choices.getChoices(this, interaction);
     return choices.takeAction(this, interaction, data);
   } else return acceptValidatedInput(interaction, data);
 }