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

48
LINES

< > BotCompany Repo | #1020368 // Greet New Live Stream Visitors & execute !say commands [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (15407L/108K).

1  
!7
2  
3  
concept User {
4  
  S channelID, name;
5  
  long greeted;
6  
}
7  
8  
concept LastMsgSeen {
9  
  S publishedAt;
10  
}
11  
12  
module GreetNewVisitors > DynPrintLog {
13  
  bool enabled, talk;
14  
  
15  
  visualize {
16  
    ret centerAndSouthWithMargins(super.visualize(),
17  
      jrightalignedline(dm_fieldCheckBox('enabled), dm_fieldCheckBox('talk)));
18  
  }
19  
  
20  
  start {
21  
    db();
22  
    dm_vmBus_onMessage_q('gotYouTubeLiveStreamMessage, voidfunc(O msg) {
23  
      if (!enabled) ret;
24  
      S publishedAt = getString(msg, 'publishedAt);
25  
      if (cmp(publishedAt, ymdWithMinuses(now()-hoursToMS(2))) < 0) ret; // general ignore-old-messages safety thing (rough)
26  
      S channelID = getString(msg, 'authorChannelId);
27  
      S name = getString(msg, 'authorDisplayName);
28  
      if (empty(channelID)) ret;
29  
      print("Got recent message from " + name + " (" + channelID + ")");
30  
      User user = uniq_sync(User, +channelID);
31  
      cset(user, +name);
32  
      if (user.greeted == 0) {
33  
        cset(user, greeted := now());
34  
        S text = "Hello " + name;
35  
        if (talk) dm_say(text); else print(text);
36  
      }
37  
      
38  
      LastMsgSeen lastSeen = uniq_sync(LastMsgSeen);
39  
      if (cmp(publishedAt, lastSeen.publishedAt) <= 0) ret;
40  
      cset(lastSeen, +publishedAt);
41  
      
42  
      S s = getString(msg, 'text);
43  
      new Matches m;
44  
      if (swic(s, "!say ", m) && talk)
45  
        dm_say(emptyIfLongerThan(80, m.rest()));
46  
    });
47  
  }
48  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020368
Snippet name: Greet New Live Stream Visitors & execute !say commands [dev.]
Eternal ID of this version: #1020368/9
Text MD5: f4e67506fe6f1b4d55c672f5ba517992
Transpilation MD5: 295a50971122b23fad699a9e6b5b6720
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-16 19:12:21
Source code size: 1425 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 359 / 561
Version history: 8 change(s)
Referenced in: [show references]