Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1003901 // scanEventLogForPosts

JavaX fragment (include)

1  
sclass ELPost {
2  
  S text;
3  
  int suggestionIndex; // Which suggestion was taken?
4  
  S suggester;
5  
  S chatTime;
6  
}
7  
8  
static L<ELPost> scanEventLogForPosts(S progID, S dialogName) {
9  
  ret scanEventLogForPosts(getProgramFile(progID, dialogName));
10  
}
11  
12  
// dialogDir can also be the log file
13  
static L<ELPost> scanEventLogForPosts(File dialogDir) {
14  
  if (dialogDir == null) null;
15  
  L<L> l = scanLog_safeUnstructure(fileFromDir(dialogDir, "event.log"));
16  
  new L<ELPost> data;
17  
  for i over l: pcall {
18  
    L a = l.get(i), prev = get(l, i-1);
19  
    if (firstIs(a, "Posting")) {
20  
      Map map = cast get(a, 2);
21  
      S text = getString(map, "Text").trim();
22  
      if (eq(text, "!delete")) { removeLast(data); continue; }
23  
      new ELPost post;
24  
      post.text = text;
25  
      post.chatTime = getString(a, 1);
26  
      pcall {
27  
        if (prev != null && firstIs(prev, "Suggestion chosen")) {
28  
          Map m = getMap(prev, 2);
29  
          S suggestion = getString(m, "Suggestion");
30  
          if (eq(suggestion, post.text)) {
31  
            post.suggestionIndex = toInt(get(m, "Row"));
32  
            post.suggester = getString(m, "Suggester");
33  
          }
34  
        }
35  
      }
36  
      data.add(post);
37  
    }
38  
  }
39  
  ret data;
40  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003901
Snippet name: scanEventLogForPosts
Eternal ID of this version: #1003901/1
Text MD5: a3e6b13fa8af56daae497ba741bbea0a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-13 19:13:44
Source code size: 1227 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 581 / 574
Referenced in: [show references]