예제 #1
0
파일: IRC.java 프로젝트: speak2me/BotLibre
  /** Output the vertex to text. */
  public void output(Vertex output) {
    if (!isEnabled()) {
      return;
    }

    Vertex sense = output.mostConscious(Primitive.SENSE);
    // If not output to IRC, ignore.
    if ((sense == null) || (!getPrimitive().equals(sense.getData()))) {
      return;
    }
    try {
      if (getChannel() != null) {
        log("Output:", Bot.FINE, output);
        getChannel().sendMessage(printInput(output) + "\n");
        for (ChannelListener listener : getChannelListeners()) {
          ChannelEvent event =
              new ChannelEvent(getChannel(), getNick(), getUserName(), printInput(output));
          listener.onMessage(event);
        }
        this.lastUsers.remove(0);
        this.lastUsers.add(getNick());
      }
    } catch (Exception exception) {
      log(exception);
    }
  }
예제 #2
0
파일: IRC.java 프로젝트: speak2me/BotLibre
 /** Set the current conversation. */
 public void setConversation(Vertex conversation) {
   if (conversation == null) {
     this.conversation = null;
   } else {
     this.conversation = conversation.getId();
   }
 }
예제 #3
0
파일: IRC.java 프로젝트: speak2me/BotLibre
 /** Process the text sentence. */
 public void inputSentence(
     String text, String userName, List<String> targetUserNames, Network network) {
   Vertex input = createInputSentence(text.trim(), network);
   input.addRelationship(Primitive.INSTANTIATION, Primitive.CHAT);
   // Process speaker.
   Vertex user = network.createSpeaker(userName);
   input.addRelationship(Primitive.SPEAKER, user);
   // Process target speakers.
   Set<String> uniqueTargetUserNames = new HashSet<String>();
   for (String targetUserName : targetUserNames) {
     if (!targetUserName.equals(userName) && !uniqueTargetUserNames.contains(targetUserName)) {
       uniqueTargetUserNames.add(targetUserName);
       Vertex targetUser = null;
       if (targetUserName.equals(getNick()) || targetUserName.equals(getNickAlt())) {
         targetUser = network.createVertex(Primitive.SELF);
       } else {
         targetUser = network.createSpeaker(targetUserName);
       }
       input.addRelationship(Primitive.TARGET, targetUser);
     }
   }
   user.addRelationship(Primitive.INPUT, input);
   // Process conversation.
   Vertex conversation = getConversation(network);
   if (conversation == null) {
     conversation = network.createInstance(Primitive.CONVERSATION);
     conversation.addRelationship(Primitive.TYPE, Primitive.CHAT);
     setConversation(conversation);
     conversation.addRelationship(Primitive.SPEAKER, Primitive.SELF);
     for (String eachUser : getUsers()) {
       conversation.addRelationship(Primitive.SPEAKER, network.createSpeaker(eachUser));
     }
   }
   Language.addToConversation(input, conversation);
   network.save();
   getBot().memory().addActiveMemory(input);
 }