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

82
LINES

< > BotCompany Repo | #1003003 // Strings Bot

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

Libraryless. Click here for Pure Java version (1898L/12K/41K).

1  
!752
2  
3  
static boolean activated;
4  
static long lastAction;
5  
static long idleTimeout = 5*60*1000; // 5 minutes
6  
7  
static S data;
8  
9  
p {
10  
  load("data");
11  
  load("lastAction");
12  
  load("activated");
13  
}
14  
15  
synchronized answer {
16  
  if (!tb()) null;
17  
  
18  
  // activating commands
19  
  
20  
  if "consider the string *" {
21  
    activate();
22  
    data = m.unq(0);
23  
    save("data");
24  
    ret "OK. " + someInfo();
25  
  }
26  
  
27  
  if "done with the string" {
28  
    if (!activated) ret "Yeah i know.";
29  
    data = null;
30  
    save("data");
31  
    deactivate();
32  
    ret "OK, " + getName() + " deactivating.";
33  
  }
34  
  
35  
  if (!activated || data == null) null;
36  
  
37  
  if (isExpired(lastAction, idleTimeout)) {
38  
    deactivate();
39  
    null;
40  
  }
41  
  
42  
  if "reverse"
43  
    ret setData(reverseString(data));
44  
    
45  
  if "show"
46  
    ret show();
47  
    
48  
  if "length"
49  
    ret l(data) + " chars";
50  
}
51  
52  
static S someInfo() {
53  
  if (data == null) ret "";
54  
  ret "Got " + l(data) + " chars.";
55  
}
56  
57  
static void activate() {
58  
  activated = true;
59  
  save("activated");
60  
  lastAction = now();
61  
  save("lastAction");
62  
}
63  
64  
static void deactivate() {
65  
  activated = false;
66  
  save("activated");
67  
  data = null;
68  
  save("data");
69  
}
70  
71  
static S setData(S s) {
72  
  data = s;
73  
  save("data");
74  
  ret "OK. Got " + show();
75  
}
76  
77  
static S show() {
78  
  if (data == null) ret "No data";
79  
  S s = quote(shorten(data, 100));
80  
  if (l(data) > 100) s += " (" + l(data) + " chars)";
81  
  ret s;
82  
}

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: #1003003
Snippet name: Strings Bot
Eternal ID of this version: #1003003/1
Text MD5: a7a0a4b8a0e73951aefb5a6b208ec3a9
Transpilation MD5: 336b8927a9ccf89f25e52a6383ec6f8b
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-17 21:25:48
Source code size: 1438 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 642 / 741
Referenced in: [show references]