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

56
LINES

< > BotCompany Repo | #1001747 // Snippet Title Bot

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

Download Jar. Libraryless. Click here for Pure Java version (9690L/68K).

// Logic: Checks every 5 minutes and clears full cache when
// anything changed in the DB. So it's as good as traffic-free
// when the DB is not changing.

!7

static int updateInterval = 5*60000;
static long lastVersionCount;

static new Map<S, S> titles;

p {
  startBot("Version Count Bot", "#1001745");
  makeAndroid3("Snippet Title Bot.");
  updateLoop();
}

static void update() {
  new Matches m;
  if (match3("version count: *", sendToLocalBot_cached("Version Count Bot", "get version count"), m)) {
    long count = parseLong(m.get(0));
    if (count != lastVersionCount) {
      lastVersionCount = count;
      clear();
    }
  }
}

static synchronized S answer(S s) {
  new Matches m;
  if (match3("what is the title of snippet *", s, m)) {
    S snippetID = formatSnippetID(m.unq(0));
    S title = titles.get(snippetID);
    if (title == null) {
      title = getSnippetTitle(snippetID);
      if (title == null) ret "null";
      titles.put(snippetID, title);
    }
    ret format("The title of snippet * is *.", snippetID, title);
  }
  
  if (match3("clear snippet title cache", s, m)) {
    clear();
    ret "OK.";
  }
  
  if (match3("get snippet title cache size", s, m)) {
    ret "Cache entries: " + titles.size();
  }
  
  ret null;
}

static synchronized void clear() {
  titles.clear();
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001747
Snippet name: Snippet Title Bot
Eternal ID of this version: #1001747/4
Text MD5: 303235a90f2ad65c7ab8d7ceed43e2db
Transpilation MD5: 4a9099e2d2463357b25272dd3e4a9a83
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-12-14 04:28:26
Source code size: 1367 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 745 / 5526
Version history: 3 change(s)
Referenced in: #1001915 - Slack Bot! (not used anymore. relp.slack.com, #talkingbots, can be redirected to other channel)
#1001966 - Start Snippet Title Bot
#1002005 - Language detector frame work
#1002009 - Language detector - find shortest code (developing)
#1002079 - Snippet MD5 Bot (seems to work)
#1002278 - Eleutheria Main 2 (developing)
#1002577 - getSnippetTitle_overBot
#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)