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

88
LINES

< > BotCompany Repo | #1002404 // Store messages bot (optimized)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2397L/15K/51K).

1  
!752
2  
static new MultiMap<S, Line> map;
3  
static class Line { 
4  
  S text;
5  
  S timestamp;
6  
  
7  
  Line(){
8  
  
9  
  }
10  
  *(S *text, S *timestamp) {}
11  
}
12  
13  
static boolean saveLater;
14  
15  
p{
16  
  load("#1002356", "map");
17  
  
18  
  thread "msgs saver" {
19  
    while (licensed()) {
20  
      saveIt();
21  
      sleepSeconds(60);
22  
    }
23  
  }
24  
  
25  
  makeBot("Store messages bot");
26  
}
27  
28  
synchronized answer{
29  
  S username = "";
30  
  if(getUserName() == null){
31  
    username = "anonymous";
32  
  }else{
33  
    username = getUserName();
34  
  }
35  
  if(matchStart("list all messages from *", s, m)){
36  
    S user = m.unq(0);
37  
    boolean isMe = isMe(user);
38  
    if (isMe) user = getUserName();
39  
    ret structure(map.get(user));
40  
  }
41  
  if(match("list all users who said something", s)){
42  
    ret structure(map.keySet());
43  
  }
44  
  if(matchStart("did * say something about *", s, m)){
45  
    S user = m.unq(0);
46  
    boolean isMe = isMe(user);
47  
    if (isMe) user = getUserName();
48  
    if(map.containsKey(user)){
49  
      List<Line> list = map.get(user);
50  
      int times = 0;
51  
      L<S> lolist = new L;
52  
      for (int i = l(list)-1; i >= 0; i--) {
53  
        if (indexOfIgnoreCase(list.get(i).text, m.unq(1)) >= 0){
54  
          times = times + 1;
55  
          lolist.add(list.get(i).text);
56  
        }
57  
      }
58  
      if (times == 0){
59  
        ret (isMe ? "You" : user) + " did not say anything about that.";
60  
      }else{
61  
        ret lolist + "\n" + times +" results found";
62  
      }
63  
    }else{
64  
      ret (isMe ? "You" : user) + " did not say anything yet.";
65  
    }
66  
  } 
67  
  Line line = new Line(s,getSlackTS());
68  
  map.put(username, line);
69  
  saveLater = true;
70  
}
71  
72  
synchronized static void saveIt() {
73  
  if (saveLater) {
74  
    time {
75  
      print(programID() + ": Saving msgs.");
76  
      save("#1002356", "map");
77  
    }
78  
    saveLater = false;
79  
  }
80  
}
81  
82  
static void cleanUp() {
83  
  saveIt();
84  
}
85  
86  
static boolean isMe(S user) {
87  
  ret eqic(user, "I") || eqic(user, "me");
88  
}

Author comment

Began life as a copy of #1002356

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002404
Snippet name: Store messages bot (optimized)
Eternal ID of this version: #1002404/1
Text MD5: 4a52009c2f9e3268f5eac7fe67f3c8d1
Transpilation MD5: 18743e12d97b200302072e3e11b9af2d
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-22 19:50:25
Source code size: 1930 bytes / 88 lines
Pitched / IR pitched: No / No
Views / Downloads: 757 / 1313
Referenced in: [show references]