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).

!752

static boolean activated;
static long lastAction;
static long idleTimeout = 5*60*1000; // 5 minutes

static S data;

p {
  load("data");
  load("lastAction");
  load("activated");
}

synchronized answer {
  if (!tb()) null;
  
  // activating commands
  
  if "consider the string *" {
    activate();
    data = m.unq(0);
    save("data");
    ret "OK. " + someInfo();
  }
  
  if "done with the string" {
    if (!activated) ret "Yeah i know.";
    data = null;
    save("data");
    deactivate();
    ret "OK, " + getName() + " deactivating.";
  }
  
  if (!activated || data == null) null;
  
  if (isExpired(lastAction, idleTimeout)) {
    deactivate();
    null;
  }
  
  if "reverse"
    ret setData(reverseString(data));
    
  if "show"
    ret show();
    
  if "length"
    ret l(data) + " chars";
}

static S someInfo() {
  if (data == null) ret "";
  ret "Got " + l(data) + " chars.";
}

static void activate() {
  activated = true;
  save("activated");
  lastAction = now();
  save("lastAction");
}

static void deactivate() {
  activated = false;
  save("activated");
  data = null;
  save("data");
}

static S setData(S s) {
  data = s;
  save("data");
  ret "OK. Got " + show();
}

static S show() {
  if (data == null) ret "No data";
  S s = quote(shorten(data, 100));
  if (l(data) > 100) s += " (" + l(data) + " chars)";
  ret s;
}

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: 706 / 834
Referenced in: [show references]