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).

!7

concept User {
  S channelID, name;
  long greeted;
}

concept LastMsgSeen {
  S publishedAt;
}

module GreetNewVisitors > DynPrintLog {
  bool enabled, talk;
  
  visualize {
    ret centerAndSouthWithMargins(super.visualize(),
      jrightalignedline(dm_fieldCheckBox('enabled), dm_fieldCheckBox('talk)));
  }
  
  start {
    db();
    dm_vmBus_onMessage_q('gotYouTubeLiveStreamMessage, voidfunc(O msg) {
      if (!enabled) ret;
      S publishedAt = getString(msg, 'publishedAt);
      if (cmp(publishedAt, ymdWithMinuses(now()-hoursToMS(2))) < 0) ret; // general ignore-old-messages safety thing (rough)
      S channelID = getString(msg, 'authorChannelId);
      S name = getString(msg, 'authorDisplayName);
      if (empty(channelID)) ret;
      print("Got recent message from " + name + " (" + channelID + ")");
      User user = uniq_sync(User, +channelID);
      cset(user, +name);
      if (user.greeted == 0) {
        cset(user, greeted := now());
        S text = "Hello " + name;
        if (talk) dm_say(text); else print(text);
      }
      
      LastMsgSeen lastSeen = uniq_sync(LastMsgSeen);
      if (cmp(publishedAt, lastSeen.publishedAt) <= 0) ret;
      cset(lastSeen, +publishedAt);
      
      S s = getString(msg, 'text);
      new Matches m;
      if (swic(s, "!say ", m) && talk)
        dm_say(emptyIfLongerThan(80, m.rest()));
    });
  }
}

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: 268 / 440
Version history: 8 change(s)
Referenced in: [show references]