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

110
LINES

< > BotCompany Repo | #1025807 // Channel History DB Bot [OK]

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

Uses 5909K of libraries. Click here for Pure Java version (20633L/113K).

!7

concept Msg {
  long msgID, channelID, userID;
  long date, edited; // epochSeconds
  S text;
}

standardBot1 EAMBot {
  init {
    dbIndexing(Msg, 'msgID);
    
    dm_vmBus_onMessage_q discord_onMessageReceived(voidfunc(O module, O event) {
      if (!enabled || !indexAllIncoming || !dm_isMe(module)) ret;
      Message message = cast rcall getMessage(event);
      storeMsg(message);
    });
  }
  
  allServers {
    bool indexAllIncoming = true;
    
    !include #1025906 // DiscordScanner 
    
    enhanceFrame {
      internalFrameMenuItem(f, "Show word list", rThread {
        S list = makeWordsList();
        showText_fast_noWrap("Word list (" + countLines(list) + ")", list);
      });
    }
  
    S makeWordsList() {
      new Map<S, Long> map; // word -> date
      new MultiSet<S> ms; // word count
      for ping (Msg msg : sortedByField date(list(Msg))) {
        Long date = msg.date;
        for ping (S word : words2_notNextToNumbers_plusApostrophe(msg.text)) {
          map.put(word, date);
          ms.add(word);
        }
      }
      ret mapToLines(keysSortedByValuesDesc(map), w -> {
        int count = ms.get(w);
        ret count == 1 ? w : count + " " + w;
      });
    }
  }

  sync S processSimplifiedLine(S s, O... _) {
    try answer super.processSimplifiedLine(s, _);
    
    if ((s = dropMyPrefixOrNull(s)) == null) null;
    
    optPar MessageChannel channel;
    
    if "upload word list" {
      S list = makeWordsList();
      editMechList("NGB Word List", list);
      ret "OK. " + nWords(countLines(list));
    }
    
    if "retrieve history" {
      setAll(new DiscordScanner, +channel, incremental := true).run();
      ret "Retrieving...";
    }
    
    if "retrieve full channel" {
      setAll(new DiscordScanner, +channel, incremental := false).run();
      ret "Retrieving...";
    }
    
    if "retrieve all channels" {
      L<TextChannel> l = getGuild().getTextChannels();
      
      new AtomicInt counter;
      Runnable whenDone = r {
        if (incAtomicInt(counter) == l(l))
          postInChannel(channel, "Incremental scan of " + nChannels(l) + " done");
      };
      
      for ping (TextChannel c : l)
        setAll(new DiscordScanner, channel := c, incremental := true,
          postResult := false, +whenDone).run();
    }
    
    if "mega retrieve" {
      try answer checkAuth(_);
      L<TextChannel> l = getGuild().getTextChannels();
      
      new AtomicInt counter;
      Runnable whenDone = r {
        if (incAtomicInt(counter) == l(l))
          postInChannel(channel, "Full scan of " + nChannels(l) + " done");
      };
      
      for ping (TextChannel c : l)
        setAll(new DiscordScanner, channel := c, incremental := false,
          postResult := false, +whenDone).run();
    }
    
    if "db size" ret nMessages(countConcepts(Msg));
    
    if "random message" {
      Msg msg = random(list(Msg));
      ret msg == null ? "No messages" : "[" + msg.msgID + "] " + msg.text;
    }

    null;
  }
}

Author comment

Began life as a copy of #1025795

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025807
Snippet name: Channel History DB Bot [OK]
Eternal ID of this version: #1025807/58
Text MD5: 0cafab3a7bbe35b728263cd736828921
Transpilation MD5: cb45085c75d24aaed69cfc8f6e4cd2c3
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-29 21:44:34
Source code size: 3119 bytes / 110 lines
Pitched / IR pitched: No / No
Views / Downloads: 250 / 5888
Version history: 57 change(s)
Referenced in: [show references]