Uses 5909K of libraries. Click here for Pure Java version (9759L/53K).
!7 cmodule eeZee > DynDiscordHopper { switchable S httpURL = "https://55392290.ngrok.io"; switchable S serverName; switchable S prefix = "<@599426196647706645> "; transient double sendTypingAfter = 6.0; L<Long> authorizedUsers = ll(463778175432785932, 547706854680297473); transient NotTooOften ntoError = notTooOften_1min(); @Override S answer(S input, Map map) { try answer super.answer(input, map); setField(prefix := "<@" + gazelle_selfUserID() + "> "); //setField(httpURL := or2(loadProgramTextFile("http-url"), httpURL)); new Matches m; long userID = getLong userID(map); print("User ID: " + userID); if (eqic(input, "hey " + trim(prefix))) ret "hey"; if (swic_trim(input, prefix + "add master ", m)) { if (!contains(authorizedUsers, userID)) ret "You are not my master"; add(authorizedUsers, parseFirstLong(m.rest())); change(); ret "Okidoki. Have " + n2(l(authorizedUsers), "master"); } S simplified = simpleSpaces_noTok(input); //print(+simplified); if (swic_trim(simplified, prefix + "set url ", m)) { print("Setting URL"); if (!contains(authorizedUsers, userID)) ret "You are not my master"; S s = m.rest(); if (neq(s, "disabled") && !contains(s, ".")) ret "Invalid URL"; setField(httpURL := s); saveProgramTextFile("http-url", httpURL); ret "URL set to " + httpURL + ", master"; } if (swic_trim(simplified, prefix + "get url", m)) { if (!contains(authorizedUsers, userID)) ret "You are not my master"; ret "URL is: " + backtickQuote(httpURL); } long time = sysNow(); S s; if (eqic(httpURL, "disabled")) null; try { temp doAfterSecondsIfStillRunning(sendTypingAfter, r { iAmTyping(map) }); s = loadPageWithTimeout(60.0, httpURL + hquery( message := input, +userID, channelID := map.get('channelID), msgID := map.get('msgID))); print("Got " + (s == null ? "timeout" : nChars(s)) + " in " + elapsedSeconds(time) + " s"); ret s; } catch e { if (!ntoError.yo()) null; S str = exceptionToStringShort(e); if (cicOneOf(str, "Server returned HTTP response code: 502", "Server code 500", "FileNotFoundException", "SocketTimeoutException")) // rough ret null with print("Bot is offline (500/502/404/timeout, " + elapsedSeconds(time) + " s): " + str); print(e); ret "Error: " + shorten(100, str); } } start { dm_registerAs_directLink('eeZee); dm_setModuleName(serverName + " - eeZee"); dm_vmBus_onMessage_q discordGuildJoin(voidfunc(Map map) { ret unless map.get('module) == module(); S name = "?"; pcall { name = rcall_string getName(rcall getUser(rcall getMember(map.get('event)))); } print("Got join, forwarding. Name: " + name); print(loadPageWithTimeout(60.0, httpURL + hquery( event := 'join, userName := name, userID := getLong userID(map) ))); }); } }
Began life as a copy of #1023494
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: | #1023928 |
Snippet name: | eeZee [LIVE, socket/http] |
Eternal ID of this version: | #1023928/69 |
Text MD5: | 0f26ea3bd3f0fbbb0724cc397f0c2cc3 |
Transpilation MD5: | 6c07dc1668040bf0d8555c19bb71a36b |
Author: | stefan |
Category: | javax / discord / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-11 22:24:45 |
Source code size: | 3292 bytes / 107 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 368 / 2021 |
Version history: | 68 change(s) |
Referenced in: | #1023940 - eeZee old [http] |