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

166
LINES

< > BotCompany Repo | #1021628 // Gazelle: Lines [CRUD, moving away from Discord focus]

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

Libraryless. Click here for Pure Java version (29471L/188K).

!7

set flag makeConceptsTable_debug.

concept User {
  long userID;
  S name;
  
  toString { ret name; }
}

concept Channel {
  long channelID;
  S name;
  
  toString { ret name; }
}

sclass Reaction {
  long created;
  User user;
  S emoji;
  
  toString { ret emoji + " (" + user + ")"; }
}

concept Line {
  S globalID /*= aGlobalIDUnlessLoading()*/; // deprecated
  GlobalID globalIDObj = aGlobalIDObj();
  long msgID;
  S context;
  bool bot, isPrivate;
  Channel channel;
  User author;
  S text;
  S editedText;
  L<Reaction> reactions;
  S extraInfo; // like images posted
  
  long channelID() {
    ret channel == null ? 0 : channel.channelID;
  }
  
  S userName() {
    ret author == null ? null : author.name;
  }
  
  // save space, transition
  void _doneLoading2() {
    if (empty(reactions)) _setField(reactions := null);
    if (globalID != null) {
      _setField(globalIDObj := globalIDObj(globalID));
      _setField(globalID := null);
    }
  }
}

module GLines > DynCRUD<Line> {
  S saveProfile;
  
  start {
    dbIndexing(Line, 'msgID, Line, 'context, Line, 'globalIDObj);
    
    conceptsObject().saveWrapper = voidfunc(Runnable r) {
      setField(saveProfile := profileThisThreadToString(r));
    };
    addCountToName();
  }
  
  // API
  
  User uniqUser(long userID) {
    ret uniq_sync User(+userID);
  }
  
  // old
  Channel uniqChannel(long channelID) {
    ret uniq_sync Channel(+channelID);
  }
  
  // new
  Channel uniqChannel(S channelName) {
    long channelID = md5_long(channelName);
    ret uniq_sync Channel(+channelID, name := channelName);
  }
  
  Reaction nuReaction(O... params) {
    ret nu Reaction(params);
  }
  
  long getChannelID(S name) {
    ret getLongOrZero channelID(conceptWhere Channel(name := dropPrefix("#", name)));
  }
  
  Line lastLineInChannel(long channelID) {
    Channel channel = conceptWhere Channel(+channelID);
    if (channel == null) null;
    ret last(conceptsWhere Line(+channel));
  }
  
  Line nextToLastLineInChannel(long channelID) {
    Channel channel = conceptWhere Channel(+channelID);
    if (channel == null) null;
    ret nextToLast(asList(conceptsWhere Line(+channel)));
  }
  
  L<Line> linesInChannelBy(long channelID, long userID) {
    Channel channel = conceptWhere Channel(+channelID);
    if (channel == null) null;
    User user = conceptWhere User(+userID);
    if (user == null) null;
    ret asList(conceptsWhere Line(+channel, author := user));
  }
  
  L<Line> linesBy(long userID) {
    User user = conceptWhere User(+userID);
    if (user == null) null;
    ret asList(conceptsWhere Line(author := user));
  }
  
  L<Line> linesInChannel(long channelID) {
    Channel channel = conceptWhere Channel(+channelID);
    if (channel == null) null;
    ret asList(conceptsWhere Line(+channel));
  }
  
  long idForChannel(S name) {
    ret getChannelID(name);
  }
  
  // attention: Discord user names may change
  long idForUser(S name) {
    ret getLong userID(conceptWhere User(+name));
  }
  
  int monologueLength(long channelID) {
    L<Line> lines = linesInChannel(channelID);
    int n = 0;
    while (n < l(lines) && lines.get(l(lines)-1-n).bot) ++n;
    ret n;
  }
  
  Line lineForID(long msgID) {
    ret conceptWhere Line(+msgID);
  }
  
  Line lineForContext(S context) {
    ret conceptWhere Line(+context);
  }
  
  Line lineForGlobalID(S globalID) {
    ret conceptWhere Line(globalIDObj := globalIDObj(globalID));
  }
  
  L<Line> botLines() {
    ret asList(conceptsWhere Line(bot := true));
  }
  
  L<Long> allChannelIDs() {
    ret collect channelID(list(Channel));
  }
  
  L<Line> linesModifiedAfter(long date) {
    ret filter(concepts(), line -> line._modified >= date);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021628
Snippet name: Gazelle: Lines [CRUD, moving away from Discord focus]
Eternal ID of this version: #1021628/58
Text MD5: 854b88bceae24d5a572b6871c8a1ebb2
Transpilation MD5: 84261de7747336f037a59607d0dfafa6
Author: stefan
Category: javax / discord
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-12 04:33:07
Source code size: 3874 bytes / 166 lines
Pitched / IR pitched: No / No
Views / Downloads: 538 / 19358
Version history: 57 change(s)
Referenced in: [show references]