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

77
LINES

< > BotCompany Repo | #1025905 // Asker Bot [dev.]

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

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

1  
!7
2  
3  
concept Msg {
4  
  long msgID, channelID, userID;
5  
  long date, edited; // epochSeconds
6  
  S text;
7  
  
8  
  S text() { ret text; }
9  
}
10  
11  
concept HasMsg {
12  
  new Ref<Msg> msg;
13  
  
14  
  S text() { ret msg->text; }
15  
}  
16  
17  
concept Question > HasMsg {
18  
  Answer acceptedAnswer;
19  
}
20  
21  
concept Answer > HasMsg {
22  
  Question question;
23  
}
24  
25  
standardBot1 Asker {
26  
  init {
27  
    dbIndexing(Msg, 'msgID, Msg, 'channelID);
28  
    thread {
29  
      temp enter();
30  
      for (Question q)
31  
        print(q.msg->text + " => " + mapMethod text(linesAfterQuestion(q)));
32  
    }
33  
  }
34  
  
35  
  allServers {
36  
    !include #1025906 // DiscordScanner
37  
    
38  
    L<Msg> linesAfterQuestion(Question q) {
39  
      long channelID = q.msg->channelID;
40  
      if (channelID == 0) null;
41  
      L<Msg> l = conceptsWhere(Msg, +channelID);
42  
      l = takeFirst(10, sortByField date(filter(l, m -> m.date > q.msg->date)));
43  
      ret l;
44  
    }
45  
    
46  
    L<Question> openQuestionsInChannel(long channelID) {
47  
      ret sortedByField date(filter(conceptsWhere(Question, acceptedAnswer := null),
48  
        q -> q.msg->channelID == channelID));
49  
    }
50  
  }
51  
  
52  
  processSimplified {
53  
    optPar Message msg;
54  
    optPar long channelID;
55  
    optPar long userID;
56  
    Msg storedMsg = pairA(storeMsg(msg));
57  
    
58  
    if null (s = dropMyPrefixOrNull(s)) null;
59  
    
60  
    if "ask me something" {
61  
      S q = "Is " + random(100) + " bigger than " + random(100) + "?";
62  
      postInChannel(channelID, discordAt(userID) + " " + q, mm -> {
63  
        Msg stored = pairA(storeMsg(mm));
64  
        printStruct("New question: " + cnew Question(msg := stored));
65  
      });
66  
      null;
67  
    }
68  
    
69  
    L<Question> qs = openQuestionsInChannel(channelID);
70  
    Question q = last(qs);
71  
    if (q != null) {
72  
      Answer a = cnew Answer(msg := storedMsg);
73  
      cset(q, acceptedAnswer := a);
74  
      ret "Assuming " + quote(s) + " is the answer to " + quote(q.text());
75  
    }
76  
  }
77  
}

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: #1025905
Snippet name: Asker Bot [dev.]
Eternal ID of this version: #1025905/18
Text MD5: 32a95923943bb14760c2fcc4ef2adaf8
Transpilation MD5: 180277dda3fbc1f641fd5f43b83279fd
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 13:36:43
Source code size: 1921 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 268 / 5353
Version history: 17 change(s)
Referenced in: [show references]