Libraryless. Click here for Pure Java version (29471L/188K).
1 | !7 |
2 | |
3 | set flag makeConceptsTable_debug. |
4 | |
5 | concept User { |
6 | long userID; |
7 | S name; |
8 | |
9 | toString { ret name; } |
10 | } |
11 | |
12 | concept Channel { |
13 | long channelID; |
14 | S name; |
15 | |
16 | toString { ret name; } |
17 | } |
18 | |
19 | sclass Reaction { |
20 | long created; |
21 | User user; |
22 | S emoji; |
23 | |
24 | toString { ret emoji + " (" + user + ")"; } |
25 | } |
26 | |
27 | concept Line { |
28 | S globalID /*= aGlobalIDUnlessLoading()*/; // deprecated |
29 | GlobalID globalIDObj = aGlobalIDObj(); |
30 | long msgID; |
31 | S context; |
32 | bool bot, isPrivate; |
33 | Channel channel; |
34 | User author; |
35 | S text; |
36 | S editedText; |
37 | L<Reaction> reactions; |
38 | S extraInfo; // like images posted |
39 | |
40 | long channelID() { |
41 | ret channel == null ? 0 : channel.channelID; |
42 | } |
43 | |
44 | S userName() { |
45 | ret author == null ? null : author.name; |
46 | } |
47 | |
48 | // save space, transition |
49 | void _doneLoading2() { |
50 | if (empty(reactions)) _setField(reactions := null); |
51 | if (globalID != null) { |
52 | _setField(globalIDObj := globalIDObj(globalID)); |
53 | _setField(globalID := null); |
54 | } |
55 | } |
56 | } |
57 | |
58 | module GLines > DynCRUD<Line> { |
59 | S saveProfile; |
60 | |
61 | start { |
62 | dbIndexing(Line, 'msgID, Line, 'context, Line, 'globalIDObj); |
63 | |
64 | conceptsObject().saveWrapper = voidfunc(Runnable r) { |
65 | setField(saveProfile := profileThisThreadToString(r)); |
66 | }; |
67 | addCountToName(); |
68 | } |
69 | |
70 | // API |
71 | |
72 | User uniqUser(long userID) { |
73 | ret uniq_sync User(+userID); |
74 | } |
75 | |
76 | // old |
77 | Channel uniqChannel(long channelID) { |
78 | ret uniq_sync Channel(+channelID); |
79 | } |
80 | |
81 | // new |
82 | Channel uniqChannel(S channelName) { |
83 | long channelID = md5_long(channelName); |
84 | ret uniq_sync Channel(+channelID, name := channelName); |
85 | } |
86 | |
87 | Reaction nuReaction(O... params) { |
88 | ret nu Reaction(params); |
89 | } |
90 | |
91 | long getChannelID(S name) { |
92 | ret getLongOrZero channelID(conceptWhere Channel(name := dropPrefix("#", name))); |
93 | } |
94 | |
95 | Line lastLineInChannel(long channelID) { |
96 | Channel channel = conceptWhere Channel(+channelID); |
97 | if (channel == null) null; |
98 | ret last(conceptsWhere Line(+channel)); |
99 | } |
100 | |
101 | Line nextToLastLineInChannel(long channelID) { |
102 | Channel channel = conceptWhere Channel(+channelID); |
103 | if (channel == null) null; |
104 | ret nextToLast(asList(conceptsWhere Line(+channel))); |
105 | } |
106 | |
107 | L<Line> linesInChannelBy(long channelID, long userID) { |
108 | Channel channel = conceptWhere Channel(+channelID); |
109 | if (channel == null) null; |
110 | User user = conceptWhere User(+userID); |
111 | if (user == null) null; |
112 | ret asList(conceptsWhere Line(+channel, author := user)); |
113 | } |
114 | |
115 | L<Line> linesBy(long userID) { |
116 | User user = conceptWhere User(+userID); |
117 | if (user == null) null; |
118 | ret asList(conceptsWhere Line(author := user)); |
119 | } |
120 | |
121 | L<Line> linesInChannel(long channelID) { |
122 | Channel channel = conceptWhere Channel(+channelID); |
123 | if (channel == null) null; |
124 | ret asList(conceptsWhere Line(+channel)); |
125 | } |
126 | |
127 | long idForChannel(S name) { |
128 | ret getChannelID(name); |
129 | } |
130 | |
131 | // attention: Discord user names may change |
132 | long idForUser(S name) { |
133 | ret getLong userID(conceptWhere User(+name)); |
134 | } |
135 | |
136 | int monologueLength(long channelID) { |
137 | L<Line> lines = linesInChannel(channelID); |
138 | int n = 0; |
139 | while (n < l(lines) && lines.get(l(lines)-1-n).bot) ++n; |
140 | ret n; |
141 | } |
142 | |
143 | Line lineForID(long msgID) { |
144 | ret conceptWhere Line(+msgID); |
145 | } |
146 | |
147 | Line lineForContext(S context) { |
148 | ret conceptWhere Line(+context); |
149 | } |
150 | |
151 | Line lineForGlobalID(S globalID) { |
152 | ret conceptWhere Line(globalIDObj := globalIDObj(globalID)); |
153 | } |
154 | |
155 | L<Line> botLines() { |
156 | ret asList(conceptsWhere Line(bot := true)); |
157 | } |
158 | |
159 | L<Long> allChannelIDs() { |
160 | ret collect channelID(list(Channel)); |
161 | } |
162 | |
163 | L<Line> linesModifiedAfter(long date) { |
164 | ret filter(concepts(), line -> line._modified >= date); |
165 | } |
166 | } |
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: | 539 / 19359 |
Version history: | 57 change(s) |
Referenced in: | [show references] |