OpenBullet2
OpenBullet2 copied to clipboard
KeyNotFoundException
Version of the software
0.2.1
Operating system
Windows 10
Browser / Native
Chrome 98
What happened?
The below block gives this error
KeyNotFoundException KeyNotFoundException The given key was not present in the dictionary."
but it works fine in my NodeJs 17.4.0 console.
Relevant LoliCode if needed
BLOCK:Script
LABEL:get proxies from links
INTERPRETER:NodeJS
INPUT proxyLinksList
BEGIN SCRIPT
const fs = require("fs");
const http = require("http");
const https = require("https");
proxyLinksList = proxyLinksList.toString().split("\n");
function getProxyLinks() {
for (let i = 0; i < proxyLinksList.length; i++) {
if (proxyLinksList[i].startsWith("https")) {
https.get(proxyLinksList[i], (res) => {
res.setEncoding("utf8");
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
const proxyRegex = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}/g;
const proxies = body.match(proxyRegex);
return proxies;
});
});
} else {
http.get(proxyLinksList[i], (res) => {
res.setEncoding("utf8");
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
const proxyRegex = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5}/g;
const proxies = body.match(proxyRegex);
return proxies;
});
});
}
}
}
let scriptResults = getProxyLinks();
END SCRIPT
OUTPUT String @scriptResults
ENDBLOCK
Can you please post a sample input and sample output of the script? Otherwise I wouldn't know how to debug this. If it's something private maybe send it to me via email, you can find my email in the readme of the repo.
Can you please post a sample input and sample output of the script? Otherwise I wouldn't know how to debug this. If it's something private maybe send it to me via email, you can find my email in the readme of the repo.
Hello, the input should be an array of links [“https://google.com”, “https://proxyscrape.com”], and the output should be an array of all the proxies found on the input array [“1.1.1.1”, “2.2.2.2”].
You put String
as type of the output array, have you tried putting ListOfStrings
?
After testing a bit, it appears that the request is not being awaited and the script immediately ends. Please read this to learn how to synchronize requests in node.js https://usefulangle.com/post/170/nodejs-synchronous-http-request
Instead of making the request sync, you could also make it return a Promise
and then await
it, read this https://github.com/openbullet/OpenBullet2/issues/99 to see how this works in practice. Let me know if you have any more doubts.
I will leave this issue open since I noticed that OB2 isn't happy with the ListOfString
return type in scripts.
After testing a bit, it appears that the request is not being awaited and the script immediately ends. Please read this to learn how to synchronize requests in node.js https://usefulangle.com/post/170/nodejs-synchronous-http-request
Instead of making the request sync, you could also make it return a
Promise
and thenawait
it, read this #99 to see how this works in practice. Let me know if you have any more doubts.I will leave this issue open since I noticed that OB2 isn't happy with the
ListOfString
return type in scripts.
Do you mean i should learn how to make asynchronous requests? Either way, changing the script to use the async/await syntax seems to have fixed it, although like still having problems with the output type. However, there are workarounds, such as getting the output as a string separated by new lines, and splitting it through the built in ob2 function...
Yeah, for now just do that, I will fix the ListOfStrings
and DictionaryOfStrings
output types, sorry about it 😅