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

52
LINES

< > BotCompany Repo | #1002477 // Nasty Eleu

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

Libraryless. Click here for Pure Java version (1106L/8K/24K).

!759

// Should be an "always" bot so it notices mode changes.

static new HashMap<S, Long> on; // dialog ID -> start time

static long timeout = 5*60*1000; // 5 minutes

static L<S> nastyStuff = toLinesFullTrim([[
Go away!
What do you want?
I DON'T KNOW
I AM BORED
Do it yourself!
I'm not your bitch!
Leave me alone!
You annoy me!!
]]);

synchronized static S answer(S s) {
  S dialog = getDialogID();
  //printF("nasty: * *", dialog, s);
  if (match("mode nasty", s) || match("nasty mode", s)) {
    print("Nasty on: " + getDialogID());
    on.put(dialog, now());
  } else if (isNasty() && (match("mode *", s) || match("* mode", s) || match("help", s) || match("exit", s) || match("stop", s))) {
    print("Nasty off: " + dialog);
    on.remove(dialog);
    ret "OK, exiting nasty mode.";
  } else if (match("mode", s) && isNasty())
    ret "I'm in " + quote("nasty") + " mode (" + formatSnippetID(getProgramID()) + ")";
  
  if (!isNasty()) null;
  
  ret randomElement(nastyStuff);
}

static boolean isNasty() {
  cleanUpMap();
  ret on.containsKey(getDialogID());
}

// remove the expired entries
static void cleanUpMap() {
  new HashMap<S, Long> newMap;
  for (S dialogID : keys(on)) {
    long time = on.get(dialogID);
    if (!isExpired(time, timeout))
      newMap.put(dialogID, time);
  }
  on = newMap;
}

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: #1002477
Snippet name: Nasty Eleu
Eternal ID of this version: #1002477/1
Text MD5: f1f8826ee2a1dc7766ea0da2deb8cd10
Transpilation MD5: b0d97daeb72f791d3a445d2c08ce7c0f
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-26 19:43:49
Source code size: 1366 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 646 / 1042
Referenced in: [show references]