!752 p { L msgs = getLastMsgs(); // must be in order for (Msg msg : msgs) onMsg(msg); now(); while true { msgs = getMoreMsgs(); for (Msg msg : msgs) onMsg(msg); if (!msgs.isEmpty()) now(); sleepSeconds(10); } } static void onMsg(Msg msg) { if (isQuestion(msg)) questions.add(msg); else if (isAnswer(msg)) { Msg q = getQuestion(msg); questions.remove(q); if (current == q) current = null; } } static void now() { if (current != null) ret; // still waiting for my own answer to appear if (!questions.isEmpty()) { current = questions.get(0); questions.remove(0); postAnswer(current); } } static Msg getQuestion(Msg a) { // TODO } static void postAnswer(Msg q) { // call the bot // if answer == null: // if we're directly targeted in the question (@blabot), // say "i don't know". // if we're not targeted, delete the question from list. // if there is an answer, post the answer with time stamp of question. }