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

30
LINES

< > BotCompany Repo | #1002457 // manageSnippetList - convenient way of managing a list of snippets (e.g. "Turing tests")

JavaX fragment (include)

1  
static synchronized S manageSnippetList(S s, S name, S varName) {
2  
  L<S> list = (L) get(main.class, varName);
3  
  new Matches m;
4  
  
5  
  if (match("list " + plural(name), s))
6  
    ret structure(list);
7  
    
8  
  if (match("how many " + plural(name), s))
9  
    ret str(l(list));
10  
    
11  
  if (webAuthed() || litlist("yes", "partially").contains(isTrustedUser())) {
12  
    if (match("add " + name + " *", s, m)) {
13  
      S id = m.fsi(0);
14  
      list.add(id);
15  
      save(varName);
16  
      ret "OK, " + name + " " + id + " added. List size now: " + l(list);
17  
    }
18  
    
19  
    if (match("remove " + name + " *", s, m)) {
20  
      S id = m.fsi(0);
21  
      int idx = list.indexOf(id);
22  
      if (idx < 0) ret id + " is not a " + name;
23  
      list.remove(idx);
24  
      save(varName);
25  
      ret "OK, " + name + " " + id + " removed. List size now: " + l(list);
26  
    }
27  
  }
28  
  
29  
  ret null;
30  
}

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: #1002457
Snippet name: manageSnippetList - convenient way of managing a list of snippets (e.g. "Turing tests")
Eternal ID of this version: #1002457/1
Text MD5: 79758c8ec1bac2e470ec194228fe9904
Author: stefan
Category: eleu
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-05 03:07:58
Source code size: 875 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 654 / 638
Referenced in: [show references]