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

58
LINES

< > BotCompany Repo | #1007829 // Celestia Slack Bot [LIVE] - can recognize greetings and say "hi!"

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

Libraryless. Click here for Pure Java version (8819L/62K/194K).

!7

!include #1007827 // Slack Bot

sbool doSlack = true;

static SelectBot<Bool> greetBot;

p {
  db();
  greetBot = uniq(SelectBot);
  
  slackSpeed = 1000;
  if (doSlack)
    initSlackBot();
  dediSay("Booting...");
  
  dediSay("Yo, back online!");
  if (doSlack)
    slackBotLoop();
}

answer {
  s = trim(s);
  if (eq(s, "!data"))
    ret struct(greetBot);
  if (eq(s, "!reload")) {
    thread { sleepSeconds(2); restart(); }
    ret "krasser reload";
  }
  if (startsWithWord(s, "!greet", m)) {
    greetBot.put($1, true);
    ret "ok";
  }
  if (startsWithWord(s, "!nogreet", m)) {
    greetBot.put($1, false);
    ret "ok";
  }
  if (eq(s, "!source"))
    ret progLink();
  if (eq(s, "!help"))
    ret autoHelp();
  //if "hi celestia" ret "hi!";
  if (isTrue(greetBot.get(s)))
    ret s + " => hi!";
}

sS autoHelp() {
  new L<S> cmds;
  L<S> tok = javaTokMe();
  for (S pat : toLinesFullTrim([[
    startsWithWord(s, <quoted>,
    eq(s, <quoted>)
  ]]))
    for (int i : jfindAll(tok, pat))
      cmds.add(trim(unquote(tok.get(i+8))));
  ret "Commands: " + join(" ", cmds);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1007829
Snippet name: Celestia Slack Bot [LIVE] - can recognize greetings and say "hi!"
Eternal ID of this version: #1007829/16
Text MD5: 4f61c93e1fec86c4a777e62f134faf35
Transpilation MD5: c54bff937faa306ed63c1f8a19ab3a20
Author: stefan
Category: javax / slack bots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-23 12:43:44
Source code size: 1142 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 653 / 1496
Version history: 15 change(s)
Referenced in: #1008059 - Celestia Slack Bot 2 [LIVE, multiple modules]
#1013777 - Electron Slack Bot [dev.]