!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())); }); } }