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

56
LINES

< > BotCompany Repo | #1009839 // Today Bot [OK]

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

Download Jar. Uses 4489K of libraries. Click here for Pure Java version (15097L/108K).

1  
!7
2  
3  
static Web web;
4  
static Canvas canvas;
5  
static IVar<Int> thinkAheadDays = new Var(7); // now including today
6  
static new Var<CirclesAndLines> cal;
7  
8  
svoid initWeb { web.node("Today"); }
9  
10  
p-subst {
11  
  thinkAheadDays = persistentVar("Think ahead this many days", thinkAheadDays!);
12  
  web = persistentObject("Web", Web);
13  
  web.useCLParse = false;
14  
  web.onNewLabel.add(voidfunc(WebNode node, O label) {
15  
    processNode(node);
16  
    change();
17  
  });
18  
  initWeb();
19  
  
20  
  cal.set(webToCAL(web));
21  
  canvas = showCAL(cal!, 650, 450);
22  
  calAddAutoLayoutSwitch(cal, canvas, voidfunc(CALSpringLayout layout) {
23  
    layout.desiredLength = 0.25;
24  
  }, true);
25  
  calcOnConceptChanges(1000, r { webToCAL(web, cal!, canvas) }, false);
26  
  botWithCommandList("Current Day.");
27  
}
28  
29  
answer {
30  
  if "clear" { web.clear(); initWeb(); ret "OK"; }
31  
  if "make days" { makeDays(); ret "OK"; }
32  
  if "make * days" { thinkAheadDays.set(parseInt($1)); makeDays(); ret "OK"; }
33  
}
34  
35  
sS dayName(int n) { ret n == 1 ? "Tomorrow" : "In " + n + " days"; }
36  
37  
svoid makeDays {
38  
  WebNode day = web.node("Today");
39  
  Calendar now = Calendar.getInstance();
40  
  addDate(day, now);
41  
  
42  
  for (int n = 1; n < thinkAheadDays!; n++) {
43  
    day = web_followOrMakeForwardRelation(day, "Next day", dayName(n));
44  
    now.add(Calendar.DATE, 1);
45  
    addDate(day, now);
46  
  }
47  
}
48  
49  
svoid addDate(WebNode day, Calendar now) {
50  
  S date = englishMonthName(now.get(Calendar.MONTH)+1) + " " + now.get(Calendar.DAY_OF_MONTH);
51  
  S origDate = web_stringLabel(day, 1);
52  
  if (notNullAndDifferent(origDate, date)) fail();
53  
  day.addLabel(date);
54  
}
55  
56  
svoid processNode(WebNode node) {}

Author comment

Began life as a copy of #1009831

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: #1009839
Snippet name: Today Bot [OK]
Eternal ID of this version: #1009839/26
Text MD5: 648716eac2139518441bb2931c347afd
Transpilation MD5: 1258074e425280982cb92d5e0ca68d37
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-23 02:39:41
Source code size: 1643 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 555 / 1613
Version history: 25 change(s)
Referenced in: [show references]