Uses 1113K of libraries. Click here for Pure Java version (9373L/48K).
1 | !7 |
2 | |
3 | cmodule2 FollowSkypeBot > DynPrintLogAndEnabled { |
4 | switchable bool uploadEnabled; |
5 | switchable double answerInterval = 3.0; |
6 | transient Q uploadQ; |
7 | switchable int lastMessageID; // messages appear in skype.log twice!? |
8 | |
9 | File logFile() { |
10 | ret userDir("dev/skype-bot/skype.log"); |
11 | } |
12 | |
13 | start-thread { |
14 | uploadQ = dm_startQ(); |
15 | printFileInfo(logFile()); |
16 | tailFileLinewise(logFile(), 1000, voidfunc(S line) { |
17 | handleLine(line); |
18 | }); |
19 | print("Listening to log " + stringIf(uploadEnabled, " with upload")); |
20 | |
21 | dm_startThread(r postAnswers); |
22 | } |
23 | |
24 | void postAnswers { |
25 | while true { |
26 | sleepSeconds(answerInterval); |
27 | if (!enabled) continue; |
28 | S file = "/root/dev/skype-bot/msgs-to-send.json"; |
29 | pcall { |
30 | L msgs = cast jsonDecode(loadPageSilently("https://bea.gazelle.rocks/beaHTML/127493?markSent=1")); |
31 | if (nempty(msgs)) { |
32 | print("Waiting for file to disappear: " + file); |
33 | while (fileExists(file)) sleepSeconds(1); |
34 | saveTextFile(file, jsonEncode(msgs)); |
35 | print("Sent msgs to bot."); |
36 | } |
37 | } |
38 | } |
39 | } |
40 | |
41 | void processWholeLog { |
42 | for (S line : linesFromFile(logFile())) |
43 | handleLine(line); |
44 | } |
45 | |
46 | void handleLine(S line) pcall { |
47 | //if (!enabled) ret; |
48 | new Matches m; |
49 | if (startsWith(line, "Message: ", m)) { |
50 | //print(m.rest()); |
51 | Map map = jsonDecodeMap(m.rest()); |
52 | int id = toInt(map.get("id")); |
53 | if (id == lastMessageID) |
54 | ret with print("Message seen twice: " + id); |
55 | setField(lastMessageID := id); |
56 | //pnl(map); |
57 | Map resource = cast mapGet(map, "resource"); |
58 | //pnl(resource); |
59 | S displayName = cast mapGet(resource, "imdisplayname"); |
60 | S content = cast mapGet(resource, "content"); |
61 | if (nempty(content)) { |
62 | S cleaned = cleanSkypeMsg(content); |
63 | print("Cleaned: " + cleaned); |
64 | if (uploadEnabled) uploadQ.add(r { |
65 | S info = "Skype"; |
66 | if (nempty(displayName)) info += " (User " + displayName + ")"; |
67 | gazelleBEA_uploadInput(cleaned, info, eq(content, cleaned) ? null : content); |
68 | }); |
69 | } |
70 | } |
71 | } |
72 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030893 |
Snippet name: | Skype Bot Gazelle Bridge Module |
Eternal ID of this version: | #1030893/42 |
Text MD5: | 89b1ab239a0996d87378bfe5cc753df2 |
Transpilation MD5: | 9f4e5e5c89e0de7b569fd5d6bc9311bb |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-29 02:01:18 |
Source code size: | 2216 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 299 / 12877 |
Version history: | 41 change(s) |
Referenced in: | [show references] |