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

110
LINES

< > BotCompany Repo | #1001248 // Public Comm Bot with forwarding (LIVE)

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

Libraryless. Click here for Pure Java version (6379L/45K/142K).

!752

// Safe-for-everyone bots only!!
static L<S> okToForwardTo = litlist("OK Collector Bot", "Leo Bot", "Identity Manager", "Who Is Online Bot",
  "I'm Jack's Identity Manager");

// May include the privileged bots.
static Map<S, S> autoStartable = litmap(
  "Who Is Online Bot", "#1001768",
  "Reboot Bot", "#1001218",
  "OK Collector Bot", "#1001245",
  "Leo Bot", "#1001294",
  "Identity Manager", "#1001348",
  "I'm Jack's Identity Manager", "#1003170"
);

static S masterKey;

p {
  masterKey = loadSnippet("#1006007");
  //readLocally("okToForwardTo");
  
  Android3 a = new Android3("Public Comm Bot at " + getComputerID() + ".");
  a.publicOverride = true;
  a.useMultiPort = false;
  a.startPort = 4999;
  makeAndroid(a);
}

static synchronized S answer(S s) {
  new Matches m;
  
  if (match3("test", s))
    return "test!";
    
  // TODO: include a timestamp :)
  if (match3("signed *", s, m)) {
    S signed = m.unq(0);
    isSignedWithKey_verbose = true;
    if (!isSignedWithKey(signed, masterKey)) {
      print("masterKey: " + masterKey);
      ret "Sorry, bad signature.";
    }
    S line = unsign(signed);
    S answer = answerPrivileged(line);
    if (answer != null) ret answer;
  }
  
  if (match3("please forward to bot *: *", s, m)) {
    S bot = unquote(m.m[0]);
    S line = unquote(m.m[1]);
    if (!okToForwardTo.contains(bot))
      return "Can't forward to this bot, sorry.";
    if (!lineOK(bot, line))
      return "Can't forward that line, sorry.";
    ret forwardTo(bot, line);
  }
  
  return null;
}

static S answerPrivileged(S s) {
  // privileged path after auth with master key - anything goes!!
  
  new Matches m;
  
  if (match3("please forward to bot *: *", s, m)) {
    S bot = unquote(m.m[0]);
    S line = unquote(m.m[1]);
    ret forwardTo(bot, line);
  }
  
  if (match3("please start program *", s, m)) {
    S progID = m.unq(0);
    nohupJavax(progID);
    ret "OK.";
  }
  
  if (match3("please restart program *", s, m)) {
    S progID = m.unq(0);
    restartProgramID(progID);
    ret "OK.";
  }
  
  if (match3("please start bot *", s, m)) {
    S botID = m.unq(0);
    startBot(botID);
    ret "OK.";
  }
  
  if (match3("please reboot", s)) {
    ret forwardTo("Reboot Bot", "Please reboot the machine.");
  }
  
  if (match3("list bots", s))
    ret structure(fullBotScan());
    
  ret null;
}

static boolean lineOK(S bot, S line) {
  return true; // OK Collector bot is not very dangerous...
}

static S forwardTo(S bot, S line) {
  S id = autoStartable.get(bot);
  if (id != null)
    startBot(bot, id);
  ret sendToLocalBotOpt(bot, line);
}

Author comment

Began life as a copy of #1001222

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001248
Snippet name: Public Comm Bot with forwarding (LIVE)
Eternal ID of this version: #1001248/1
Text MD5: 786f95d48977d7a199586156648f8122
Transpilation MD5: f51bf93da5c2a0ec4e798a46f9a4601f
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-14 03:24:53
Source code size: 2717 bytes / 110 lines
Pitched / IR pitched: No / No
Views / Downloads: 793 / 1337
Referenced in: #1001714 - Inject Public Comm Bot to local Bot VM
#1004080 - Simple Public Comm Bot for phone - assumes phone is on private IP
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000238 - Answer for stefanreich (>> t power bot)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)