Uses 1113K of libraries. Click here for Pure Java version (9373L/48K).
!7 cmodule2 FollowSkypeBot > DynPrintLogAndEnabled { switchable bool uploadEnabled; switchable double answerInterval = 3.0; transient Q uploadQ; switchable int lastMessageID; // messages appear in skype.log twice!? File logFile() { ret userDir("dev/skype-bot/skype.log"); } start-thread { uploadQ = dm_startQ(); printFileInfo(logFile()); tailFileLinewise(logFile(), 1000, voidfunc(S line) { handleLine(line); }); print("Listening to log " + stringIf(uploadEnabled, " with upload")); dm_startThread(r postAnswers); } void postAnswers { while true { sleepSeconds(answerInterval); if (!enabled) continue; S file = "/root/dev/skype-bot/msgs-to-send.json"; pcall { L msgs = cast jsonDecode(loadPageSilently("https://bea.gazelle.rocks/beaHTML/127493?markSent=1")); if (nempty(msgs)) { print("Waiting for file to disappear: " + file); while (fileExists(file)) sleepSeconds(1); saveTextFile(file, jsonEncode(msgs)); print("Sent msgs to bot."); } } } } void processWholeLog { for (S line : linesFromFile(logFile())) handleLine(line); } void handleLine(S line) pcall { //if (!enabled) ret; new Matches m; if (startsWith(line, "Message: ", m)) { //print(m.rest()); Map map = jsonDecodeMap(m.rest()); int id = toInt(map.get("id")); if (id == lastMessageID) ret with print("Message seen twice: " + id); setField(lastMessageID := id); //pnl(map); Map resource = cast mapGet(map, "resource"); //pnl(resource); S displayName = cast mapGet(resource, "imdisplayname"); S content = cast mapGet(resource, "content"); if (nempty(content)) { S cleaned = cleanSkypeMsg(content); print("Cleaned: " + cleaned); if (uploadEnabled) uploadQ.add(r { S info = "Skype"; if (nempty(displayName)) info += " (User " + displayName + ")"; gazelleBEA_uploadInput(cleaned, info, eq(content, cleaned) ? null : content); }); } } } }
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: | 297 / 12875 |
Version history: | 41 change(s) |
Referenced in: | [show references] |